16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/fastlane/plugin/appcircle_testing_distribution/helper/TDAuthService.rb', line 16
def self.get_ac_token(pat:)
endpoint_url = 'https://auth.appcircle.io/auth/v2/token'
uri = URI(endpoint_url)
request = Net::HTTP::Post.new(uri)
request.content_type = 'application/x-www-form-urlencoded'
request['Accept'] = 'application/json'
params = { pat: pat }
request.body = URI.encode_www_form(params)
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(request)
end
if response.is_a?(Net::HTTPSuccess)
response_data = JSON.parse(response.body)
user = UserResponse.new(
accessToken: response_data['access_token']
)
return user
else
raise "HTTP Request failed (#{response.code} #{response.message})"
end
end
|