Class: Sequence::Query
- Inherits:
-
Object
- Object
- Sequence::Query
- Includes:
- Enumerable, Validations
- Defined in:
- lib/sequence/query.rb
Direct Known Subclasses
Account::Query, Action::ListQuery, Action::SumQuery, Asset::Query, Balance::Query, Contract::Query, 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
- #all ⇒ Object deprecated Deprecated.
-
#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(opts = {}) ⇒ 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.
17 18 19 20 |
# File 'lib/sequence/query.rb', line 17 def initialize(client, query = {}) @client = client @query = query end |
Instance Attribute Details
#query ⇒ Hash (readonly)
15 16 17 |
# File 'lib/sequence/query.rb', line 15 def query @query end |
Instance Method Details
#all ⇒ Object
Returns all objects, blocking until complete. Deprecated: use Enumerable methods such as to_a instead.
52 53 54 |
# File 'lib/sequence/query.rb', line 52 def all to_a end |
#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.
28 29 30 31 32 33 34 |
# File 'lib/sequence/query.rb', line 28 def each pages.each do |page| page.items.each do |item| yield item end end end |
#fetch(_query) ⇒ Object
37 38 39 |
# File 'lib/sequence/query.rb', line 37 def fetch(_query) raise NotImplementedError end |
#page(opts = {}) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/sequence/query.rb', line 61 def page(opts = {}) validate_inclusion_of!(opts, :size, :cursor) unless opts[:size].nil? || opts[:size].zero? opts[:page_size] = opts.delete(:size) end @query = @query.merge(opts) pages.page end |
#pages ⇒ Object
57 58 59 |
# File 'lib/sequence/query.rb', line 57 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.
43 44 45 |
# File 'lib/sequence/query.rb', line 43 def translate(_response_object) raise NotImplementedError end |