Class: Supply::Client

Inherits:
AbstractGoogleServiceClient show all
Defined in:
supply/lib/supply/client.rb

Constant Summary collapse

SERVICE =
Androidpublisher::AndroidPublisherService
SCOPE =
Androidpublisher::AUTH_ANDROIDPUBLISHER

Instance Attribute Summary collapse

Attributes inherited from AbstractGoogleServiceClient

#client

Login collapse

Handling the edit lifecycle collapse

Getting data collapse

Modifying data collapse

Screenshots collapse

Constructor Details

#initialize(path_to_key: nil, issuer: nil, service_account_json: nil, params: nil) ⇒ Client

Initializes the client and its auth_client using the specified information

Parameters:

  • service_account_json: (defaults to: nil)

    The raw service account Json data

  • path_to_key: (defaults to: nil)

    The path to your p12 file (@deprecated)

  • issuer: (defaults to: nil)

    Email address for oauth (@deprecated)



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'supply/lib/supply/client.rb', line 108

def initialize(path_to_key: nil, issuer: nil, service_account_json: nil, params: nil)
  if 
    key_io = 
  else
    # deprecated
    require 'google/api_client/auth/key_utils'
    key = Google::APIClient::KeyUtils.load_from_pkcs12(File.expand_path(path_to_key), 'notasecret')
    cred_json = {
      private_key: key.to_s,
      client_email: issuer
    }
    key_io = StringIO.new(MultiJson.dump(cred_json))
  end

  super(service_account_json: key_io, params: params)
end

Instance Attribute Details

#current_editObject

Editing something Reference to the entry we’re currently editing. Might be nil if don’t have one open



81
82
83
# File 'supply/lib/supply/client.rb', line 81

def current_edit
  @current_edit
end

#current_package_nameObject

Package name of the currently edited element



83
84
85
# File 'supply/lib/supply/client.rb', line 83

def current_package_name
  @current_package_name
end

Class Method Details

.make_from_config(params: nil) ⇒ Object

instantiate a client given the supplied configuration



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'supply/lib/supply/client.rb', line 90

def self.make_from_config(params: nil)
  if params.nil?
    params = Supply.config
  end

  # first consider deprecated params
  unless params[:json_key] || params[:json_key_data] || (params[:key] && params[:issuer])
    UI.important("To not be asked about this value, you can specify it using 'json_key'")
    params[:json_key] = UI.input("The service account json file used to authenticate with Google: ")
  end

  super(params: params)
end

Instance Method Details

#aab_version_codesObject

Get a list of all AAB version codes - returns the list of version codes



209
210
211
212
213
214
215
# File 'supply/lib/supply/client.rb', line 209

def aab_version_codes
  ensure_active_edit!

  result = call_google_api { client.list_edit_bundles(current_package_name, current_edit.id) }

  return Array(result.bundles).map(&:version_code)
end

#abort_current_editObject

Aborts the current edit deleting all pending changes



139
140
141
142
143
144
145
146
# File 'supply/lib/supply/client.rb', line 139

def abort_current_edit
  ensure_active_edit!

  call_google_api { client.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



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'supply/lib/supply/client.rb', line 218

def apk_listings(apk_version_code)
  ensure_active_edit!

  result = call_google_api do
    client.list_apk_listings(
      current_package_name,
      current_edit.id,
      apk_version_code
    )
  end

  return (result.listings || []).map do |row|
    ApkListing.new(row.recent_changes, row.language, apk_version_code)
  end
end

#apks_version_codesObject

Get a list of all APK version codes - returns the list of version codes



200
201
202
203
204
205
206
# File 'supply/lib/supply/client.rb', line 200

def apks_version_codes
  ensure_active_edit!

  result = call_google_api { client.list_apks(current_package_name, current_edit.id) }

  return Array(result.apks).map(&:version_code)
end

#begin_edit(package_name: nil) ⇒ Object

Begin modifying a certain package



130
131
132
133
134
135
136
# File 'supply/lib/supply/client.rb', line 130

def begin_edit(package_name: nil)
  UI.user_error!("You currently have an active edit") if @current_edit

  self.current_edit = call_google_api { client.insert_edit(package_name) }

  self.current_package_name = package_name
end

#clear_screenshots(image_type: nil, language: nil) ⇒ Object



402
403
404
405
406
407
408
409
410
411
412
413
# File 'supply/lib/supply/client.rb', line 402

def clear_screenshots(image_type: nil, language: nil)
  ensure_active_edit!

  call_google_api do
    client.delete_all_images(
      current_package_name,
      current_edit.id,
      language,
      image_type
    )
  end
end

#commit_current_edit!Object

Commits the current edit saving all pending changes on Google Play



156
157
158
159
160
161
162
163
# File 'supply/lib/supply/client.rb', line 156

def commit_current_edit!
  ensure_active_edit!

  call_google_api { client.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



371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'supply/lib/supply/client.rb', line 371

def fetch_images(image_type: nil, language: nil)
  ensure_active_edit!

  result = call_google_api do
    client.list_images(
      current_package_name,
      current_edit.id,
      language,
      image_type
    )
  end

  (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



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'supply/lib/supply/client.rb', line 182

def listing_for_language(language)
  ensure_active_edit!

  begin
    result = client.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

#listingsObject

Get a list of all languages - returns the list make sure to have an active edit



171
172
173
174
175
176
177
178
179
# File 'supply/lib/supply/client.rb', line 171

def listings
  ensure_active_edit!

  result = call_google_api { client.list_listings(current_package_name, current_edit.id) }

  return result.listings.map do |row|
    Listing.new(self, row.language, row)
  end
end

#track_version_codes(track) ⇒ Object

Get list of version codes for track



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'supply/lib/supply/client.rb', line 332

def track_version_codes(track)
  ensure_active_edit!

  begin
    result = client.get_track(
      current_package_name,
      current_edit.id,
      track
    )
    return result.version_codes || []
  rescue Google::Apis::ClientError => e
    return [] if e.status_code == 404 && e.to_s.include?("trackEmpty")
    raise
  end
end

#update_apk_listing_for_language(apk_listing) ⇒ Object



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'supply/lib/supply/client.rb', line 348

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
  })

  call_google_api do
    client.update_apk_listing(
      current_package_name,
      current_edit.id,
      apk_listing.apk_version_code,
      apk_listing.language,
      apk_listing_object
    )
  end
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



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'supply/lib/supply/client.rb', line 239

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
  })

  call_google_api do
    client.update_listing(
      current_package_name,
      current_edit.id,
      language,
      listing
    )
  end
