Class: ApkDownloader::Api
- Inherits:
-
Object
- Object
- ApkDownloader::Api
- Defined in:
- lib/apk_downloader/api.rb
Constant Summary collapse
- LoginUri =
URI('https://android.clients.google.com/auth')
- GoogleApiUri =
URI('https://android.clients.google.com/fdfe')
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
Instance Method Summary collapse
- #details(package) ⇒ Object
- #fetch_apk_data(package) ⇒ Object
-
#initialize ⇒ Api
constructor
A new instance of Api.
- #log_in! ⇒ Object
- #logged_in? ⇒ Boolean
Constructor Details
#initialize ⇒ Api
Returns a new instance of Api.
12 13 14 |
# File 'lib/apk_downloader/api.rb', line 12 def initialize @details_messages = {} end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
10 11 12 |
# File 'lib/apk_downloader/api.rb', line 10 def auth_token @auth_token end |
Instance Method Details
#details(package) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/apk_downloader/api.rb', line 60 def details package if @details_messages[package].nil? log_in! = api_request :get, '/details', :doc => package @details_messages[package] = .payload end return @details_messages[package] end |
#fetch_apk_data(package) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/apk_downloader/api.rb', line 70 def fetch_apk_data package log_in! doc = details(package).detailsResponse.docV2 version_code = doc.details.appDetails.versionCode offer_type = doc.offer[0].offerType = api_request :post, '/purchase', :ot => offer_type, :doc => package, :vc => version_code url = URI(.payload.buyResponse.purchaseStatusResponse.appDeliveryData.downloadUrl) = .payload.buyResponse.purchaseStatusResponse.appDeliveryData.downloadAuthCookie[0] resp = recursive_apk_fetch(url, ) return resp.body end |
#log_in! ⇒ Object
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 |
# File 'lib/apk_downloader/api.rb', line 20 def log_in! return if self.logged_in? params = { "Email" => ApkDownloader.configuration.email, "Passwd" => ApkDownloader.configuration.password, "service" => "androidmarket", "accountType" => "HOSTED_OR_GOOGLE", "has_permission" => "1", "source" => "android", "androidId" => ApkDownloader.configuration.android_id, "app" => "com.android.vending", "device_country" => "fr", "operatorCountry" => "fr", "lang" => "fr", "sdk_version" => "16" } login_http = Net::HTTP.new LoginUri.host, LoginUri.port login_http.use_ssl = true login_http.verify_mode = OpenSSL::SSL::VERIFY_NONE post = Net::HTTP::Post.new LoginUri.to_s post.set_form_data params post["Accept-Encoding"] = "" response = login_http.request post if ApkDownloader.configuration.debug pp "Login response:" pp response end if response.body =~ /error/i raise "Unable to authenticate with Google" elsif response.body.include? "Auth=" @auth_token = response.body.scan(/Auth=(.*?)$/).flatten.first end end |
#logged_in? ⇒ Boolean
16 17 18 |
# File 'lib/apk_downloader/api.rb', line 16 def logged_in? !self.auth_token.nil? end |