Class: Fastlane::Actions::ManagedGooglePlayAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/managed_google_play/actions/managed_google_play_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



63
64
65
# File 'lib/fastlane/plugin/managed_google_play/actions/managed_google_play_action.rb', line 63

def self.authors
  ["Jan Piotrowski"]
end

.available_optionsObject



76
77
78
79
80
81
82
83
84
# File 'lib/fastlane/plugin/managed_google_play/actions/managed_google_play_action.rb', line 76

def self.available_options
  [
    # FastlaneCore::ConfigItem.new(key: :your_option,
    #                         env_name: "MANAGED_GOOGLE_PLAY_YOUR_OPTION",
    #                      description: "A description of your option",
    #                         optional: false,
    #                             type: String)
  ]
end

.descriptionObject



59
60
61
# File 'lib/fastlane/plugin/managed_google_play/actions/managed_google_play_action.rb', line 59

def self.description
  "Create Managed Google Play Apps"
end

.detailsObject



71
72
73
74
# File 'lib/fastlane/plugin/managed_google_play/actions/managed_google_play_action.rb', line 71

def self.details
  # Optional:
  "none yet"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
92
# File 'lib/fastlane/plugin/managed_google_play/actions/managed_google_play_action.rb', line 86

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.return_valueObject



67
68
69
# File 'lib/fastlane/plugin/managed_google_play/actions/managed_google_play_action.rb', line 67

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
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
52
53
54
55
56
57
# File 'lib/fastlane/plugin/managed_google_play/actions/managed_google_play_action.rb', line 7

def self.run(params)
  require "google/apis/playcustomapp_v1"

  # Auth Info
  @keyfile = ENV['KEYFILE_PATH']
  @developer_account = ENV['DEVELOPER_ACCOUNT']

  # App Info
  @apk_path = "artifacts/app-release.apk"
  @app_title = "App title!"
  @language_code = "en_US"

  # login
  scope = 'https://www.googleapis.com/auth/androidpublisher'
  credentials = JSON.parse(File.open(@keyfile, 'rb').read)
  auth_client = Signet::OAuth2::Client.new(
    token_credential_uri: 'https://oauth2.googleapis.com/token',
    audience: 'https://oauth2.googleapis.com/token',
    scope: scope,
    issuer: credentials['client_id'],
    signing_key: OpenSSL::PKey::RSA.new(credentials['private_key'], nil)
  )
  UI.message('auth_client: ' + auth_client.inspect)
  auth_client.fetch_access_token!

  # service
  play_custom_apps = Google::Apis::PlaycustomappV1::PlaycustomappService.new
  play_custom_apps.authorization = auth_client
  UI.message('play_custom_apps with auth: ' + play_custom_apps.inspect)

  # app
  custom_app = Google::Apis::PlaycustomappV1::CustomApp.new(title: @app_title, language_code: @language_code)
  UI.message('custom_app: ' + custom_app.inspect)

  # create app
  returned = play_custom_apps.(
    @developer_account,
    custom_app,
    upload_source: nil # ,
    # upload_source: @apk_path,
  ) do |created_app, error|
    if error.nil?
      puts("Success: #{created_app}.")
      UI.success(created_app)
    else
      puts("Error: #{error}")
      UI.error(error.inspect)
    end
  end
  UI.message('returned: ' + returned.inspect)
end