Class: CARMA::Client::MuleSoftClient
Defined Under Namespace
Classes: RecordParseError
Constant Summary
collapse
- STATSD_KEY_PREFIX =
'api.carma.mulesoft'
Instance Method Summary
collapse
#increment, #increment_failure, #increment_total, #with_monitoring
#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Instance Method Details
#create_submission_v2(payload) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/carma/client/mule_soft_client.rb', line 17
def create_submission_v2(payload)
with_monitoring do
res = if Flipper.enabled?(:cg1010_oauth_2_enabled)
perform_post(payload)
else
do_post('v2/application/1010CG/submit', payload, config.settings.async_timeout)
end
raise RecordParseError if res.dig('record', 'hasErrors')
res
end
end
|
#do_post(resource, payload, timeout = config.timeout) ⇒ Hash
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/carma/client/mule_soft_client.rb', line 36
def do_post(resource, payload, timeout = config.timeout)
with_monitoring do
Rails.logger.info "[Form 10-10CG] Submitting to '#{resource}'"
args = post_args(resource, payload, timeout)
resp = perform(*args)
Sentry.(response_body: resp.body)
raise_error_unless_success(resource, resp.status)
JSON.parse(resp.body)
end
end
|
#get_body(payload) ⇒ Object
92
93
94
|
# File 'lib/carma/client/mule_soft_client.rb', line 92
def get_body(payload)
payload.is_a?(String) ? payload : payload.to_json
end
|
#handle_response(resource, response) ⇒ Object
96
97
98
99
100
|
# File 'lib/carma/client/mule_soft_client.rb', line 96
def handle_response(resource, response)
Sentry.(response_body: response.body)
raise_error_unless_success(resource, response.status)
JSON.parse(response.body)
end
|
85
86
87
88
89
90
|
# File 'lib/carma/client/mule_soft_client.rb', line 85
def
{
'Authorization' => "Bearer #{bearer_token}",
'Content-Type' => 'application/json'
}
end
|
#perform_post(payload) ⇒ Object
New Authentication strategy Call Mulesoft with bearer token
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/carma/client/mule_soft_client.rb', line 64
def perform_post(payload)
resource = 'v2/application/1010CG/submit'
with_monitoring do
Rails.logger.info "[Form 10-10CG] Submitting to '#{resource}' using bearer token"
response = perform(
:post,
resource,
get_body(payload),
,
{ timeout: config.settings.async_timeout }
)
handle_response(resource, response)
end
end
|
#post_args(resource, payload, timeout) ⇒ Array
48
49
50
51
52
53
|
# File 'lib/carma/client/mule_soft_client.rb', line 48
def post_args(resource, payload, timeout)
body = payload.is_a?(String) ? payload : payload.to_json
= config.
opts = { timeout: }
[:post, resource, body, , opts]
end
|
#raise_error_unless_success(resource, status) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/carma/client/mule_soft_client.rb', line 55
def raise_error_unless_success(resource, status)
Rails.logger.info "[Form 10-10CG] Submission to '#{resource}' resource resulted in response code #{status}"
return if [200, 201, 202].include? status
raise Common::Exceptions::SchemaValidationErrors, ["Expecting 200 status but received #{status}"]
end
|