Class: Forms::Client

Inherits:
Common::Client::Base show all
Includes:
Common::Client::Concerns::Monitoring, SentryLogging
Defined in:
lib/forms/client.rb

Overview

Proxy Service for Forms API.

Examples:

Get all forms or filter by a wildcard query.

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.forms'

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#increment, #increment_failure, #increment_total, #with_monitoring

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

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

Constructor Details

#initialize(search_term) ⇒ Client

Returns a new instance of Client.



23
24
25
# File 'lib/forms/client.rb', line 23

def initialize(search_term)
  @search_term = search_term
end

Instance Attribute Details

#search_termObject (readonly)

Returns the value of attribute search_term.



21
22
23
# File 'lib/forms/client.rb', line 21

def search_term
  @search_term
end

Instance Method Details

#get_allObject

Get all forms with an optional query parameter “query” for wildcard filtering.



29
30
31
32
33
34
35
36
# File 'lib/forms/client.rb', line 29

def get_all
  with_monitoring do
    raw_response = perform(:get, 'forms', query: search_term)
    Forms::Responses::Response.new(raw_response.status, raw_response.body, 'forms')
  end
rescue => e
  handle_error(e)
end

#handle_error(error) ⇒ Object (private)



40
41
42
43
44
45
46
47
48
# File 'lib/forms/client.rb', line 40

def handle_error(error)
  case error
  when Common::Client::Errors::ClientError
    save_error_details(error)
    raise_backend_exception('FORMS_502', self.class, error)
  else
    raise error
  end
end

#save_error_details(error) ⇒ Object (private)



50
51
52
53
54
55
56
57
58
# File 'lib/forms/client.rb', line 50

def save_error_details(error)
  Sentry.set_tags(external_service: self.class.to_s.underscore)

  Sentry.set_extras(
    url: config.base_path,
    message: error.message,
    body: error.body
  )
end