Last active
August 29, 2015 14:15
-
-
Save yiyuanlu/797463dd16c9cb194ca3 to your computer and use it in GitHub Desktop.
This file contains 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 'rubygems' | |
require 'mechanize' | |
if (ARGV[0] != '1' && ARGV[0] != '0') || (ARGV[0] == '1' && ARGV.size < 5) || (ARGV[0] == '0' && ARGV.size < 4) | |
puts %q{Usage: ruby xcode.rb HAS_MULTITEAM USERNAME PASSWORD TEAMID "DOWNLOAD_URL"} | |
puts %q{Example: ruby xcode.rb 0 myusername@apple.com 123456 "DOWNLOAD_URL" } | |
puts %q{Example: ruby xcode.rb 1 myusername@apple.com 123456 TEAMID "DOWNLOAD_URL" } | |
puts %q{DOWNLOAD_URL Example: https://developer.apple.com/devcenter/download.action?path=/Developer_Tools/xcode_6.1.1/xcode_6.1.1.dmg" } | |
exit | |
end | |
appleId = ARGV[1] | |
accountPassword = ARGV[2] | |
if ARGV[0] == '1' | |
teamId = ARGV[3] | |
downloadURL = ARGV[4] | |
else | |
downloadURL = ARGV[3] | |
end | |
a = Mechanize.new { |agent| | |
agent.user_agent_alias = 'Mac Safari' | |
} | |
a.get('https://developer.apple.com/') do |page| | |
member_page = a.click(page.link_with(:text => /Member Center/)) | |
teamSelect = member_page.form_with(:name => 'form2') do |form| | |
form.appleId = appleId | |
form.accountPassword = accountPassword | |
end.submit | |
# select team here | |
if ARGV[0] == '1' | |
login = teamSelect.form_with(:name => 'saveTeamSelection') do |form| | |
form.field_with(:name => 'memberDisplayId').option_with(:value => teamId).click | |
end.submit | |
end | |
a.redirect_ok = false | |
download_page = a.get(downloadURL) | |
system %Q{ aria2c -c -s10 -x10 #{download_page.response["location"]} --header "Cookie: #{download_page.response["set-cookie"][/ADCDownloadAuth=.*?;/]}" #{downloadURL}} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment