Class: IOSDeveloper::ProvisioningPortal
- Inherits:
-
Object
- Object
- IOSDeveloper::ProvisioningPortal
- Defined in:
- lib/iosdeveloper/provisioning_portal.rb
Constant Summary collapse
- DEVICES_URL =
"https://developer.apple.com/ios/manage/devices/index.action"
- PROFILES_URL =
"https://developer.apple.com/ios/manage/provisioningprofiles/index.action"
- DISTRIBUTION_PROFILES_URL =
"https://developer.apple.com/ios/manage/provisioningprofiles/viewDistributionProfiles.action"
- ADD_DEVICE_URL =
"https://developer.apple.com/ios/manage/devices/add.action"
- PROVISIONING_PROFILES_LOCATION =
"#{ENV['HOME']}/Library/MobileDevice/Provisioning Profiles"
Instance Method Summary collapse
- #add_device(name, id) ⇒ Object
- #download_profile(profile_name, location = ".", options) ⇒ Object
- #get_development_profiles ⇒ Object
- #get_distribution_profiles ⇒ Object
- #get_page(url) ⇒ Object
- #get_profiles(url, type) ⇒ Object
- #get_uuid(profile_file) ⇒ Object
-
#initialize(login, password, team_name) ⇒ ProvisioningPortal
constructor
A new instance of ProvisioningPortal.
- #install_profile(profile_name = nil, options) ⇒ Object
- #list_devices ⇒ Object
- #list_profiles ⇒ Object
- #login(form) ⇒ Object
- #profile_id(display_url) ⇒ Object
- #select_team(form) ⇒ Object
Constructor Details
#initialize(login, password, team_name) ⇒ ProvisioningPortal
Returns a new instance of ProvisioningPortal.
15 16 17 18 19 20 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 15 def initialize (login, password, team_name) @agent = Mechanize.new @username = login @password = password @team_name = team_name end |
Instance Method Details
#add_device(name, id) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 64 def add_device(name, id) page = get_page(ADD_DEVICE_URL) form = page.form_with(:name => 'add') form["deviceNameList[0]"] = name form["deviceNumberList[0]"] = id page = form.submit = page.search(".errorMessage li span") raise .text unless .empty? puts "Added device: #{id}" end |
#download_profile(profile_name, location = ".", options) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 104 def download_profile(profile_name, location=".", ) profiles = list_profiles profiles.each do |profile| if profile_name.nil? || (profile.name == profile_name) temporal_file_location = "#{profile.name}.mobileprovision" puts "Downloading #{profile.name} ..." @agent.get(profile.download_url).save(temporal_file_location) if ([:uuid]) file_location = "#{location}/#{get_uuid(temporal_file_location)}.mobileprovision" else file_location = "#{location}/#{profile.name}.mobileprovision" end FileUtils.move(temporal_file_location, file_location) puts "Saved #{profile.name} profile in #{file_location}" end end end |
#get_development_profiles ⇒ Object
81 82 83 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 81 def get_development_profiles get_profiles(PROFILES_URL, 'development') end |
#get_distribution_profiles ⇒ Object
85 86 87 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 85 def get_distribution_profiles get_profiles(DISTRIBUTION_PROFILES_URL, 'distribution') end |
#get_page(url) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 22 def get_page url page = @agent.get(url) login_form = page.form_with(:name => 'appleConnectForm') if login_form login(login_form) page = @agent.get(url) end team_select_form = page.form_with(:name => 'saveTeamSelection') if team_select_form page = select_team(team_select_form) end page end |
#get_profiles(url, type) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 89 def get_profiles(url, type) page = get_page(url) page.search("#remove table tbody tr").map do |item| name = item.at(".profile span").text app_id = item.at(".appid").text status = item.at(".statusXcode").child.text.strip download_url = item.at(".action a").attr("href") Profile.new(name, app_id, status, type, download_url) end end |
#get_uuid(profile_file) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 122 def get_uuid profile_file p7 = OpenSSL::PKCS7.new(File.read(profile_file)) store = OpenSSL::X509::Store.new cert = OpenSSL::X509::Certificate.new(File.read(File.join(File.dirname(File.(__FILE__)), '../AppleIncRootCertificate.cer'))) store.add_cert(cert) p7.verify([cert], store) hash = Plist::parse_xml(p7.data) hash["UUID"] end |
#install_profile(profile_name = nil, options) ⇒ Object
132 133 134 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 132 def install_profile profile_name=nil, download_profile(profile_name, PROVISIONING_PROFILES_LOCATION, ) end |
#list_devices ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 55 def list_devices page = get_page(DEVICES_URL) page.search("#removeDevice table tbody tr").map do |item| device_name = item.at(".name span").text device_id = item.at(".id").text "#{device_name} - #{device_id}" end end |
#list_profiles ⇒ Object
77 78 79 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 77 def list_profiles get_development_profiles + get_distribution_profiles end |
#login(form) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 48 def login(form) puts "Logging in with Apple ID '#{@username}'." form.theAccountName = @username form.theAccountPW = @password form.submit end |
#profile_id(display_url) ⇒ Object
100 101 102 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 100 def profile_id(display_url) /provDisplayId=(\w+)/.match(display_url)[1] end |
#select_team(form) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/iosdeveloper/provisioning_portal.rb', line 36 def select_team(form) team_list = form.field_with(:name => 'memberDisplayId') if @team_name.nil? || @team_name == '' team_option = team_list..first else team_option = team_list.option_with(:text => @team_name) end puts "Selecting team '#{team_option.text}'." team_option.select form.(form.(:name => 'action:saveTeamSelection!save')) end |