Class: Twingly::Search::Client
- Inherits:
-
Object
- Object
- Twingly::Search::Client
- Defined in:
- lib/twingly/search/client.rb
Overview
Twingly Search API client
Constant Summary collapse
- BASE_URL =
"https://api.twingly.com"- SEARCH_API_VERSION =
"v3"- SEARCH_PATH =
"/blog/search/api/#{SEARCH_API_VERSION}/search"- DEFAULT_USER_AGENT =
"Twingly Search Ruby Client/#{VERSION}"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#endpoint_url ⇒ String
The API endpoint URL.
-
#execute_query(query) ⇒ Result
Executes the given Query and returns the result.
-
#initialize(api_key = nil, options = {}) {|_self| ... } ⇒ Client
constructor
Creates a new Twingly Search API client.
-
#query {|Query| ... } ⇒ Query
Returns a new Query object connected to this client.
Constructor Details
#initialize(api_key = nil, options = {}) {|_self| ... } ⇒ Client
Creates a new Twingly Search API client
25 26 27 28 29 30 31 32 |
# File 'lib/twingly/search/client.rb', line 25 def initialize(api_key = nil, = {}) @api_key = api_key @user_agent = .fetch(:user_agent) { DEFAULT_USER_AGENT } yield self if block_given? @api_key ||= env_api_key || api_key_missing end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/twingly/search/client.rb', line 9 def api_key @api_key end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
9 10 11 |
# File 'lib/twingly/search/client.rb', line 9 def user_agent @user_agent end |
Instance Method Details
#endpoint_url ⇒ String
Returns the API endpoint URL.
55 56 57 |
# File 'lib/twingly/search/client.rb', line 55 def endpoint_url "#{BASE_URL}#{SEARCH_PATH}" end |
#execute_query(query) ⇒ Result
Executes the given Query and returns the result
This method should not be called manually, as that is handled by Query#execute.
49 50 51 52 |
# File 'lib/twingly/search/client.rb', line 49 def execute_query(query) response_body = get_response(query).body Parser.new.parse(response_body) end |
#query {|Query| ... } ⇒ Query
Returns a new Query object connected to this client
38 39 40 |
# File 'lib/twingly/search/client.rb', line 38 def query(&block) Query.new(self, &block) end |