Class: Search::Service

Inherits:
Common::Client::Base show all
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

Instance Method Summary collapse

Methods included from Common::Client::Concerns::Monitoring

#with_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

#pageObject (readonly)

Returns the value of attribute page.



22
23
24
# File 'lib/search/service.rb', line 22

def page
  @page
end

#queryObject (readonly)

Returns the value of attribute query.



22
23
24
# File 'lib/search/service.rb', line 22

def query
  @query
end

Instance Method Details

#resultsSearch::ResultsResponse

GETs a list of search results from Search.gov web results API

Returns:



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