Class: AudioVision::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/audio_vision/base.rb

Overview

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.

Direct Known Subclasses

Billboard, Bucket, Post

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.api_pathObject

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



12
13
14
# File 'lib/audio_vision/base.rb', line 12

def api_path
  @api_path ||= [AudioVision.api_root, self.api_namespace].join("/")
end

.collection(options = {}) ⇒ Object

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") #=> [ ... ]


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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) ⇒ Object

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

Example:

AudioVision::Post.find(10) #=> #<AudioVision::Post>


21
22
23
24
25
26
27
28
29
# 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

Instance Method Details

#==(comparison_object) ⇒ Object Also known as: eql?

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.



70
71
72
73
74
# 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