Class: Lexile::Api::Page
- Inherits:
-
Object
- Object
- Lexile::Api::Page
- Includes:
- Enumerable
- Defined in:
- lib/lexile/api/page.rb
Overview
Represents a page of data
Instance Attribute Summary collapse
-
#all ⇒ Array
readonly
private
Get all elements in page.
Instance Method Summary collapse
-
#each(&blk) ⇒ Array
private
Iterate over all elements in the page.
-
#initialize(client, api_model, uri, query_params = {}) ⇒ Lexile::Api::Page
constructor
private
Request a page of data and store the results in this instance.
-
#last(num = nil) ⇒ Lexile::Model, Lexile::Api::Page
Retrieve the last element or n elements in the resource.
-
#next ⇒ Lexile::Api::Page?
private
Gets next page if one is present, nil otherwise.
Constructor Details
#initialize(client, api_model, uri, query_params = {}) ⇒ Lexile::Api::Page
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Request a page of data and store the results in this instance
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/lexile/api/page.rb', line 12 def initialize(client, api_model, uri, query_params = {}) @client = client @api_model = api_model @uri = uri @query_params = query_params response_json = @client.get( uri, @query_params ) @all = api_model.parse(response_json) raise Lexile::CannotProcessResponse.new('[:meta] is not present in response') unless response_json.has_key?('meta') @limit = response_json['meta']['limit'] @next = response_json['meta']['next'] #puts "NEXT URI IS ==>#{@next}<==" @offset = response_json['meta']['offset'] @previous = response_json['meta']['previous'] @total_count = response_json['meta']['total_count'] end |
Instance Attribute Details
#all ⇒ Array (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get all elements in page
57 58 59 |
# File 'lib/lexile/api/page.rb', line 57 def all @all end |
Instance Method Details
#each(&blk) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterate over all elements in the page
48 49 50 |
# File 'lib/lexile/api/page.rb', line 48 def each(&blk) @all.each(&blk) end |
#last(num = nil) ⇒ Lexile::Model, Lexile::Api::Page
Retrieve the last element or n elements in the resource
68 69 70 71 |
# File 'lib/lexile/api/page.rb', line 68 def last(num = nil) return @all.last num if num @all.last end |
#next ⇒ Lexile::Api::Page?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gets next page if one is present, nil otherwise
38 39 40 41 |
# File 'lib/lexile/api/page.rb', line 38 def next return nil if @next.nil? Page.new( @client, @api_model, @next, {} ) end |