Class: Fastlane::Actions::PromoCodeAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



36
37
38
# File 'lib/fastlane/plugin/promo_code/actions/promo_code_action.rb', line 36

def self.authors
  ["marumemomo"]
end

.available_optionsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fastlane/plugin/promo_code/actions/promo_code_action.rb', line 49

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :app_identifier,
      env_name: "APP_IDENTIFIER",
      description: "APP ID of the application",
      optional: false,
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :quantity,
      env_name: "PROMO_CODE_QUANTITY",
      description: "Quantity of creating promo code",
      optional: false,
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :is_editing_version,
      env_name: "PROMO_CODE_IS_LIVE_VERSION",
      description: "App version is editing?",
      optional: true,
      type: String
    ),
  ]
end

.descriptionObject



32
33
34
# File 'lib/fastlane/plugin/promo_code/actions/promo_code_action.rb', line 32

def self.description
  "promo_code"
end

.detailsObject



44
45
46
47
# File 'lib/fastlane/plugin/promo_code/actions/promo_code_action.rb', line 44

def self.details
  # Optional:
  "A Fastlane plugin that create and get ITC promo code"
end

.get_app(params) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/fastlane/plugin/promo_code/actions/promo_code_action.rb', line 24

def self.get_app(params)
  Spaceship::Tunes. unless Spaceship::Tunes.client
  Spaceship::Tunes::Application.find params[:app_identifier]
rescue => ex
  UI.error("#{ex.message}\n#{ex.backtrace.join('\n')}")
  UI.user_error!("Could not find your App Identifier")
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
81
# File 'lib/fastlane/plugin/promo_code/actions/promo_code_action.rb', line 75

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].include?(platform)
  true
end

.return_valueObject



40
41
42
# File 'lib/fastlane/plugin/promo_code/actions/promo_code_action.rb', line 40

def self.return_value
  ["PROMO_CODE", "PROMO_CODE"]
end

.run(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fastlane/plugin/promo_code/actions/promo_code_action.rb', line 9

def self.run(params)
  UI.message("The promo_code plugin is working!")
  app = get_app(params)
  app_version = params[:is_editing_version] == "true" ? app.edit_version : app.live_version
  if app_version.nil?
    UI.user_error!("Could not find your App Version")
  end
  Spaceship::Tunes.client.generate_app_version_promocodes!(
    app_id: app_version.application.apple_id,
    version_id: app_version.version_id,
    quantity: params[:quantity]
  )
  Spaceship::Tunes.client.app_promocodes_history(app_id: app_version.application.apple_id)[0]['codes']
end