Class: Apps::Client

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

Overview

Proxy Service for Apps API.

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.apps'

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 = nil) ⇒ Client

Returns a new instance of Client.



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

def initialize(search_term = nil)
  @search_term = search_term
end

Instance Attribute Details

#search_termObject (readonly)

Returns the value of attribute search_term.



19
20
21
# File 'lib/apps/client.rb', line 19

def search_term
  @search_term
end

Instance Method Details

#get_allObject

Get all apps



27
28
29
30
31
32
33
34
# File 'lib/apps/client.rb', line 27

def get_all
  with_monitoring do
    raw_response = perform(:get, 'directory', nil)
    Apps::Responses::Response.new(raw_response.status, raw_response.body, 'apps')
  end
rescue => e
  handle_error(e)
end

#get_appObject

Get an individual app



38
39
40
41
42
43
44
45
46
# File 'lib/apps/client.rb', line 38

def get_app
  with_monitoring do
    escaped_code = ERB::Util.url_encode(@search_term)
    raw_response = perform(:get, "directory/#{escaped_code}", nil)
    Apps::Responses::Response.new(raw_response.status, raw_response.body, 'app')
  end
rescue => e
  handle_error(e)
end

#get_scopesObject

Get the scopes an app with a given service_category could request



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

def get_scopes
  with_monitoring do
    raw_response = perform(:get, "directory/scopes/#{@search_term}", nil)
    Apps::Responses::Response.new(raw_response.status, raw_response.body, 'scopes')
  end
rescue => e
  handle_error(e)
end

#handle_error(error) ⇒ Object (private)



61
62
63
64
65
66
67
68
69
# File 'lib/apps/client.rb', line 61

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

#save_error_details(error) ⇒ Object (private)



71
72
73
74
75
76
77
78
79
# File 'lib/apps/client.rb', line 71

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