Class: SearchClickTracking::Service
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- SearchClickTracking::Service
- Includes:
- Common::Client::Concerns::Monitoring
- Defined in:
- lib/search_click_tracking/service.rb
Overview
This class builds a wrapper around Search.gov web click tracking API.
Constant Summary collapse
- STATSD_KEY_PREFIX =
'api.search_click_tracking'
Instance Attribute Summary collapse
-
#module_code ⇒ Object
readonly
Returns the value of attribute module_code.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #access_key ⇒ Object private
- #affiliate ⇒ Object private
-
#initialize(url, query, position, user_agent, module_code = 'I14Y') ⇒ Service
constructor
A new instance of Service.
-
#query_params ⇒ Object
private
Required params [affiliate, access_key, module_code, url, query, position, user_agent].
-
#track_click ⇒ Object
POSTs click tracking query param data to search.gov.
- #track_click_url ⇒ Object private
- #url_with_params ⇒ 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(url, query, position, user_agent, module_code = 'I14Y') ⇒ Service
Returns a new instance of Service.
23 24 25 26 27 28 29 |
# File 'lib/search_click_tracking/service.rb', line 23 def initialize(url, query, position, user_agent, module_code = 'I14Y') @url = url @query = query @position = position @user_agent = user_agent @module_code = module_code end |
Instance Attribute Details
#module_code ⇒ Object (readonly)
Returns the value of attribute module_code.
21 22 23 |
# File 'lib/search_click_tracking/service.rb', line 21 def module_code @module_code end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
21 22 23 |
# File 'lib/search_click_tracking/service.rb', line 21 def position @position end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
21 22 23 |
# File 'lib/search_click_tracking/service.rb', line 21 def query @query end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
21 22 23 |
# File 'lib/search_click_tracking/service.rb', line 21 def url @url end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
21 22 23 |
# File 'lib/search_click_tracking/service.rb', line 21 def user_agent @user_agent end |
Instance Method Details
#access_key ⇒ Object (private)
73 74 75 |
# File 'lib/search_click_tracking/service.rb', line 73 def access_key Settings.search_click_tracking.access_key end |
#affiliate ⇒ Object (private)
69 70 71 |
# File 'lib/search_click_tracking/service.rb', line 69 def affiliate Settings.search_click_tracking.affiliate end |
#query_params ⇒ Object (private)
Required params [affiliate, access_key, module_code, url, query, position, user_agent]
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/search_click_tracking/service.rb', line 55 def query_params URI.encode_www_form( { affiliate:, access_key:, module_code:, url:, query:, position:, user_agent: } ) end |
#track_click ⇒ Object
POSTs click tracking query param data to search.gov
33 34 35 36 37 38 39 |
# File 'lib/search_click_tracking/service.rb', line 33 def track_click with_monitoring do Faraday.post(url_with_params, '') end rescue => e e end |
#track_click_url ⇒ Object (private)
47 48 49 |
# File 'lib/search_click_tracking/service.rb', line 47 def track_click_url config.base_path end |
#url_with_params ⇒ Object (private)
43 44 45 |
# File 'lib/search_click_tracking/service.rb', line 43 def url_with_params "#{track_click_url}?#{query_params}" end |