class Capkin::Robot

Oauth2 grant_type=authorization_token|refresh_token code= client_id=<the client ID token created in the APIs Console> client_secret=<the client secret corresponding to the client ID> refresh_token=<the refresh token from the previous step> start a new edit headers = {

'access_token' => ENV['CAPKIN_CLIENT']

} auth.apply(headers)

developers.google.com/android-publisher/api-ref/edits

github.com/google/google-api-ruby-client/issues/140

Constants

SCOPE
STAGE

Attributes

apk[R]
app[R]
pkg[R]
pub[R]
source[R]
stage[R]
track[R]

Public Class Methods

new(config, stage = nil) click to toggle source
# File lib/capkin/robot.rb, line 23
def initialize(config, stage = nil)
  @app = config['app']
  @source ||= File.join(config['build'], "#{@app}.apk")
  stage = stage.join if stage.respond_to?(:join)
  @stage = stage.strip.empty? ? STAGE : stage.strip

  @pkg = namespace
  init_google
end

Public Instance Methods

apk_date() click to toggle source
# File lib/capkin/robot.rb, line 66
def apk_date
  subject.time.strftime('%Y-%m-%d')
end
app_name() click to toggle source
# File lib/capkin/robot.rb, line 54
def app_name
  subject.manifest.label
end
commit!() click to toggle source

Commit the edit

# File lib/capkin/robot.rb, line 119
def commit!
  pub.commit_edit(pkg, edit.id)
rescue Google::Apis::ClientError => e
  puts Paint["✗ Problem commiting: #{e}", :red]
  raise e
end
current_version() click to toggle source
# File lib/capkin/robot.rb, line 62
def current_version
  subject.manifest.version_code
end
edit() click to toggle source

Create new editio

# File lib/capkin/robot.rb, line 42
def edit
  @edit ||= pub.insert_edit(pkg)
end
info() click to toggle source
# File lib/capkin/robot.rb, line 85
def info
  a = pub.get_listing(pkg, edit.id, 'pt-BR')
  puts "\n#{a.title} - #{a.short_description}"
  puts '---'
  puts a.full_description
  puts
end
init_google() click to toggle source
# File lib/capkin/robot.rb, line 33
def init_google
  # Get authorization!
  @auth = Google::Auth.get_application_default(SCOPE)
  # Create a publisher object
  @pub = Google::Apis::AndroidpublisherV2::AndroidPublisherService.new
  @pub.authorization = @auth
end
list() click to toggle source

pub.list_apks -> Lists with idcode and sha1

# File lib/capkin/robot.rb, line 77
def list
  puts "➔ Listing all APK! Current #{current_version} - #{apk_date}"
  pub.list_apks(pkg, edit.id).apks.each do |a|
    color = current_version == a.version_code ? :green : :black
    puts Paint["#{a.version_code} ➔ #{a.binary.sha1}", color]
  end
end
namespace() click to toggle source
# File lib/capkin/robot.rb, line 58
def namespace
  subject.manifest.package_name
end
subject() click to toggle source
# File lib/capkin/robot.rb, line 50
def subject # the apk
  @current_apk ||= Android::Apk.new(source)
end
track!() click to toggle source

Update the alpha track to point to this APK You need to use a track object to change this

# File lib/capkin/robot.rb, line 109
def track!
  track.update!(version_codes: [apk.version_code])

  # Save the modified track object
  pub.update_track(pkg, edit.id, stage, track)

  commit!
end
upload_apk!() click to toggle source

Uploads the APK

# File lib/capkin/robot.rb, line 94
def upload_apk!
  @apk = pub.upload_apk(pkg, edit.id, upload_source: source)
  track!
  puts Paint["✓ APK uploaded! ##{apk.version_code}", :green]
rescue Google::Apis::ClientError => e
  if e.to_s =~ /apkUpgradeVersionConflict/
    puts Paint['✓ Version already exists on play store!', :yellow]
  else
    puts Paint["✗ Problem with upload: #{e}", :red]
    raise e
  end
end