Class: Fastlane::Actions::GetAppStoreVersionNumberAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



84
85
86
# File 'lib/fastlane/plugin/versioning/actions/get_app_store_version_number.rb', line 84

def self.authors
  ["SiarheiFedartsou", "jdouglas-nz", "raymondjacobson"]
end

.available_optionsObject



46
47
48
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
74
75
76
77
78
79
80
81
82
# File 'lib/fastlane/plugin/versioning/actions/get_app_store_version_number.rb', line 46

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :bundle_id,
                       env_name: "FL_APPSTORE_VERSION_NUMBER_BUNDLE_ID",
                       description: "Bundle ID of the application",
                       optional: true,
                       conflicting_options: i[xcodeproj target scheme build_configuration_name],
                       is_string: true),
    FastlaneCore::ConfigItem.new(key: :xcodeproj,
                       env_name: "FL_VERSION_NUMBER_PROJECT",
                       description: "optional, you must specify the path to your main Xcode project if it is not in the project root directory",
                       optional: true,
                       conflicting_options: [:bundle_id],
                       verify_block: proc do |value|
                         UI.user_error!("Please pass the path to the project, not the workspace") if value.end_with? ".xcworkspace"
                         UI.user_error!("Could not find Xcode project at path '#{File.expand_path(value)}'") if !File.exist?(value) and !Helper.is_test?
                       end),
    FastlaneCore::ConfigItem.new(key: :target,
                       env_name: "FL_VERSION_NUMBER_TARGET",
                       optional: true,
                       conflicting_options: i[bundle_id scheme],
                       description: "Specify a specific target if you have multiple per project, optional"),
    FastlaneCore::ConfigItem.new(key: :scheme,
                       env_name: "FL_VERSION_NUMBER_SCHEME",
                       optional: true,
                       conflicting_options: i[bundle_id target],
                       description: "Specify a specific scheme if you have multiple per project, optional"),
    FastlaneCore::ConfigItem.new(key: :build_configuration_name,
                       optional: true,
                       conflicting_options: [:bundle_id],
                       description: "Specify a specific build configuration if you have different Info.plist build settings for each configuration"),
    FastlaneCore::ConfigItem.new(key: :country,
                       optional: true,
                       description: "Pass an optional country code, if your app's availability is limited to specific countries",
                       is_string: true)
  ]
end

.descriptionObject



42
43
44
# File 'lib/fastlane/plugin/versioning/actions/get_app_store_version_number.rb', line 42

def self.description
  "Get the version number of your app in the App Store"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/fastlane/plugin/versioning/actions/get_app_store_version_number.rb', line 88

def self.is_supported?(platform)
  i[ios mac].include? platform
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/versioning/actions/get_app_store_version_number.rb', line 8

def self.run(params)
  if params[:bundle_id]
    bundle_id = params[:bundle_id]
  else
    if Helper.test?
      plist = "/tmp/fastlane/tests/fastlane/plist/Info.plist"
    else
      plist = GetInfoPlistPathAction.run(params)
    end
    bundle_id = GetInfoPlistValueAction.run(path: plist, key: 'CFBundleIdentifier') # TODO: add same kind of flag to support build setting variables
  end

  random = Helper.test? ? "123" : SecureRandom.uuid

  if params[:country]
    uri = URI("http://itunes.apple.com/lookup?bundleId=#{bundle_id}&country=#{params[:country]}&rand=#{random}")
  else
    uri = URI("http://itunes.apple.com/lookup?bundleId=#{bundle_id}&rand=#{random}")
  end
  Net::HTTP.get(uri)

  response = Net::HTTP.get_response(uri)
  UI.crash!("Unexpected status code from iTunes Search API") unless response.kind_of?(Net::HTTPSuccess)
  response_body = JSON.parse(response.body)

  UI.user_error!("Cannot find app with #{bundle_id} bundle ID in the App Store") if response_body["resultCount"] == 0

  response_body["results"][0]["version"]
end