Class: IOSDeveloper::ProvisioningPortal

Inherits:
Object
  • Object
show all
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

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 (, password, team_name)
  @agent = Mechanize.new
  @username = 
  @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

  error_message = page.search(".errorMessage li span")
  raise error_message.text unless error_message.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=".", options)
  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 (options[: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_profilesObject



81
82
83
# File 'lib/iosdeveloper/provisioning_portal.rb', line 81

def get_development_profiles
  get_profiles(PROFILES_URL, 'development')
end

#get_distribution_profilesObject



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)
   = page.form_with(:name => 'appleConnectForm')
  if 
    ()
    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.expand_path(__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, options
  download_profile(profile_name, PROVISIONING_PROFILES_LOCATION, options)
end

#list_devicesObject



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_profilesObject



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 (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.options.first
  else
    team_option = team_list.option_with(:text => @team_name)
  end
  puts "Selecting team '#{team_option.text}'."
  team_option.select
  form.click_button(form.button_with(:name => 'action:saveTeamSelection!save'))
end