Class: Fastlane::Actions::ApperianAction

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

Class Method Summary collapse

Class Method Details

.authenticate(api_url, email, password) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 81

def self.authenticate(api_url, email, password)
  require 'rest-client'
  require 'json'

  body = {
    "id" => 1,
    "apiVersion" => "1.0",
    "jsonrpc" => "2.0",
    "method" => "com.apperian.eas.user.authenticateuser",
    "params" => {
      "email" => email,
      "password" => password
    }
  }
  
  response = RestClient.post(api_url, body.to_json, {content_type: :json, accept: :json})
  
  if debug 
    UI.message(response.code)
    UI.message(response.body)        
  end
  
  json = JSON.parse(response.body)
  token = json["result"]["token"]
  return token
end

.authorsObject



263
264
265
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 263

def self.authors
  ["Thomas Blank"]
end

.available_optionsObject



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 276

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_url,
                            env_name: "APPERIAN_API_URL",
                         description: "The API URL to the Apperian API host",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("No Apperian API URl given, check https://help.apperian.com/display/pub/Using+the+Publishing+API for options and pass using `api_url: 'https://easesvc.apperian.com/ease.interface.php'`") unless value and !value.empty?
                                      end),

    FastlaneCore::ConfigItem.new(key: :email,
                            env_name: "APPERIAN_EMAIL",
                         description: "Your email address to authenticate yourself with the Apperian API host",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("No email for Apperian authentication given, pass using `email: '[email protected]'`") unless value and !value.empty?
                                      end),

    FastlaneCore::ConfigItem.new(key: :password,
                            env_name: "APPERIAN_PASSWORD",
                         description: "Your password to authenticate yourself with the Apperian API host",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("No password for Apperian authentication given, pass using `password: 'secret'`") unless value and !value.empty?
                                      end),

    FastlaneCore::ConfigItem.new(key: :app_identifier,
                            env_name: "APPERIAN_APP_IDENTIFIER",
                         description: "The identifier of your app",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("No app identifier given, pass using `app_identifier: 'com.example.app'`") unless value and !value.empty?
                                      end),

    FastlaneCore::ConfigItem.new(key: :ipa,
                            env_name: "APPERIAN_IPA",
                         description: "The path to your IPA file",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("Could not find IPA file, pass using `ipa: '/path/to/file.ipa'`") unless File.exist?(value)
                                      end),

    FastlaneCore::ConfigItem.new(key: :app_name,
                            env_name: "APPERIAN_APP_NAME",
                         description: "The name of your app",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("No app name given, pass using `app_name: 'My sample app'`") unless value and !value.empty?
                                        UI.user_error!("app_name: maximum characters allowed: 30") unless value.length <= 30
                                      end),

    FastlaneCore::ConfigItem.new(key: :author,
                            env_name: "APPERIAN_AUTHOR",
                         description: "Author of the app",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("No author given, pass using `author: 'Bob'`") unless value and !value.empty?
                                        UI.user_error!("author: maximum characters allowed: 150") unless value.length <= 150
                                      end),

    FastlaneCore::ConfigItem.new(key: :short_description,
                            env_name: "APPERIAN_SHORT_DESCRIPTION",
                         description: "Short description",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("No short description given, pass using `short_description: 'This is what my app does'`") unless value and !value.empty?
                                        UI.user_error!("short_description: maximum characters allowed: 100") unless value.length <= 100
                                      end),

    FastlaneCore::ConfigItem.new(key: :long_description,
                            env_name: "APPERIAN_LONG_DESCRIPTION",
                         description: "Long description",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("No long description given, pass using `long_description: 'Detailled description of my app'`") unless value and !value.empty?
                                        UI.user_error!("long_description: maximum characters allowed: 10'000'") unless value.length <= 10000  
                                      end),

    FastlaneCore::ConfigItem.new(key: :version,
                            env_name: "APPERIAN_VERSION",
                         description: "Version number",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("No version given, pass using `version: '1.0.2'`") unless value and !value.empty?
                                        UI.user_error!("version: maximum characters allowed: 21") unless value.length <= 21
                                      end),

    FastlaneCore::ConfigItem.new(key: :version_notes,
                            env_name: "APPERIAN_VERSION_NOTES",
                         description: "Version notes",
                            optional: false,
                                type: String,
                        verify_block: proc do |value|
                                        UI.user_error!("No version notes given, pass using `version_notes: 'New version available'`") unless value and !value.empty?
                                        UI.user_error!("version_notes: maximum characters allowed: 1500") unless value.length <= 1500
                                      end),

    FastlaneCore::ConfigItem.new(key: :debug,
                            env_name: "APPERIAN_DEBUG",
                         description: "Debug flag, set to true to show extended output. default: false",
                            optional: true,
                           is_string: false,
                       default_value: false)

  ]
end

.create_app(api_url, token) ⇒ Object



148
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
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 148

def self.create_app(api_url, token)
  require 'rest-client'
  require 'json'

  body = {
    "id" => 1,
    "apiVersion" => "1.0",
    "jsonrpc" => "2.0",
    "method" => "com.apperian.eas.apps.create",
    "params" => {
      "token" => token
    }
  }
  
  response = RestClient.post(api_url, body.to_json, {content_type: :json, accept: :json})

  if debug
    UI.message(response.code)
    UI.message(response.body)
  end

  json = JSON.parse(response.body)
  transactionID = json["result"]["transactionID"]
  fileUploadURL = json["result"]["fileUploadURL"]
  return transactionID, fileUploadURL
end

.debugObject

helpers



402
403
404
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 402

def self.debug
  $is_debug
end

.descriptionObject



259
260
261
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 259

def self.description
  "Allows to upload your app file to Apperian"
end

.detailsObject



271
272
273
274
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 271

