Class: Spaceship::ProvisioningProfile
- Defined in:
- lib/spaceship/provisioning_profile.rb
Overview
Represents a provisioning profile of the Apple Dev Portal
Direct Known Subclasses
Defined Under Namespace
Classes: AdHoc, AppStore, Development, InHouse
Instance Attribute Summary collapse
-
#app ⇒ App
A reference to the app this profile is for.
-
#certificates ⇒ Array
A list of certificates used for this profile.
-
#devices ⇒ Array
A list of devices this profile is enabled for.
-
#distribution_method ⇒ String
The profile distribution type.
-
#expires ⇒ DateTime
The date and time of when the profile expires.
-
#id ⇒ String
The ID generated by the Dev Portal You’ll probably not really need this value.
-
#managing_app ⇒ Object
No information about this attribute.
-
#name ⇒ String
The name of this profile.
-
#platform ⇒ String
The supported platform for this profile.
-
#status ⇒ String
The status of this profile.
-
#type ⇒ String
The type of the profile (development or distribution).
-
#uuid ⇒ String
The UDID of this provisioning profile This value is used for example for code signing It is also contained in the actual profile.
-
#version ⇒ String
This will always be “2”.
Class Method Summary collapse
-
.all ⇒ Array
Returns all profiles registered for this account If you’re calling this from a subclass (like AdHoc), this will only return the profiles that are of this type.
-
.create!(name: nil, bundle_id: nil, certificate: nil, devices: []) ⇒ ProvisioningProfile
Create a new provisioning profile.
-
.factory(attrs) ⇒ Object
Create a new object based on a hash.
-
.find_by_bundle_id(bundle_id) ⇒ Array
Returns an array of provisioning profiles matching the bundle identifier Returns [] if no profiles were found This may also contain invalid or expired profiles.
-
.pretty_type ⇒ String
The human readable name of this profile type.
-
.type ⇒ String
The profile type used for web requests to the Dev Portal.
Instance Method Summary collapse
-
#certificate_valid? ⇒ Bool
Is the certificate of this profile available?.
-
#delete! ⇒ Object
Delete the provisioning profile.
-
#download ⇒ String
Download the current provisioning profile.
-
#managed_by_xcode? ⇒ Bool
Is this profile managed by Xcode?.
-
#repair! ⇒ ProvisioningProfile
Repair an existing provisioning profile alias to update!.
-
#update! ⇒ ProvisioningProfile
Updates the provisioning profile from the local data e.g.
-
#valid? ⇒ Bool
Is the current provisioning profile valid?.
Methods inherited from Base
attr_mapping, #client, #initialize, #inspect, method_missing, remap_keys!, set_client
Constructor Details
This class inherits a constructor from Spaceship::Base
Instance Attribute Details
#app ⇒ App
A reference to the app this profile is for. You can then easily access the value directly
85 86 87 |
# File 'lib/spaceship/provisioning_profile.rb', line 85 def app @app end |
#certificates ⇒ Array
Returns A list of certificates used for this profile.
104 105 106 |
# File 'lib/spaceship/provisioning_profile.rb', line 104 def certificates @certificates end |
#devices ⇒ Array
Returns A list of devices this profile is enabled for. This will always be [] for AppStore profiles.
119 120 121 |
# File 'lib/spaceship/provisioning_profile.rb', line 119 def devices @devices end |
#distribution_method ⇒ String
Returns The profile distribution type. You probably want to use the class type to detect the profile type instead of this string.
31 32 33 |
# File 'lib/spaceship/provisioning_profile.rb', line 31 def distribution_method @distribution_method end |
#expires ⇒ DateTime
Returns The date and time of when the profile expires.
21 22 23 |
# File 'lib/spaceship/provisioning_profile.rb', line 21 def expires @expires end |
#id ⇒ String
Returns The ID generated by the Dev Portal You’ll probably not really need this value.
8 9 10 |
# File 'lib/spaceship/provisioning_profile.rb', line 8 def id @id end |
#managing_app ⇒ Object
No information about this attribute
66 67 68 |
# File 'lib/spaceship/provisioning_profile.rb', line 66 def managing_app @managing_app end |
#name ⇒ String
Returns The name of this profile.
36 37 38 |
# File 'lib/spaceship/provisioning_profile.rb', line 36 def name @name end |
#platform ⇒ String
Returns The supported platform for this profile.
63 64 65 |
# File 'lib/spaceship/provisioning_profile.rb', line 63 def platform @platform end |
#status ⇒ String
Returns The status of this profile.
45 46 47 |
# File 'lib/spaceship/provisioning_profile.rb', line 45 def status @status end |
#type ⇒ String
Returns The type of the profile (development or distribution). You’ll probably not need this value.
53 54 55 |
# File 'lib/spaceship/provisioning_profile.rb', line 53 def type @type end |
#uuid ⇒ String
Returns The UDID of this provisioning profile This value is used for example for code signing It is also contained in the actual profile.
15 16 17 |
# File 'lib/spaceship/provisioning_profile.rb', line 15 def uuid @uuid end |
#version ⇒ String
Returns This will always be “2”.
58 59 60 |
# File 'lib/spaceship/provisioning_profile.rb', line 58 def version @version end |
Class Method Details
.all ⇒ Array
Returns all profiles registered for this account If you’re calling this from a subclass (like AdHoc), this will only return the profiles that are of this type
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/spaceship/provisioning_profile.rb', line 223 def all profiles = client.provisioning_profiles.map do |profile| self.factory(profile) end # filter out the profiles managed by xcode profiles.delete_if do |profile| profile.managed_by_xcode? end return profiles if self == ProvisioningProfile # only return the profiles that match the class profiles.select do |profile| profile.class == self end end |
.create!(name: nil, bundle_id: nil, certificate: nil, devices: []) ⇒ ProvisioningProfile
Create a new provisioning profile
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/spaceship/provisioning_profile.rb', line 193 def create!(name: nil, bundle_id: nil, certificate: nil, devices: []) raise "Missing required parameter 'bundle_id'" if bundle_id.to_s.empty? raise "Missing required parameter 'certificate'. e.g. use `Spaceship::Certificate::Production.all.first`" if certificate.to_s.empty? app = Spaceship::App.find(bundle_id) raise "Could not find app with bundle id '#{bundle_id}'" unless app # Fill in sensible default values name ||= [bundle_id, self.pretty_type].join(' ') devices = [] if self == AppStore # App Store Profiles MUST NOT have devices if devices.nil? or devices.count == 0 if self == Development or self == AdHoc # For Development and AdHoc we usually want all devices by default devices = Spaceship::Device.all end end profile = client.create_provisioning_profile!(name, self.type, app.app_id, [certificate.id], devices.map {|d| d.id} ) self.new(profile) end |
.factory(attrs) ⇒ Object
Create a new object based on a hash. This is used to create a new object based on the server response.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/spaceship/provisioning_profile.rb', line 148 def factory(attrs) # Ad Hoc Profiles look exactly like App Store profiles, but usually include devices attrs['distributionMethod'] = 'adhoc' if attrs['distributionMethod'] == 'store' && attrs['devices'].size > 0 # available values of `distributionMethod` at this point: ['adhoc', 'store', 'limited'] klass = case attrs['distributionMethod'] when 'limited' Development when 'store' AppStore when 'adhoc' AdHoc when 'inhouse' InHouse else raise "Can't find class '#{attrs['distributionMethod']}'" end attrs['appId'] = App.factory(attrs['appId']) attrs['devices'].map! { |device| Device.factory(device) } attrs['certificates'].map! { |cert| Certificate.factory(cert) } klass.client = @client klass.new(attrs) end |
.find_by_bundle_id(bundle_id) ⇒ Array
Returns an array of provisioning profiles matching the bundle identifier Returns [] if no profiles were found This may also contain invalid or expired profiles
245 246 247 248 249 |
# File 'lib/spaceship/provisioning_profile.rb', line 245 def find_by_bundle_id(bundle_id) all.find_all do |profile| profile.app.bundle_id == bundle_id end end |
.pretty_type ⇒ String
Returns The human readable name of this profile type.
180 181 182 |
# File 'lib/spaceship/provisioning_profile.rb', line 180 def pretty_type name.split('::').last end |
.type ⇒ String
Returns The profile type used for web requests to the Dev Portal.
142 143 144 |
# File 'lib/spaceship/provisioning_profile.rb', line 142 def type raise "You cannot create a ProvisioningProfile without a type. Use a subclass." end |
Instance Method Details
#certificate_valid? ⇒ Bool
Is the certificate of this profile available?
340 341 342 343 344 345 346 347 348 |
# File 'lib/spaceship/provisioning_profile.rb', line 340 def certificate_valid? return false if (certificates || []).count == 0 certificates.each do |c| if Spaceship::Certificate.all.collect { |s| s.id }.include?(c.id) return true end end return false end |
#delete! ⇒ Object
Delete the provisioning profile
293 294 295 |
# File 'lib/spaceship/provisioning_profile.rb', line 293 def delete! client.delete_provisioning_profile!(self.id) end |
#download ⇒ String
Download the current provisioning profile. This will not store the provisioning profile on the file system. Instead this method will return the content of the profile.
288 289 290 |
# File 'lib/spaceship/provisioning_profile.rb', line 288 def download client.download_provisioning_profile(self.id) end |
#managed_by_xcode? ⇒ Bool
Returns Is this profile managed by Xcode?.
356 357 358 |
# File 'lib/spaceship/provisioning_profile.rb', line 356 def managed_by_xcode? managing_app == 'Xcode' end |
#repair! ⇒ ProvisioningProfile
Repair an existing provisioning profile alias to update!
301 302 303 |
# File 'lib/spaceship/provisioning_profile.rb', line 301 def repair! update! end |
#update! ⇒ ProvisioningProfile
Updates the provisioning profile from the local data e.g. after you added new devices to the profile This will also update the code signing identity if necessary
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/spaceship/provisioning_profile.rb', line 310 def update! unless certificate_valid? if self.kind_of?Development self.certificates = [Spaceship::Certificate::Development.all.first] elsif self.kind_of?InHouse self.certificates = [Spaceship::Certificate::InHouse.all.first] else self.certificates = [Spaceship::Certificate::Production.all.first] end end client.repair_provisioning_profile!( self.id, self.name, self.distribution_method, self.app.app_id, self.certificates.map { |c| c.id }, self.devices.map { |d| d.id } ) # We need to fetch the provisioning profile again, as the ID changes profile = Spaceship::ProvisioningProfile.all.find do |profile| profile.name == self.name # we can use the name as it's valid end return profile end |
#valid? ⇒ Bool
Returns Is the current provisioning profile valid?.
351 352 353 |
# File 'lib/spaceship/provisioning_profile.rb', line 351 def valid? return (status == 'Active' and certificate_valid?) end |