Class: XcodeInstaller::Agent
- Inherits:
-
Mechanize
- Object
- Mechanize
- XcodeInstaller::Agent
- Defined in:
- lib/xcode-installer/agent.rb
Instance Attribute Summary collapse
-
#dry_run ⇒ Object
Returns the value of attribute dry_run.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #download(xcode_url) ⇒ Object
-
#initialize ⇒ Agent
constructor
A new instance of Agent.
Constructor Details
#initialize ⇒ Agent
Returns a new instance of Agent.
9 10 11 12 13 14 15 |
# File 'lib/xcode-installer/agent.rb', line 9 def initialize super self.user_agent_alias = 'Mac Safari' pw = Security::InternetPassword.find(:server => XcodeInstaller::AppleDeveloperCenter::HOST) @username, @password = pw.attributes['acct'], pw.password if pw end |
Instance Attribute Details
#dry_run ⇒ Object
Returns the value of attribute dry_run.
7 8 9 |
# File 'lib/xcode-installer/agent.rb', line 7 def dry_run @dry_run end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/xcode-installer/agent.rb', line 7 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/xcode-installer/agent.rb', line 7 def username @username end |
#verbose ⇒ Object
Returns the value of attribute verbose.
7 8 9 |
# File 'lib/xcode-installer/agent.rb', line 7 def verbose @verbose end |
Instance Method Details
#download(xcode_url) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/xcode-installer/agent.rb', line 17 def download(xcode_url) adc_login_url = XcodeInstaller::AppleDeveloperCenter::LOGIN_URL downloads_url = XcodeInstaller::AppleDeveloperCenter::DOWNLOADS_URL begin # Request login response puts "\n>>> Login response >>>" if @verbose response = get(adc_login_url) if @verbose puts "status code: #{response.code}\n" pp response puts .jar end # Submit login form puts "\n>>> Submit Login Form >>>" if @verbose form = response.form_with(:name => 'appleConnectForm') form.theAccountName = username form.theAccountPW = password response = form.submit if @verbose puts "status code: #{response.code}\n" pp response puts .jar end # Request downloads response puts "\n>>> Downloads >>>" if @verbose response = get(downloads_url) if @verbose puts "status code: #{response.code}\n" pp response puts .jar end # Shouldn't get the login form if login was successful form = response.form_with(:name => 'appleConnectForm') raise UnsuccessfulAuthenticationError if form # Download puts "\n>>> Xcode >>>" if @verbose if @dry_run # HEAD request for testing response = head(xcode_url) if @verbose puts "status code: #{response.code}\n" pp response else puts "filename: #{response.filename}" puts "size: #{response.header['content-length']}" puts "last-modified: #{response.header['last-modified']}" return response.filename end else # GET request for actual download pluggable_parser.default = Mechanize::Download self.{ file = get(xcode_url) } file = get(xcode_url) file.save return file.filename end rescue Mechanize::ResponseCodeError => exception if exception.response_code == '403' response = exception.page puts "The file doesn't exist at that location or access denied (status code: #{response.code})\n" puts "\n>>> Unexpected response >>>" if @verbose pp response if @verbose else raise # Some other error, re-raise end end end |