Module: Kippt::Collection

Extended by:
Forwardable
Includes:
Enumerable
Included in:
ClipCollection, CommentCollection, LikeCollection, ListCollection, UserCollection
Defined in:
lib/kippt/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



4
5
6
# File 'lib/kippt/collection.rb', line 4

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



4
5
6
# File 'lib/kippt/collection.rb', line 4

def offset
  @offset
end

Instance Method Details

#[](index) ⇒ Object



25
26
27
# File 'lib/kippt/collection.rb', line 25

def [](index)
  objects[index]
end

#each(&block) ⇒ Object



29
30
31
# File 'lib/kippt/collection.rb', line 29

def each(&block)
  objects.each(&block)
end

#initialize(data, client = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/kippt/collection.rb', line 6

def initialize(data, client = nil)
  meta         = data.fetch("meta") { {} }
  @limit       = meta.fetch("limit") { nil }
  @offset      = meta.fetch("offset") { nil }
  @next        = meta.fetch("next") { nil }
  @previous    = meta.fetch("previous") { nil }

  @client  = client

  @object_data = data.fetch("objects")
end

#next_pageObject

Raises:



37
38
39
40
41
# File 'lib/kippt/collection.rb', line 37

def next_page
  raise Kippt::APIError.new("There is no next page") if @next.nil? || @next == ""

  collection_resource.collection_from_url(@next)
end

#next_page?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/kippt/collection.rb', line 33

def next_page?
  @next
end

#objectsObject



21
22
23
# File 'lib/kippt/collection.rb', line 21

def objects
  @objects ||= @object_data.map {|data| object_class.new(data, client) }
end

#previous_pageObject Also known as: prev_page

Raises:



48
49
50
51
52
# File 'lib/kippt/collection.rb', line 48

def previous_page
  raise Kippt::APIError.new("There is no previous page") if @previous.nil? || @previous == ""

  collection_resource.collection_from_url(@previous)
end

#previous_page?Boolean Also known as: prev_page?

Returns:

  • (Boolean)


43
44
45
# File 'lib/kippt/collection.rb', line 43

def previous_page?
  @previous
end