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.
11 12 13 |
# File 'lib/apk_downloader/api.rb', line 11 def initialize @details_messages = {} end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
9 10 11 |
# File 'lib/apk_downloader/api.rb', line 9 def auth_token @auth_token end |
Instance Method Details
#details(package) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/apk_downloader/api.rb', line 53 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/apk_downloader/api.rb', line 63 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
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 |
# File 'lib/apk_downloader/api.rb', line 19 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 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
15 16 17 |
# File 'lib/apk_downloader/api.rb', line 15 def logged_in? !self.auth_token.nil? end |