Class: Spaceship::ConnectAPI::Profile

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
spaceship/lib/spaceship/connect_api/models/profile.rb

Defined Under Namespace

Modules: ProfileState, ProfileType

Instance Attribute Summary collapse

Attributes included from Model

#id, #reverse_attr_map

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#attr_mapping, included, #initialize, #reverse_attr_mapping, #to_json, #update_attributes

Instance Attribute Details

#bundle_idObject

Returns the value of attribute bundle_id.



17
18
19
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 17

def bundle_id
  @bundle_id
end

#certificatesObject

Returns the value of attribute certificates.



18
19
20
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 18

def certificates
  @certificates
end

#created_dateObject

Returns the value of attribute created_date.



12
13
14
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 12

def created_date
  @created_date
end

#devicesObject

Returns the value of attribute devices.



19
20
21
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 19

def devices
  @devices
end

#expiration_dateObject

Returns the value of attribute expiration_date.



15
16
17
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 15

def expiration_date
  @expiration_date
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 8

def name
  @name
end

#platformObject

Returns the value of attribute platform.



9
10
11
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 9

def platform
  @platform
end

#profile_contentObject

Returns the value of attribute profile_content.



10
11
12
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 10

def profile_content
  @profile_content
end

#profile_stateObject

Returns the value of attribute profile_state.



13
14
15
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 13

def profile_state
  @profile_state
end

#profile_typeObject

Returns the value of attribute profile_type.



14
15
16
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 14

def profile_type
  @profile_type
end

#uuidObject

Returns the value of attribute uuid.



11
12
13
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 11

def uuid
  @uuid
end

Class Method Details

.all(client: nil, filter: {}, includes: nil, fields: nil, limit: Spaceship::ConnectAPI::MAX_OBJECTS_PER_PAGE_LIMIT, sort: nil) ⇒ Object

API



81
82
83
84
85
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 81

def self.all(client: nil, filter: {}, includes: nil, fields: nil, limit: Spaceship::ConnectAPI::MAX_OBJECTS_PER_PAGE_LIMIT, sort: nil)
  client ||= Spaceship::ConnectAPI
  resps = client.get_profiles(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort).all_pages
  return resps.flat_map(&:to_models)
end

.create(client: nil, name: nil, profile_type: nil, bundle_id_id: nil, certificate_ids: nil, device_ids: nil, template_name: nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 87

def self.create(client: nil, name: nil, profile_type: nil, bundle_id_id: nil, certificate_ids: nil, device_ids: nil, template_name: nil)
  client ||= Spaceship::ConnectAPI
  resp = client.post_profiles(
    bundle_id_id: bundle_id_id,
    certificates: certificate_ids,
    devices: device_ids,
    attributes: {
      name: name,
      profileType: profile_type,
      templateName: template_name
    }
  )
  return resp.to_models.first
end

.typeObject



62
63
64
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 62

def self.type
  return "profiles"
end

Instance Method Details

#delete!(client: nil) ⇒ Object



114
115
116
117
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 114

def delete!(client: nil)
  client ||= Spaceship::ConnectAPI
  return client.delete_profile(profile_id: id)
end

#fetch_all_certificates(client: nil, filter: {}, includes: nil, sort: nil) ⇒ Object



108
109
110
111
112
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 108

def fetch_all_certificates(client: nil, filter: {}, includes: nil, sort: nil)
  client ||= Spaceship::ConnectAPI
  resps = client.get_certificates(profile_id: id, filter: filter, includes: includes).all_pages
  return resps.flat_map(&:to_models)
end

#fetch_all_devices(client: nil, filter: {}, includes: nil, sort: nil) ⇒ Object



102
103
104
105
106
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 102

def fetch_all_devices(client: nil, filter: {}, includes: nil, sort: nil)
  client ||= Spaceship::ConnectAPI
  resps = client.get_devices(profile_id: id, filter: filter, includes: includes).all_pages
  return resps.flat_map(&:to_models)
end

#valid?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
# File 'spaceship/lib/spaceship/connect_api/models/profile.rb', line 66

def valid?
  # Provisioning profiles are not invalidated automatically on the dev portal when the certificate expires.
  # They become Invalid only when opened directly in the portal 🤷.
  # We need to do an extra check on the expiration date to ensure the profile is valid.
  expired = Time.now.utc > Time.parse(self.expiration_date)

  is_valid = profile_state == ProfileState::ACTIVE && !expired

  return is_valid
end