Class: Fastlane::Actions::AppcircleEnterpriseAppStoreAction

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

Constant Summary collapse

@@apiToken =
nil

Class Method Summary collapse

Class Method Details

.ac_login(accessToken) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 51

def self.(accessToken)
  begin
    user = AuthService.get_ac_token(pat: accessToken)
    UI.success("Login is successful.")
    @@apiToken = user.accessToken
  rescue => e
    UI.error("Login failed: #{e.message}")
    raise e
  end
end

.authorsObject



136
137
138
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 136

def self.authors
  ["Guven Karanfil"]
end

.available_optionsObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 149

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :personalAPIToken,
                            env_name: "AC_PERSONAL_API_TOKEN",
                         description: "Provide Personal API Token to authenticate Appcircle services",
                            optional: false,
                                type: String),

    FastlaneCore::ConfigItem.new(key: :appPath,
                            env_name: "AC_APP_PATH",
                         description: "Specify the path to your application file. For iOS, this can be a .ipa or .xcarchive file path. For Android, specify the .apk or .appbundle file path",
                            optional: false,
                                type: String),                            

    FastlaneCore::ConfigItem.new(key: :summary,
                            env_name: "AC_SUMMARY",
                         description: "Provide a summary for the application to be published. This summary will be displayed in the Appcircle Enterprise App Store",
                            optional: false,
                                type: String),

    FastlaneCore::ConfigItem.new(key: :releaseNotes,
                            env_name: "AC_RELEASE_NOTES",
                         description: "Provide release notes for the application to be published. These notes will be displayed in the Appcircle Enterprise App Store",
                            optional: false,
                                type: String),

    FastlaneCore::ConfigItem.new(key: :publishType,
                            env_name: "AC_PUBLISH_TYPE",
                         description: "Specify the publish type for the application. This can be 0: None, 1: Beta, 2: Live. Default is 0: None. For more information, provide the number of the publish type",
                            optional: false,
                                type: String),
  ]
end

.checkTaskStatus(taskId) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 63

def self.checkTaskStatus(taskId)
  uri = URI.parse("https://api.appcircle.io/task/v1/tasks/#{taskId}")
  timeout = 1
  
  response = self.send_request(uri, @@apiToken)
  if response.is_a?(Net::HTTPSuccess)
    stateValue = JSON.parse(response.body)["stateValue"]
    if stateValue == 1
      sleep(1)
      return checkTaskStatus(taskId)
    end
    if stateValue == 3
      return true
    else
      taskStatus = {
        0 => "Unknown",
        1 => "Begin",
        2 => "Canceled",
        3 => 'Completed',
      }
      raise UI.error("#{taskId} id upload request failed with status #{taskStatus[stateValue]}.")
    end
  else
    "Upload failed with response code #{response.code} and message '#{response.message}'"
    raise
  end
end

.descriptionObject



132
133
134
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 132

def self.description
  "Efficiently publish your apps to Appcircle Enterprise Store"
end

.detailsObject



144
145
146
147
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 144

def self.details
  # Optional:
  "Appcircle Enterprise Mobile App Store is your own mobile app store for providing access to in-house apps with a customizable mobile storefront"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


183
184
185
186
187
188
189
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 183

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

.publishToStore(entProfileId, entVersionId, summary, releaseNote, publishType) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 107

def self.publishToStore(entProfileId, entVersionId, summary, releaseNote, publishType)
  begin
    options = {
      auth_token: @@apiToken,
      ent_profile_id: entProfileId,
      ent_version_id: entVersionId,
      summary: summary,
      release_notes: releaseNote,
      publish_type: publishType
    }
    response = UploadService.publishVersion(options)
  rescue => e
    UI.error("App could not publish at Enterprise App Store. #{e&.response}")
    raise e
  end
end

.return_valueObject



140
141
142
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 140

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

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 17

def self.run(params)
  personalAPIToken = params[:personalAPIToken]
  appPath = params[:appPath]
  summary = params[:summary]
  releaseNotes = params[:releaseNotes]
  publishType = params[:publishType]

  valid_extensions = ['.apk', '.ipa']

  file_extension = File.extname(appPath).downcase
  unless valid_extensions.include?(file_extension)
    raise "Invalid file extension: #{file_extension}. For Android, use .apk. For iOS, use .ipa."
  end

  if personalAPIToken.nil?
    raise UI.error("Please provide Personal API Token to authenticate connections to Appcircle services")
  elsif appPath.nil?
    raise UI.error("Please specify the path to your application file. For iOS, this can be a .ipa or .xcarchive file path. For Android, specify the .apk or .appbundle file path")
  elsif summary.nil?
    raise UI.error("Please provide a summary for the application to be published. This summary will be displayed in the Appcircle Enterprise App Store")
  elsif releaseNotes.nil?
    raise UI.error("Please provide release notes for the application to be published. These notes will be displayed in the Appcircle Enterprise App Store")
  elsif publishType.nil?
    raise UI.error("Please specify the publish type for the application. This can be 0: None, 1: Beta, 2: Live. Default is 0: None. For more information, provide the number of the publish type")
  elsif publishType != "0" && publishType != "1" && publishType != "2"
    raise UI.error("Please provide a valid publish type. This can be 0: None, 1: Beta, 2: Live. Default is 0: None. For more information, provide the number of the publish type")
  end


  self.(personalAPIToken)
  self.uploadToProfile(appPath, summary, releaseNotes, publishType)
end

.send_request(uri, access_token) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 124

def self.send_request(uri, access_token)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = (uri.scheme == "https")
  request = Net::HTTP::Get.new(uri.request_uri)
  request["Authorization"] = "Bearer #{access_token}"
  http.request(request)
end

.uploadToProfile(appPath, summary, releaseNotes, publishType) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 92

def self.uploadToProfile(appPath, summary, releaseNotes, publishType)
  response = UploadService.upload_artifact(token: @@apiToken, app: appPath)
  result = self.checkTaskStatus(response["taskId"])

  if result
    profileId = UploadService.getProfileId(authToken: @@apiToken)
    appVersions = UploadService.getAppVersions(auth_token: @@apiToken, entProfileId: profileId)
    appVersionId = UploadService.getVersionId(versionList: appVersions)
    if publishType != "0"
      self.publishToStore(profileId, appVersionId, summary, releaseNotes, publishType)
    end
    UI.success("#{appPath} uploaded to the Appcircle Enterprise Store successfully")
  end
end