Class: Spaceship::Portal::Key

Inherits:
Spaceship::PortalBase show all
Defined in:
spaceship/lib/spaceship/portal/key.rb

Constant Summary collapse

APNS_ID =

data model for managing JWT tokens or “Keys” as the ADP refers to them

'U27F4V844T'
DEVICE_CHECK_ID =
'DQ8HTZ7739'
MUSIC_KIT_ID =
'6A7HVUVQ3M'

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #raw_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spaceship::PortalBase

client

Methods inherited from Base

attr_accessor, attr_mapping, #attributes, attributes, factory, #initialize, #inspect, mapping_module, method_missing, set_client, #setup, #to_s

Constructor Details

This class inherits a constructor from Spaceship::Base

Instance Attribute Details

#idObject

Returns the value of attribute id


13
14
15
# File 'spaceship/lib/spaceship/portal/key.rb', line 13

def id
  @id
end

#nameObject

Returns the value of attribute name


14
15
16
# File 'spaceship/lib/spaceship/portal/key.rb', line 14

def name
  @name
end

Class Method Details

.allObject


24
25
26
27
28
29
# File 'spaceship/lib/spaceship/portal/key.rb', line 24

def self.all
  keys = client.list_keys
  keys.map do |key|
    new(key)
  end
end

.create(name: nil, apns: nil, device_check: nil, music_id: nil) ⇒ Object

Creates a new JWT / Key for making requests to services.

Parameters:

  • name (String) (defaults to: nil)

    the name of the key

  • apns (Bool) (defaults to: nil)

    whether the key should be able to make APNs requests

  • device_check (Bool) (defaults to: nil)

    whether the key should be able to make DeviceCheck requests

  • music_id (String) (defaults to: nil)

    the Music Id id (the autogenerated id, not the user specified identifier “music.com.etc…”)


43
44
45
46
47
48
49
50
51
# File 'spaceship/lib/spaceship/portal/key.rb', line 43

def self.create(name: nil, apns: nil, device_check: nil, music_id: nil)
  service_config = {}
  service_config[APNS_ID] = [] if apns
  service_config[DEVICE_CHECK_ID] = [] if device_check
  service_config[MUSIC_KIT_ID] = [music_id] if music_id

  key = client.create_key!(name: name, service_configs: service_config)
  new(key)
end

.find(id) ⇒ Object


31
32
33
34
# File 'spaceship/lib/spaceship/portal/key.rb', line 31

def self.find(id)
  key = client.get_key(id: id)
  new(key)
end

Instance Method Details

#downloadObject


57
58
59
# File 'spaceship/lib/spaceship/portal/key.rb', line 57

def download
  client.download_key(id: id)
end

#has_apns?Boolean

Returns:

  • (Boolean)

72
73
74
# File 'spaceship/lib/spaceship/portal/key.rb', line 72

def has_apns?
  has_service?(APNS_ID)
end

#has_device_check?Boolean

Returns:

  • (Boolean)

80
81
82
# File 'spaceship/lib/spaceship/portal/key.rb', line 80

def has_device_check?
  has_service?(DEVICE_CHECK_ID)
end

#has_music_kit?Boolean

Returns:

  • (Boolean)

76
77
78
# File 'spaceship/lib/spaceship/portal/key.rb', line 76

def has_music_kit?
  has_service?(MUSIC_KIT_ID)
end

#reloadObject


84
85
86
# File 'spaceship/lib/spaceship/portal/key.rb', line 84

def reload
  self.raw_data = self.class.find(id).raw_data
end

#revoke!Object


53
54
55
# File 'spaceship/lib/spaceship/portal/key.rb', line 53

def revoke!
  client.revoke_key!(id: id)
end

#service_configs_for(service_id) ⇒ Object


66
67
68
69
70
# File 'spaceship/lib/spaceship/portal/key.rb', line 66

def service_configs_for(service_id)
  if (service = find_service(service_id))
    service['configurations']
  end
end

#servicesObject


61
62
63
64
# File 'spaceship/lib/spaceship/portal/key.rb', line 61

def services
  raw_data['services'] || reload
  super
end