end

#update_track(track, rollout, apk_version_code) ⇒ Object

Updates the track for the provided version code(s)



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'supply/lib/supply/client.rb', line 305

def update_track(track, rollout, apk_version_code)
  ensure_active_edit!

  track_version_codes = apk_version_code.kind_of?(Array) ? apk_version_code : [apk_version_code]

  # This change happend on 2018-04-24
  # rollout cannot be sent on any other track besides "rollout"
  # https://github.com/fastlane/fastlane/issues/12372
  rollout = nil unless track == "rollout"

  track_body = Androidpublisher::Track.new({
    track: track,
    user_fraction: rollout,
    version_codes: track_version_codes
  })

  call_google_api do
    client.update_track(
      current_package_name,
      current_edit.id,
      track,
      track_body
    )
  end
end

#upload_apk(path_to_apk) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'supply/lib/supply/client.rb', line 260

def upload_apk(path_to_apk)
  ensure_active_edit!

  result_upload = call_google_api do
    client.upload_apk(
      current_package_name,
      current_edit.id,
      upload_source: path_to_apk
    )
  end

  return result_upload.version_code
end

#upload_bundle(path_to_aab) ⇒ Object



289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'supply/lib/supply/client.rb', line 289

def upload_bundle(path_to_aab)
  ensure_active_edit!

  result_upload = call_google_api do
    client.upload_edit_bundle(
      current_package_name,
      self.current_edit.id,
      upload_source: path_to_aab,
      content_type: "application/octet-stream"
    )
  end

  return result_upload.version_code
end

#upload_image(image_path: nil, image_type: nil, language: nil) ⇒ Object

Parameters:

  • image_type (e.g. phoneScreenshots, sevenInchScreenshots, ...) (defaults to: nil)


387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'supply/lib/supply/client.rb', line 387

def upload_image(image_path: nil, image_type: nil, language: nil)
  ensure_active_edit!

  call_google_api do
    client.upload_image(
      current_package_name,
      current_edit.id,
      language,
      image_type,
      upload_source: image_path,
      content_type: 'image/*'
    )
  end
end

#upload_mapping(path_to_mapping, apk_version_code) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'supply/lib/supply/client.rb', line 274

def upload_mapping(path_to_mapping, apk_version_code)
  ensure_active_edit!

  call_google_api do
    client.upload_edit_deobfuscationfile(
      current_package_name,
      current_edit.id,
      apk_version_code,
      "proguard",
      upload_source: path_to_mapping,
      content_type: "application/octet-stream"
    )
  end
end

#upload_obb(obb_file_path: nil, apk_version_code: nil, expansion_file_type: nil) ⇒ Object



415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'supply/lib/supply/client.rb', line 415

def upload_obb(obb_file_path: nil, apk_version_code: nil, expansion_file_type: nil)
  ensure_active_edit!

  call_google_api do
    client.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
end

#validate_current_edit!Object

Validates the current edit - does not change data on Google Play



149
150
151
152
153
# File 'supply/lib/supply/client.rb', line 149

def validate_current_edit!
  ensure_active_edit!

  call_google_api { client.validate_edit(current_package_name, current_edit.id) }
end