Class: Search::Service
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- Search::Service
- Includes:
- Common::Client::Concerns::Monitoring
- Defined in:
- lib/search/service.rb
Overview
This class builds a wrapper around Search.gov web results API. Creating a new instance of class will and calling #results will return a ResultsResponse upon success or an exception upon failure.
Constant Summary collapse
- STATSD_KEY_PREFIX =
'api.search'
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(query, page = 1) ⇒ Service
constructor
A new instance of Service.
-
#results ⇒ Search::ResultsResponse
GETs a list of search results from Search.gov web results API.
Methods included from Common::Client::Concerns::Monitoring
Methods inherited from Common::Client::Base
configuration, #raise_backend_exception
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Constructor Details
#initialize(query, page = 1) ⇒ Service
Returns a new instance of Service.
24 25 26 27 |
# File 'lib/search/service.rb', line 24 def initialize(query, page = 1) @query = query @page = page.to_i end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
22 23 24 |
# File 'lib/search/service.rb', line 22 def page @page end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
22 23 24 |
# File 'lib/search/service.rb', line 22 def query @query end |
Instance Method Details
#results ⇒ Search::ResultsResponse
GETs a list of search results from Search.gov web results API
32 33 34 35 36 37 38 39 |
# File 'lib/search/service.rb', line 32 def results with_monitoring do response = perform(:get, results_url, query_params) Search::ResultsResponse.from(response) end rescue => e handle_error(e) end |