Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
update docs and make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
snatchev committed May 18, 2015
1 parent eb8d599 commit 7ba6154
Show file tree
Hide file tree
Showing 9 changed files with 13,395 additions and 51 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,27 @@ profiles = Spaceship.provisioning_profiles
create a distribution provisioning profile for an app
```ruby
production_cert = Spaceship.certificates.select {|c| c.is_a?(Spaceship::Certificates::Production)}.first
Spaceship::ProvisioningProfile.create!(Spaceship::ProvisioningProfiles::AppStore, 'Flappy Bird 2.0', 'tools.fastlane.flappy-bird', production_cert)
Spaceship::ProvisioningProfile::AppStore.create!('Flappy Bird 2.0', 'tools.fastlane.flappy-bird', production_cert)
```

Named Parameters
```ruby
Spaceship.ProvisioningProfile.create!(
klass: Spaceship::ProvisioningProfiles::Development,
Spaceship::ProvisioningProfile::Development.create!(
name: "Spaceship",
bundle_id: "net.sunapps.1",
certificate: Spaceship.certificates.all_of_type(Spaceship::Certificates::Development).first,
devices: [Spaceship.devices.first]
)
devices: [Spaceship.devices.first])
```

download the .mobileprovision profile
```ruby
file = Spaceship.ProvisioningProfile.download('tools.fastlane.flappy-bird')
profile = Spaceship.provisioning_profiles.find do |pp|
pp.app.bundle_id == 'net.sunapps.1' && pp.distribution_method == 'store'
end
file = profile.download

#provisioning profiles also can be scoped by their types like this:
file = Spaceship::ProvisioningProfile::AppStore.find {|p| pp.app.bundle_id == 'net.sunapps.1' }.download
```

Check out the wiki for a full list of all supported actions.
Expand Down
6 changes: 5 additions & 1 deletion lib/spaceship/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ class App < Base
)

class << self
def factory(attrs)
self.new(attrs)
end

def all
client.apps.map {|app| self.new(app) }
client.apps.map {|app| self.factory(app) }
end

# Creates a new App ID on the Apple Dev Portal
Expand Down
12 changes: 8 additions & 4 deletions lib/spaceship/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def login(username = nil, password = nil)

if response['Set-Cookie'] =~ /myacinfo=(\w+);/
@cookie = "myacinfo=#{$1};"

return @client
else
# User Credentials are wrong
Expand Down Expand Up @@ -279,9 +278,8 @@ def request(method, url_or_path = nil, params = nil, headers = {}, &block)

#form-encode the params only if there are params, and the block is not supplied.
# this is so that certain requests can be made using the block for more control
if params && !block_given?
params = Faraday::Utils::ParamsHash[params].to_query
headers = {'Content-Type' => 'application/x-www-form-urlencoded'}.merge(headers)
if method == :post && params && !block_given?
params, headers = encode_params(params, headers)
end

@last_response = @client.send(method, url_or_path, params, headers, &block)
Expand All @@ -300,5 +298,11 @@ def parse_response(expected_key = nil)
content
end
end

def encode_params(params, headers)
params = Faraday::Utils::ParamsHash[params].to_query
headers = {'Content-Type' => 'application/x-www-form-urlencoded'}.merge(headers)
return params, headers
end
end
end
6 changes: 5 additions & 1 deletion lib/spaceship/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ class Device < Base
})

class << self
def factory(attrs)
self.new(attrs)
end

def all
client.devices.map {|device| self.new(device)}
client.devices.map {|device| self.factory(device)}
end

def find(device_id)
Expand Down
15 changes: 11 additions & 4 deletions lib/spaceship/provisioning_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ProvisioningProfile < Base
'type' => :type,
'version' => :version,
'proProPlatform' => :platform,
'managingApp' => :managing_app
'managingApp' => :managing_app,
'appId' => :app
})

class << self
Expand All @@ -36,8 +37,9 @@ def factory(attrs)
raise attrs['distributionMethod']
end

attrs['devices'].map! {|d| Device.new(d) }
attrs['certificates'].map! {|c| Certificate.factory(c) }
attrs['appId'] = App.factory(attrs['appId'])
attrs['devices'].map! {|device| Device.factory(device) }
attrs['certificates'].map! {|cert| Certificate.factory(cert) }

klass.new(attrs)
end
Expand All @@ -53,9 +55,14 @@ def all
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

#filter out the profiles that don't match the class.
#only return the profiles that match the class
profiles.select do |profile|
profile.class == self
end
Expand Down
Loading

0 comments on commit 7ba6154

Please sign in to comment.