Class: Supply::Client
- Inherits:
-
Object
- Object
- Supply::Client
- Defined in:
- lib/supply/client.rb
Instance Attribute Summary collapse
-
#android_publisher ⇒ Object
Connecting with Google.
-
#current_edit ⇒ Object
Editing something Reference to the entry we’re currently editing.
-
#current_package_name ⇒ Object
Package name of the currently edited element.
Login collapse
-
.make_from_config ⇒ Object
instanciate a client given the supplied configuration.
-
#initialize(path_to_key: nil, issuer: nil, path_to_service_account_json: nil) ⇒ Client
constructor
Initializes the android_publisher and its auth_client using the specified information.
Handling the edit lifecycle collapse
-
#abort_current_edit ⇒ Object
Aborts the current edit deleting all pending changes.
-
#begin_edit(package_name: nil) ⇒ Object
Begin modifying a certain package.
-
#commit_current_edit! ⇒ Object
Commits the current edit saving all pending changes on Google Play.
Getting data collapse
-
#apk_listings(apk_version_code) ⇒ Object
Get a list of all apk listings (changelogs) - returns the list.
-
#apks_version_codes ⇒ Object
Get a list of all apks verion codes - returns the list of version codes.
-
#listing_for_language(language) ⇒ Object
Returns the listing for the given language filled with the current values if it already exists.
-
#listings ⇒ Object
Get a list of all languages - returns the list make sure to have an active edit.
Modifying data collapse
- #update_apk_listing_for_language(apk_listing) ⇒ Object
-
#update_listing_for_language(language: nil, title: nil, short_description: nil, full_description: nil, video: nil) ⇒ Object
Updates or creates the listing for the specified language.
- #update_track(track, rollout, apk_version_code) ⇒ Object
- #upload_apk(path_to_apk) ⇒ Object
Screenshots collapse
- #clear_screenshots(image_type: nil, language: nil) ⇒ Object
- #fetch_images(image_type: nil, language: nil) ⇒ Object
- #upload_image(image_path: nil, image_type: nil, language: nil) ⇒ Object
- #upload_obb(obb_file_path: nil, apk_version_code: nil, expansion_file_type: nil) ⇒ Object
Constructor Details
#initialize(path_to_key: nil, issuer: nil, path_to_service_account_json: nil) ⇒ Client
Initializes the android_publisher and its auth_client using the specified information
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 |
# File 'lib/supply/client.rb', line 38 def initialize(path_to_key: nil, issuer: nil, path_to_service_account_json: nil) scope = Androidpublisher::AUTH_ANDROIDPUBLISHER if path_to_service_account_json key_io = File.open(File.(path_to_service_account_json)) else require 'google/api_client/auth/key_utils' key = Google::APIClient::KeyUtils.load_from_pkcs12(File.(path_to_key), 'notasecret') cred_json = { private_key: key.to_s, client_email: issuer } key_io = StringIO.new(MultiJson.dump(cred_json)) end auth_client = Google::Auth::ServiceAccountCredentials.make_creds(json_key_io: key_io, scope: scope) Helper.log.debug "Fetching a new access token from Google..." auth_client.fetch_access_token! Google::Apis::ClientOptions.default.application_name = "fastlane - supply" Google::Apis::ClientOptions.default.application_version = Supply::VERSION self.android_publisher = Androidpublisher::AndroidPublisherService.new self.android_publisher. = auth_client end |
Instance Attribute Details
#android_publisher ⇒ Object
Connecting with Google
11 12 13 |
# File 'lib/supply/client.rb', line 11 def android_publisher @android_publisher end |
#current_edit ⇒ Object
Editing something Reference to the entry we’re currently editing. Might be nil if don’t have one open
15 16 17 |
# File 'lib/supply/client.rb', line 15 def current_edit @current_edit end |
#current_package_name ⇒ Object
Package name of the currently edited element
17 18 19 |
# File 'lib/supply/client.rb', line 17 def current_package_name @current_package_name end |
Class Method Details
.make_from_config ⇒ Object
instanciate a client given the supplied configuration
24 25 26 27 28 29 30 31 32 |
# File 'lib/supply/client.rb', line 24 def self.make_from_config unless Supply.config[:json_key] || (Supply.config[:key] && Supply.config[:issuer]) UI.user_error! "Missing auth credentials: You must specify either 'json_key' or 'key' and 'issuer'" end return Client.new(path_to_key: Supply.config[:key], issuer: Supply.config[:issuer], path_to_service_account_json: Supply.config[:json_key]) end |
Instance Method Details
#abort_current_edit ⇒ Object
Aborts the current edit deleting all pending changes
80 81 82 83 84 85 86 87 |
# File 'lib/supply/client.rb', line 80 def abort_current_edit ensure_active_edit! android_publisher.delete_edit(current_package_name, current_edit.id) self.current_edit = nil self.current_package_name = nil end |
#apk_listings(apk_version_code) ⇒ Object
Get a list of all apk listings (changelogs) - returns the list
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/supply/client.rb', line 142 def apk_listings(apk_version_code) ensure_active_edit! result = android_publisher.list_apk_listings( current_package_name, current_edit.id, apk_version_code) return (result.listings || []).map do |row| ApkListing.new(row.recent_changes, row.language, apk_version_code) end end |
#apks_version_codes ⇒ Object
Get a list of all apks verion codes - returns the list of version codes
133 134 135 136 137 138 139 |
# File 'lib/supply/client.rb', line 133 def apks_version_codes ensure_active_edit! result = android_publisher.list_apks(current_package_name, current_edit.id) return result.apks.map(&:version_code) end |
#begin_edit(package_name: nil) ⇒ Object
Begin modifying a certain package
71 72 73 74 75 76 77 |
# File 'lib/supply/client.rb', line 71 def begin_edit(package_name: nil) raise "You currently have an active edit" if @current_edit self.current_edit = android_publisher.insert_edit(package_name) self.current_package_name = package_name end |
#clear_screenshots(image_type: nil, language: nil) ⇒ Object
250 251 252 253 254 255 256 257 258 |
# File 'lib/supply/client.rb', line 250 def clear_screenshots(image_type: nil, language: nil) ensure_active_edit! android_publisher.delete_all_images( current_package_name, current_edit.id, language, image_type) end |
#commit_current_edit! ⇒ Object
Commits the current edit saving all pending changes on Google Play
90 91 92 93 94 95 96 97 |
# File 'lib/supply/client.rb', line 90 def commit_current_edit! ensure_active_edit! android_publisher.commit_edit(current_package_name, current_edit.id) self.current_edit = nil self.current_package_name = nil end |
#fetch_images(image_type: nil, language: nil) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/supply/client.rb', line 225 def fetch_images(image_type: nil, language: nil) ensure_active_edit! result = android_publisher.list_images( current_package_name, current_edit.id, language, image_type) (result.images || []).map(&:url) end |
#listing_for_language(language) ⇒ Object
Returns the listing for the given language filled with the current values if it already exists
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/supply/client.rb', line 116 def listing_for_language(language) ensure_active_edit! begin result = android_publisher.get_listing( current_package_name, current_edit.id, language) return Listing.new(self, language, result) rescue Google::Apis::ClientError => e return Listing.new(self, language) if e.status_code == 404 # create a new empty listing raise end end |
#listings ⇒ Object
Get a list of all languages - returns the list make sure to have an active edit
105 106 107 108 109 110 111 112 113 |
# File 'lib/supply/client.rb', line 105 def listings ensure_active_edit! result = android_publisher.list_listings(current_package_name, current_edit.id) return result.listings.map do |row| Listing.new(self, row.language, row) end end |
#update_apk_listing_for_language(apk_listing) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/supply/client.rb', line 205 def update_apk_listing_for_language(apk_listing) ensure_active_edit! apk_listing_object = Androidpublisher::ApkListing.new({ language: apk_listing.language, recent_changes: apk_listing.recent_changes }) android_publisher.update_apk_listing( current_package_name, current_edit.id, apk_listing.apk_version_code, apk_listing.language, apk_listing_object) end |
#update_listing_for_language(language: nil, title: nil, short_description: nil, full_description: nil, video: nil) ⇒ Object
Updates or creates the listing for the specified language
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/supply/client.rb', line 160 def update_listing_for_language(language: nil, title: nil, short_description: nil, full_description: nil, video: nil) ensure_active_edit! listing = Androidpublisher::Listing.new({ language: language, title: title, full_description: full_description, short_description: short_description, video: video }) android_publisher.update_listing( current_package_name, current_edit.id, language, listing) end |
#update_track(track, rollout, apk_version_code) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/supply/client.rb', line 189 def update_track(track, rollout, apk_version_code) ensure_active_edit! track_body = Androidpublisher::Track.new({ track: track, user_fraction: rollout, version_codes: [apk_version_code] }) android_publisher.update_track( current_package_name, current_edit.id, track, track_body) end |
#upload_apk(path_to_apk) ⇒ Object
178 179 180 181 182 183 184 185 186 187 |
# File 'lib/supply/client.rb', line 178 def upload_apk(path_to_apk) ensure_active_edit! result_upload = android_publisher.upload_apk( current_package_name, current_edit.id, upload_source: path_to_apk) return result_upload.version_code end |
#upload_image(image_path: nil, image_type: nil, language: nil) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/supply/client.rb', line 238 def upload_image(image_path: nil, image_type: nil, language: nil) ensure_active_edit! android_publisher.upload_image( current_package_name, current_edit.id, language, image_type, upload_source: image_path, content_type: 'image/*') end |
#upload_obb(obb_file_path: nil, apk_version_code: nil, expansion_file_type: nil) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/supply/client.rb', line 260 def upload_obb(obb_file_path: nil, apk_version_code: nil, expansion_file_type: nil) ensure_active_edit! android_publisher.upload_expansion_file( current_package_name, current_edit.id, apk_version_code, expansion_file_type, upload_source: obb_file_path, content_type: 'application/octet-stream' ) end |