Class: AppleMusic::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_music/config.rb

Constant Summary collapse

ALGORITHM =
'ES256'
TOKEN_EXPIRATION_TIME =

1.day

60 * 60 * 24
DEFAULT_STOREFRONT =
'us'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



16
17
18
19
20
21
22
23
24
# File 'lib/apple_music/config.rb', line 16

def initialize
  @secret_key_path = ENV['APPLE_MUSIC_SECRET_KEY_PATH']
  @secret_key = ENV['APPLE_MUSIC_SECRET_KEY']
  @team_id = ENV['APPLE_MUSIC_TEAM_ID']
  @music_id = ENV['APPLE_MUSIC_MUSIC_ID']
  @token_expiration_time = TOKEN_EXPIRATION_TIME
  @adapter = Faraday.default_adapter
  @storefront = ENV.fetch('APPLE_MUSIC_STOREFRONT') { DEFAULT_STOREFRONT }
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



13
14
15
# File 'lib/apple_music/config.rb', line 13

def adapter
  @adapter
end

#music_idObject

Returns the value of attribute music_id.



13
14
15
# File 'lib/apple_music/config.rb', line 13

def music_id
  @music_id
end

#secret_keyObject

Returns the value of attribute secret_key.



13
14
15
# File 'lib/apple_music/config.rb', line 13

def secret_key
  @secret_key
end

#secret_key_pathObject

Returns the value of attribute secret_key_path.



13
14
15
# File 'lib/apple_music/config.rb', line 13

def secret_key_path
  @secret_key_path
end

#storefrontObject

Returns the value of attribute storefront.



13
14
15
# File 'lib/apple_music/config.rb', line 13

def storefront
  @storefront
end

#team_idObject

Returns the value of attribute team_id.



13
14
15
# File 'lib/apple_music/config.rb', line 13

def team_id
  @team_id
end

#token_expiration_timeObject

Returns the value of attribute token_expiration_time.



13
14
15
# File 'lib/apple_music/config.rb', line 13

def token_expiration_time
  @token_expiration_time
end

Instance Method Details

#authentication_tokenObject



26
27
28
29
# File 'lib/apple_music/config.rb', line 26

def authentication_token
  private_key = OpenSSL::PKey::EC.new(apple_music_secret_key)
  JWT.encode(authentication_payload, private_key, ALGORITHM, kid: music_id)
end