class AudioVision::Base

This is a private class and shouldn’t be used directly. It acts as a base class for all of the AudioVision classes which are available in the API.

Public Class Methods

api_path() click to toggle source

Returns the API path for this class. Example: /api/v1/posts

# File lib/audio_vision/base.rb, line 12
def api_path
  @api_path ||= [AudioVision.api_root, self.api_namespace].join("/")
end
collection(options={}) click to toggle source

Get a collection of posts. Passed-in parameters are passed directly to the API. Returns an array of Posts.

Example:

AudionVision::Post.collection(limit: 5, query: "Photos") #=> [ ... ]
# File lib/audio_vision/base.rb, line 38
def collection(options={})
  response = client.get(api_path, options)

  if response.success?
    collection = []

    response.body.each do |json|
      collection << new(json)
    end

    collection
  else
    []
  end
end
find(id) click to toggle source

Find an object by its ID. Returns the object if found, otherwise false.

Example:

AudioVision::Post.find(10) #=> #<AudioVision::Post>
# File lib/audio_vision/base.rb, line 21
def find(id)
  response = client.get(endpoint(id))

  if response.success?
    new(response.body)
  else
    false
  end
end

Private Class Methods

client() click to toggle source
# File lib/audio_vision/base.rb, line 61
def client
  @client ||= AudioVision::Client.new
end
endpoint(*segments) click to toggle source
# File lib/audio_vision/base.rb, line 57
def endpoint(*segments)
  [self.api_namespace, *segments].join("/")
end

Public Instance Methods

==(comparison_object) click to toggle source

Steal the ActiveRecord behavior for object comparison. If they’re the same class and the ID is the same, then it’s “same” enough for us.

Calls superclass method
# File lib/audio_vision/base.rb, line 70
def ==(comparison_object)
  super ||
    comparison_object.instance_of?(self.class) &&
    self.id && self.id == comparison_object.id
end
Also aliased as: eql?
eql?(comparison_object)
Alias for: ==