def self.details
  # Optional:
  "Detailled description will follow soon"
end

.find_app(api_url, app_identifier, token) ⇒ Object



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

def self.find_app(api_url, app_identifier, token)
  # get the list of apps 
  data = list_apps(api_url, token)
  result = ""

  data['result']['applications'].each do |app|
    if app['bundleId'] == app_identifier
      result = app['ID']
      break
    end
  end

  return result
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


393
394
395
396
397
398
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 393

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md

  [:ios].include?(platform)
end

.list_apps(api_url, token) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 123

def self.list_apps(api_url, token)
  require 'rest-client'
  require 'json'

  body = {
    "id" => 1,
    "apiVersion" => "1.0",
    "jsonrpc" => "2.0",
    "method" => "com.apperian.eas.apps.getlist",
    "params" => {
      "token" => token
    }
  }
  
  response = RestClient.post(api_url, body.to_json, {content_type: :json, accept: :json})

  if debug
    UI.message(response.code)
    UI.message(response.body)
  end

  json = JSON.parse(response.body)
  return json
end

.publish_app(api_url, fileID, token, transactionID, app_name, author, short_description, long_description, version, version_notes) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 203

def self.publish_app(api_url, fileID, token, transactionID, app_name, author, short_description, long_description, version, version_notes)
  require 'rest-client'
  require 'json'

  body = {
    "id" => 1,
    "apiVersion" => "1.0",
    "jsonrpc" => "2.0",
    "method" => "com.apperian.eas.apps.publish",
    "params" => {
      "EASEmetadata" => {
        "author" => author,
        "name" => app_name,
        "shortdescription" => short_description,
        "longdescription" => long_description,
        "version" => version,
        "versionNotes" => version_notes
      },
      "files" => {
        "application" => fileID
      },
      "token" => token,
      "transactionID" => transactionID
    }
  }
  
  response = RestClient.post(api_url, body.to_json, {content_type: :json, accept: :json})

  if debug
    UI.message(response.code)
    UI.message(response.body)
  end

  json = JSON.parse(response.body)
  status = json["result"]["status"]
  appID = json["result"]["appID"]
  return status, appID
end

.return_valueObject



267
268
269
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 267

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

.run(params) ⇒ Object



6
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 6

def self.run(params)
  # check if debug is enabled
  $is_debug = params[:debug]

  if debug
    UI.message("---------------------------------")
    UI.message("Apperian plugin debug information")
    UI.message("---------------------------------")
    UI.message(" api_url: #{params[:api_url]}")
    UI.message(" email: #{params[:email]}")
    UI.message(" password: #{params[:password]}")
    UI.message(" app_identifier: #{params[:app_identifier]}")
    UI.message(" ipa: #{params[:ipa]}")
    UI.message(" app_name: #{params[:app_name]}")
    UI.message(" author: #{params[:author]}")
    UI.message(" short_description: #{params[:short_description]}")
    UI.message(" long_description: #{params[:long_description]}")
    UI.message(" version: #{params[:version]}")
    UI.message(" version_notes: #{params[:version_notes]}")
    UI.message("---------------------------------")
  end

  api_url = params[:api_url]
  email = params[:email]
  password = params[:password]
  app_identifier = params[:app_identifier]
  ipa = params[:ipa]
  app_name = params[:app_name]
  author = params[:author]
  short_description = params[:short_description]
  long_description = params[:long_description]
  version = params[:version]
  version_notes = params[:version_notes]

  # step 1: authenticate
  UI.message("1. Authenticate")
  token = authenticate(api_url, email, password)

  # step 2: find app
  UI.message("2. Find app")
  appID = find_app(api_url, app_identifier, token)
  if debug
    UI.message("Found app:")
    UI.message(appID)
  end
  
  # step 3: create or update app
  transactionID = ""
  fileUploadURL = ""

  if appID == "" then
    # step 3a: create app
    UI.message("3a. Create app")
    result = create_app(api_url, token) # return array [0] = transactionID, [1] = fileUploadURL
    transactionID = result[0]
    fileUploadURL = result[1]
  else 
    # step 3b: update app
    UI.message("3b. Update app")
    result = update_app(api_url, appID, token) # return array [0] = transactionID, [1] = fileUploadURL
    transactionID = result[0]
    fileUploadURL = result[1]
  end

  # step 4: upload file
  UI.message("4. Upload file")
  fileID = upload_file(fileUploadURL, ipa)

  # step 5: publish app
  UI.message("5. Publish app")
  result = publish_app(api_url, fileID, token, transactionID, app_name, author, short_description, long_description, version, version_notes)
  
end

.update_app(api_url, appID, token) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 175

def self.update_app(api_url, appID, token)
  require 'rest-client'
  require 'json'

  body = {
    "id" => 1,
    "apiVersion" => "1.0",
    "jsonrpc" => "2.0",
    "method" => "com.apperian.eas.apps.update",
    "params" => {
      "appID" => appID,
      "token" => token
    }
  }
  
  response = RestClient.post(api_url, body.to_json, {content_type: :json, accept: :json})

  if debug
    UI.message(response.code)
    UI.message(response.body)
  end

  json = JSON.parse(response.body)
  transactionID = json["result"]["transactionID"]
  fileUploadURL = json["result"]["fileUploadURL"]
  return transactionID, fileUploadURL
end

.upload_file(upload_url, file_path) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/fastlane/plugin/apperian/actions/apperian_action.rb', line 242

def self.upload_file(upload_url, file_path)
  require 'rest-client'
  require 'json'

  response = RestClient.post upload_url, :LUuploadFile => File.new(file_path, 'rb')

  if debug
    UI.message(response.code)
    UI.message(response.body)
  end

  json = JSON.parse(response.body)
  fileID = json["fileID"]
  return fileID

end