Class: Cased::Query
- Inherits:
-
Object
- Object
- Cased::Query
- Extended by:
- Forwardable
- Defined in:
- lib/cased/query.rb
Instance Method Summary collapse
-
#initialize(client, phrase: nil, variables: {}) ⇒ Query
constructor
A new instance of Query.
- #limit(new_limit) ⇒ Cased::Query
- #page(new_page) ⇒ Cased::Query
- #phrase(new_phrase) ⇒ Cased::Query
- #response ⇒ Object
Constructor Details
#initialize(client, phrase: nil, variables: {}) ⇒ Query
Returns a new instance of Query.
14 15 16 17 18 19 20 21 22 |
# File 'lib/cased/query.rb', line 14 def initialize(client, phrase: nil, variables: {}) raise ArgumentError, 'variables must be a Hash' unless variables.is_a?(Hash) @client = client @phrase = phrase @page = 1 @limit = 25 @variables = variables end |
Instance Method Details
#limit(new_limit) ⇒ Cased::Query
34 35 36 37 38 |
# File 'lib/cased/query.rb', line 34 def limit(new_limit) @limit = [[new_limit, 100].min, 1].max self end |
#page(new_page) ⇒ Cased::Query
42 43 44 45 46 |
# File 'lib/cased/query.rb', line 42 def page(new_page) @page = [1, new_page.to_i].max self end |
#phrase(new_phrase) ⇒ Cased::Query
26 27 28 29 30 |
# File 'lib/cased/query.rb', line 26 def phrase(new_phrase) @phrase = new_phrase self end |
#response ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cased/query.rb', line 73 def response return @response if defined?(@response) @response = begin resp = @client.get('events') do |req| req.params['phrase'] = @phrase unless @phrase.nil? req.params['per_page'] = @limit unless @limit.nil? req.params['page'] = @page unless @page.nil? req.params['variables'] = @variables unless @variables.nil? end CollectionResponse.new(response: resp) rescue Cased::HTTP::Error, Faraday::Error => e CollectionResponse.new(exception: e) end end |