Module: TDAuthService

Defined in:
lib/fastlane/plugin/appcircle_testing_distribution/helper/TDAuthService.rb

Class Method Summary collapse

Class Method Details

.get_ac_token(pat:) ⇒ Object



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)

  # Create HTTP request
  request = Net::HTTP::Post.new(uri)
  request.content_type = 'application/x-www-form-urlencoded'
  request['Accept'] = 'application/json'
  
  # Encode parameters
  params = { pat: pat }
  request.body = URI.encode_www_form(params)

  # Make the HTTP request
  response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
    http.request(request)
  end

  

  # Check response
  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