Class: AppStoreConnectAPI::Client

Inherits:
Object
  • Object
show all
Includes:
TestFlight::BetaTesters, HTTParty
Defined in:
lib/app_store_connect_api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TestFlight::BetaTesters

#beta_tester, #beta_testers

Constructor Details

#initialize(issuer_id, key_id, access_key_path) ⇒ Client

Configure the client

Examples:

client = AppStoreConnectAPI::Client.new(issuer_id, key_id, access_key_path)

Parameters:

  • issuer_id (String)

    the issuer id found under the users and access page in App Store Connect

  • key_id (String)

    the key id specific to the following access key

  • access_key_path (String)

    path to the access key p8 file used to generate the jwt for authentication with the api

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/app_store_connect_api/client.rb', line 32

def initialize(issuer_id, key_id, access_key_path)
  raise ConfigurationError, 'issuer_id is required' if issuer_id.nil?
  raise ConfigurationError, 'key_id is required' if key_id.nil?
  raise ConfigurationError, 'access_key_path is required' if access_key_path.nil?

  private_key = OpenSSL::PKey.read(File.read(access_key_path))
  @token = JWT.encode(
    {
      iss: issuer_id,
      exp: Time.now.to_i + 20 * 60,
      aud: 'appstoreconnect-v1'
    },
    private_key,
    'ES256',
    header_fields={
      kid: key_id
    }
  )
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



22
23
24
# File 'lib/app_store_connect_api/client.rb', line 22

def token
  @token
end

Instance Method Details

#headersObject



52
53
54
# File 'lib/app_store_connect_api/client.rb', line 52

def headers
  { 'Authorization' => "Bearer #{@token}" }
end