Class: Googlepub::APK
- Inherits:
-
Object
- Object
- Googlepub::APK
- Defined in:
- lib/googlepub/apk.rb
Instance Method Summary collapse
-
#initialize(file, track) ⇒ APK
constructor
A new instance of APK.
- #list_apks ⇒ Object
- #select_version(version) ⇒ Object
- #upload_apk ⇒ Object
Constructor Details
#initialize(file, track) ⇒ APK
Returns a new instance of APK.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/googlepub/apk.rb', line 9 def initialize(file, track) @track = track @file = file @edit_id = ENV['EDIT_ID'] @access_token = ENV['ACCESS_TOKEN'] @package = ENV['PACKAGE'] if !@edit_id || !@access_token || !@package p "Invalid call".red end if !File.new(@file) p "File read error, Maybe file not found at #{@file}" exit (1) end end |
Instance Method Details
#list_apks ⇒ Object
24 25 26 |
# File 'lib/googlepub/apk.rb', line 24 def list_apks apks = HTTParty.get("https://www.googleapis.com/androidpublisher/v2/applications/#{@package}/edits/#{@edit_id}/apks?access_token=#{@access_token}") end |
#select_version(version) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/googlepub/apk.rb', line 35 def select_version(version) @version = version if !@version p "Please provide a version with call!".red exit (1) end track_resp = HTTParty.get("https://www.googleapis.com/androidpublisher/v2/applications/#{@package}/edits/#{@edit_id}/tracks/#{@track}?access_token=#{@access_token}").parsed_response if (track_resp["versionCodes"][0]).to_i >= @version.to_i puts "Please bump the Version. \nAPK with Version: #{@version} already exists!".red exit 0 end track_resp["versionCodes"][0] = @version response_track = HTTParty.put("https://www.googleapis.com/androidpublisher/v2/applications/#{@package}/edits/#{@edit_id}/tracks/#{@track}?access_token=#{@access_token}", :headers => { 'Content-Type' => 'application/json' }, :body => track_resp.to_json).parsed_response if (response_track["versionCodes"][0]).to_i != @version.to_i puts "Unsuccessfull upload, Please check!".red else puts "Successfully put the #{@version} build to #{@track}".green end end |
#upload_apk ⇒ Object
28 29 30 31 32 33 |
# File 'lib/googlepub/apk.rb', line 28 def upload_apk puts "Uploading the APK".green resp = HTTMultiParty.post("https://www.googleapis.com/upload/androidpublisher/v2/applications/#{@package}/edits/#{@edit_id}/apks?access_token=#{@access_token}", :body =>{:somefile => File.new(@file)}) p "Uploaded the APK file".green end |