Created
May 6, 2011 12:06
-
-
Save runeb/958835 to your computer and use it in GitHub Desktop.
A script for accessing the iOS provisioning portal programmatically. Probably a bit outdated now, and assumes you are part of several teams. CUD of CRUD not impl.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'bundler/setup' | |
| require 'mechanize' | |
| class Device | |
| attr_accessor :name, :uuid, :id | |
| end | |
| class ProvisioningPortal | |
| attr_reader :connection | |
| def initialize(user, pass, team) | |
| start_session(user, pass, team) | |
| true | |
| end | |
| def devices | |
| @devices ||= begin | |
| page = @connection.get('http://developer.apple.com/ios/manage/devices/index.action') | |
| doc = Nokogiri::HTML.parse(page.send(:html_body)) | |
| devices_raw = doc.css('tr') | |
| devices_raw.shift | |
| devices_raw.map do |d| | |
| device = Device.new | |
| device.id = d.children.css('input').attr('value').text | |
| device.name = d.children[2].text | |
| device.uuid = d.children[4].text | |
| device | |
| end | |
| end | |
| end | |
| private | |
| def start_session(user, pass, team) | |
| a = Mechanize.new do |agent| | |
| agent.follow_meta_refresh = true | |
| agent.history.max_size = 1 | |
| end | |
| manage_devices = 'http://developer.apple.com/ios/manage/devices/index.action' | |
| a.get(manage_devices) do |page| | |
| form = page.form_with(:name => 'appleConnectForm') do |login| | |
| login['theAccountName'] = user | |
| login['theAccountPW'] = pass | |
| end | |
| next_page = form.click_button(form.buttons.first) | |
| if teamSelectForm = next_page.forms.detect {|f| f.name == 'saveTeamSelection'} | |
| select_list = teamSelectForm.fields.first | |
| team_found = false | |
| select_list.options.each do |o| | |
| if o.text == team | |
| o.tick | |
| team_found = true | |
| end | |
| end | |
| if team_found | |
| next_page = teamSelectForm.click_button(teamSelectForm.buttons.last) | |
| else | |
| raise "Could not find team #{team}!" | |
| end | |
| end | |
| end | |
| @connection = a | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment