Class: ADCDownload::Client
- Inherits:
-
Spaceship::Client
- Object
- Spaceship::Client
- ADCDownload::Client
- Defined in:
- lib/adcdownload/client.rb
Instance Attribute Summary collapse
-
#download_cookie ⇒ Object
Returns the value of attribute download_cookie.
Class Method Summary collapse
Instance Method Summary collapse
-
#api_key ⇒ Object
Fetches the latest API Key from the Apple Dev Portal.
- #get_cookies(user, password) ⇒ Object
Instance Attribute Details
#download_cookie ⇒ Object
Returns the value of attribute download_cookie.
3 4 5 |
# File 'lib/adcdownload/client.rb', line 3 def @download_cookie end |
Class Method Details
.hostname ⇒ Object
5 6 7 |
# File 'lib/adcdownload/client.rb', line 5 def self.hostname "https://developer.apple.com/services-account/#{PROTOCOL_VERSION}/" end |
Instance Method Details
#api_key ⇒ Object
Fetches the latest API Key from the Apple Dev Portal
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/adcdownload/client.rb', line 10 def api_key cache_path = "/tmp/spaceship_api_key.txt" begin cached = File.read(cache_path) rescue Errno::ENOENT end return cached if cached landing_url = "https://developer.apple.com/account/" logger.info("GET: " + landing_url) response = @client.get(landing_url) headers = response.headers results = headers['location'].match(/.*appIdKey=(\h+)/) if (results || []).length > 1 api_key = results[1] File.write(cache_path, api_key) if api_key.length == 64 return api_key else raise "Could not find latest API Key from the Dev Portal - the server might be slow right now" end end |
#get_cookies(user, password) ⇒ Object
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 |
# File 'lib/adcdownload/client.rb', line 31 def (user, password) jar = HTTP::CookieJar.new(store: :hash, filename: 'cookies.txt') params = { appIdKey: api_key, accNameLocked: "false", language: "US-EN", path: '/account/', rv: "1", Env: "PROD", appleId: user, accountPassword: password } response = request(:post, "https://idmsa.apple.com/IDMSWebAuth/authenticate", params) jar.parse(response['Set-Cookie'], "http://idmsa.apple.com") if response['Set-Cookie'] =~ /myacinfo=(\w+);/ @cookie = "myacinfo=#{$1};" else raise InvalidUserCredentialsError.new, response end response = request(:get, "#{self.class.hostname}/downloadws/listDownloads.action") jar.parse(response['Set-Cookie'], "https://developer.apple.com") if response['Set-Cookie'] =~ /ADCDownloadAuth=([^;]+);/ @download_cookie = "ADCDownloadAuth=#{$1};" else raise InvalidUserCredentialsError.new, response end jar.each {|c| c.httponly = false} jar.save(".adccookies", format: :cookiestxt, session: true) end |