Commit 3e7f4801 authored by Rubén Dávila's avatar Rubén Dávila

Address suggestions from last code review

- Standardize usage of quotes
- Refactor Gitlab::SubscriptionPortal::Client#parse_response
- Fix code that reads errors from HTTP response
parent ee8717a9
......@@ -8,7 +8,7 @@ module GitlabSubscriptions
if response[:success]
{ success: true }
else
{ success: false, errors: response[:data]&.errors }
{ success: false, errors: response.dig(:data, 'errors') }
end
end
......
......@@ -19,27 +19,22 @@ module Gitlab
def headers
{
"Accept" => 'application/json',
'Accept' => 'application/json',
'Content-Type' => 'application/json',
"X-Admin-Email" => ENV['SUBSCRIPTION_PORTAL_ADMIN_EMAIL'],
"X-Admin-Token" => ENV['SUBSCRIPTION_PORTAL_ADMIN_TOKEN']
'X-Admin-Email' => ENV['SUBSCRIPTION_PORTAL_ADMIN_EMAIL'],
'X-Admin-Token' => ENV['SUBSCRIPTION_PORTAL_ADMIN_TOKEN']
}
end
def parse_response(http_response)
response = { success: false }
case http_response.response
when Net::HTTPSuccess
response[:success] = true
response[:data] = http_response.parsed_response
{ success: true, data: http_response.parsed_response }
when Net::HTTPUnprocessableEntity
response[:data] = http_response.parsed_response
{ success: false, data: http_response.parsed_response }
else
response[:data] = { errors: "HTTP status code: #{http_response.code}" }
{ success: false, data: "HTTP status code: #{http_response.code}" }
end
response
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment