Class: Twingly::Search::Query
- Inherits:
-
Object
- Object
- Twingly::Search::Query
- Defined in:
- lib/twingly/search/query.rb
Overview
Twingly Search API query
Instance Attribute Summary collapse
-
#client ⇒ Client
the client that this query is connected to.
-
#search_query ⇒ String
the search query.
Instance Method Summary collapse
-
#end_time ⇒ Time
The time that was set with #end_time=.
-
#end_time=(time) ⇒ Object
Search for posts published before this time (inclusive).
-
#execute ⇒ Result
Executes the query and returns the result.
-
#initialize(client) {|_self| ... } ⇒ Query
constructor
No need to call this method manually, instead use Client#query.
-
#language ⇒ Object
deprecated
Deprecated.
Please use #search_query instead
-
#language=(language_code) ⇒ Object
deprecated
Deprecated.
Please use #search_query= instead
-
#pattern ⇒ Object
deprecated
Deprecated.
Please use #search_query instead
-
#pattern=(search_query) ⇒ Object
deprecated
Deprecated.
Please use #search_query= instead
-
#request_parameters ⇒ Hash
The request parameters.
-
#start_time ⇒ Time
The time that was set with #start_time=.
-
#start_time=(time) ⇒ Object
Search for posts published after this time (inclusive).
-
#url ⇒ String
The request url for the query.
-
#url_parameters ⇒ String
The query part of the request url.
Constructor Details
#initialize(client) {|_self| ... } ⇒ Query
No need to call this method manually, instead use Client#query.
52 53 54 55 56 57 58 59 |
# File 'lib/twingly/search/query.rb', line 52 def initialize(client) @client = client @start_time = nil @end_time = nil @language = nil yield self if block_given? end |
Instance Attribute Details
#client ⇒ Client
the client that this query is connected to.
12 13 14 |
# File 'lib/twingly/search/query.rb', line 12 def client @client end |
#search_query ⇒ String
the search query.
12 13 14 |
# File 'lib/twingly/search/query.rb', line 12 def search_query @search_query end |
Instance Method Details
#end_time ⇒ Time
Returns the time that was set with #end_time=.
45 46 47 |
# File 'lib/twingly/search/query.rb', line 45 def end_time @end_time end |
#end_time=(time) ⇒ Object
Search for posts published before this time (inclusive).
117 118 119 120 121 |
# File 'lib/twingly/search/query.rb', line 117 def end_time=(time) assert_valid_time(time) @end_time = time end |
#execute ⇒ Result
Executes the query and returns the result.
73 74 75 |
# File 'lib/twingly/search/query.rb', line 73 def execute @client.execute_query(self) end |
#language ⇒ Object
Please use #search_query instead
28 29 30 31 |
# File 'lib/twingly/search/query.rb', line 28 def language warn "[DEPRECATION] `language` is deprecated. Please use `search_query` instead." @language end |
#language=(language_code) ⇒ Object
Please use #search_query= instead
34 35 36 37 |
# File 'lib/twingly/search/query.rb', line 34 def language=(language_code) warn "[DEPRECATION] `language=` is deprecated. Please use `search_query=` instead." @language = language_code end |
#pattern ⇒ Object
Please use #search_query instead
16 17 18 19 |
# File 'lib/twingly/search/query.rb', line 16 def pattern warn "[DEPRECATION] `pattern` is deprecated. Please use `search_query` instead." @search_query end |
#pattern=(search_query) ⇒ Object
Please use #search_query= instead
22 23 24 25 |
# File 'lib/twingly/search/query.rb', line 22 def pattern=(search_query) warn "[DEPRECATION] `pattern=` is deprecated. Please use `search_query=` instead." @search_query = search_query end |
#request_parameters ⇒ Hash
Returns the request parameters.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/twingly/search/query.rb', line 85 def request_parameters full_search_query = search_query.to_s.dup full_search_query << " lang:#{@language}" unless @language.to_s.empty? full_search_query << " start-date:#{formatted_start_date}" if start_time full_search_query << " end-date:#{formatted_end_date}" if end_time if full_search_query.to_s.empty? fail QueryError, "Search query cannot be empty" end { apikey: client.api_key, q: full_search_query } end |
#start_time ⇒ Time
Returns the time that was set with #start_time=.
40 41 42 |
# File 'lib/twingly/search/query.rb', line 40 def start_time @start_time end |
#start_time=(time) ⇒ Object
Search for posts published after this time (inclusive).
106 107 108 109 110 |
# File 'lib/twingly/search/query.rb', line 106 def start_time=(time) assert_valid_time(time) @start_time = time end |
#url ⇒ String
Returns the request url for the query.
62 63 64 |
# File 'lib/twingly/search/query.rb', line 62 def url "#{client.endpoint_url}?#{url_parameters}" end |
#url_parameters ⇒ String
Returns the query part of the request url.
79 80 81 |
# File 'lib/twingly/search/query.rb', line 79 def url_parameters Faraday::Utils.build_query(request_parameters) end |