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
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each(&block) ⇒ Object
- #initialize(data, client = nil) ⇒ Object
- #next_page ⇒ Object
- #next_page? ⇒ Boolean
- #objects ⇒ Object
- #previous_page ⇒ Object (also: #prev_page)
- #previous_page? ⇒ Boolean (also: #prev_page?)
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
4 5 6 |
# File 'lib/kippt/collection.rb', line 4 def limit @limit end |
#offset ⇒ Object (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) = data.fetch("meta") { {} } @limit = .fetch("limit") { nil } @offset = .fetch("offset") { nil } @next = .fetch("next") { nil } @previous = .fetch("previous") { nil } @client = client @object_data = data.fetch("objects") end |
#next_page ⇒ Object
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_from_url(@next).fetch end |
#next_page? ⇒ Boolean
33 34 35 |
# File 'lib/kippt/collection.rb', line 33 def next_page? @next end |
#objects ⇒ Object
21 22 23 |
# File 'lib/kippt/collection.rb', line 21 def objects @objects ||= @object_data.map {|data| object_class.new(data, client) } end |
#previous_page ⇒ Object Also known as: prev_page
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_from_url(@previous).fetch end |
#previous_page? ⇒ Boolean Also known as: prev_page?
43 44 45 |
# File 'lib/kippt/collection.rb', line 43 def previous_page? @previous end |