Class: SearchTypeahead::Service
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- SearchTypeahead::Service
- Includes:
- Common::Client::Concerns::Monitoring
- Defined in:
- lib/search_typeahead/service.rb
Overview
This class builds a wrapper around Search.gov web suggestioms API.
Constant Summary collapse
- STATSD_KEY_PREFIX =
'api.search_typeahead'
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #api_key ⇒ Object private
-
#initialize(query) ⇒ Service
constructor
A new instance of Service.
- #name ⇒ Object private
-
#query_params ⇒ Object
private
Required params [name, access_key, query].
-
#suggestions ⇒ Object
GETs suggestion data from search.gov.
- #suggestions_url ⇒ Object private
Methods included from Common::Client::Concerns::Monitoring
#increment, #increment_failure, #increment_total, #with_monitoring
Methods inherited from Common::Client::Base
#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
#initialize(query) ⇒ Service
Returns a new instance of Service.
22 23 24 |
# File 'lib/search_typeahead/service.rb', line 22 def initialize(query) @query = query || '' end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
20 21 22 |
# File 'lib/search_typeahead/service.rb', line 20 def query @query end |
Instance Method Details
#api_key ⇒ Object (private)
61 62 63 |
# File 'lib/search_typeahead/service.rb', line 61 def api_key Settings.search_typeahead.api_key end |
#name ⇒ Object (private)
57 58 59 |
# File 'lib/search_typeahead/service.rb', line 57 def name Settings.search_typeahead.name end |
#query_params ⇒ Object (private)
Required params [name, access_key, query]
49 50 51 52 53 54 55 |
# File 'lib/search_typeahead/service.rb', line 49 def query_params { name:, q: query, api_key: } end |
#suggestions ⇒ Object
GETs suggestion data from search.gov
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/search_typeahead/service.rb', line 28 def suggestions with_monitoring do Faraday.get(suggestions_url, query_params) do |req| req..timeout = 2 req..open_timeout = 2 end end rescue => e e end |
#suggestions_url ⇒ Object (private)
41 42 43 |
# File 'lib/search_typeahead/service.rb', line 41 def suggestions_url config.base_path end |