Commit 473bf37c authored by Rubén Dávila's avatar Rubén Dávila

Add API client to talk with subscription portal

parent 67e35588
......@@ -3,7 +3,19 @@
module GitlabSubscriptions
class CreateLeadService
def execute(company_params)
{ success: true }
response = subscription_app_client.create_trial_account(company_params)
if response.success
{ success: true }
else
{ success: false, errors: response.data&.errors }
end
end
private
def subscription_app_client
Gitlab::SubscriptionPortal::Client.new
end
end
end
# frozen_string_literal: true
module Gitlab
module SubscriptionPortal
class Client
def create_trial_account(params)
parse_response(Gitlab::HTTP.post("#{base_url}/trials",
body: params.to_json,
headers: headers))
end
private
def base_url
EE::SUBSCRIPTIONS_URL
end
def headers
{
"Accept" => 'application/json',
"X-Admin-Email" => ENV['SUBSCRIPTION_PORTAL_ADMIN_EMAIL'],
"X-Admin-Token" => ENV['SUBSCRIPTION_PORTAL_ADMIN_TOKEN']
}
end
def parse_response(http_response)
response = Hashie::Mash.new(success: false)
case http_response.response
when Net::HTTPSuccess
response.success = true
response.data = JSON.parse(response.body)
when Net::HTTPUnprocessableEntity
response.data = JSON.parse(response.body) rescue nil
else
response.data = { errors: "HTTP status code: #{http_response.code}" }
end
response
end
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