Class: Sequence::Query
- Inherits:
-
Object
- Object
- Sequence::Query
- Includes:
- Enumerable
- Defined in:
- lib/sequence/query.rb
Direct Known Subclasses
Account::Query, Action::ListQuery, Action::SumQuery, Feed::Query, Flavor::Query, Key::Query, Token::GroupQuery, Token::SumQuery, Transaction::Query
Defined Under Namespace
Classes: PageQuery
Instance Attribute Summary collapse
- #client ⇒ Client readonly
- #query ⇒ Hash readonly
Instance Method Summary collapse
-
#each ⇒ void
Iterate through objects in response, fetching the next page of results from the API as needed.
- #fetch(_query) ⇒ Object
-
#initialize(client, query = {}) ⇒ Query
constructor
A new instance of Query.
- #page(size: nil, cursor: nil) ⇒ Object
- #pages ⇒ Object
-
#translate(_response_object) ⇒ Object
Overwrite to translate API response data to a different Ruby object.
Constructor Details
#initialize(client, query = {}) ⇒ Query
Returns a new instance of Query.
15 16 17 18 |
# File 'lib/sequence/query.rb', line 15 def initialize(client, query = {}) @client = client @query = query end |
Instance Attribute Details
#query ⇒ Hash (readonly)
13 14 15 |
# File 'lib/sequence/query.rb', line 13 def query @query end |
Instance Method Details
#each ⇒ void
This method returns an undefined value.
Iterate through objects in response, fetching the next page of results from the API as needed.
Implements required method Enumerable#each.
26 27 28 29 30 31 32 |
# File 'lib/sequence/query.rb', line 26 def each pages.each do |page| page.items.each do |item| yield item end end end |
#fetch(_query) ⇒ Object
35 36 37 |
# File 'lib/sequence/query.rb', line 35 def fetch(_query) raise NotImplementedError end |
#page(size: nil, cursor: nil) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/sequence/query.rb', line 50 def page(size: nil, cursor: nil) opts = { size: size, cursor: cursor } unless size.nil? || size.zero? opts[:page_size] = size end @query = @query.merge(opts) pages.page end |
#pages ⇒ Object
46 47 48 |
# File 'lib/sequence/query.rb', line 46 def pages PageQuery.new(client, query, method(:fetch), method(:translate)) end |
#translate(_response_object) ⇒ Object
Overwrite to translate API response data to a different Ruby object.
41 42 43 |
# File 'lib/sequence/query.rb', line 41 def translate(_response_object) raise NotImplementedError end |