Class: Viki::APIObject

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/viki/api_object.rb

Constant Summary

Constants included from Utilities

Utilities::URL_NAMESPACES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, access_token) ⇒ APIObject

Returns a new instance of APIObject.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/viki/api_object.rb', line 8

def initialize(json, access_token)
  hash = MultiJson.load(json)
  @content = hash["response"] ?  hash["response"] : hash
  @count =  hash["count"] ? hash["count"].to_i : 1

  pagination = hash["pagination"]

  if pagination
    @next_url = pagination["next"] if not pagination["next"].empty?
    @previous_url = pagination["previous"] if not pagination["previous"].empty?
  end

  @access_token = access_token
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



23
24
25
# File 'lib/viki/api_object.rb', line 23

def content
  @content
end

#countObject (readonly)

Returns the value of attribute count.



23
24
25
# File 'lib/viki/api_object.rb', line 23

def count
  @count
end

Instance Method Details

#nextObject



25
26
27
# File 'lib/viki/api_object.rb', line 25

def next
  @next_url ? direct_request(@next_url) : nil
end

#prevObject



29
30
31
# File 'lib/viki/api_object.rb', line 29

def prev
  @previous_url ? direct_request(@previous_url) : nil
end