Class: Fastlane::Actions::LoadlyAction

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

Constant Summary collapse

UPLOAD_URL =
"https://api.loadly.io/apiv2/app/upload"
"https://i.loadly.io"

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



136
137
138
# File 'lib/fastlane/plugin/loadly/actions/loadly_action.rb', line 136

def self.authors
    ["hmphu"]
end

.available_optionsObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fastlane/plugin/loadly/actions/loadly_action.rb', line 94

def self.available_options
    [
        FastlaneCore::ConfigItem.new(key: :api_key,
                                env_name: "LOADLY_API_KEY",
                             description: "Loadly API Key",
                                optional: false),
        FastlaneCore::ConfigItem.new(key: :file,
                                env_name: "LOADLY_FILE",
                             description: "Path to .ipa or .apk file. Default - `IPA_OUTPUT_PATH` or `GRADLE_APK_OUTPUT_PATH` based on platform",
                                optional: true,
                           default_value: self.default_file_path),
        FastlaneCore::ConfigItem.new(key: :build_password,
                                env_name: "LOADLY_BUILD_PASSWORD",
                             description: "Set the App installation password. If the password is empty, public installation is used by default",
                                optional: true),
        FastlaneCore::ConfigItem.new(key: :build_description,
                                env_name: "LOADLY_BUILD_UPDATE_DESCRIPTION",
                             description: "Additional information to your users on this build: the comment will be displayed on the installation page",
                                optional: true),
        FastlaneCore::ConfigItem.new(key: :callback_url,
                                env_name: "LOADLY_CALLBACK_URL",
                             description: "The URL loadly should call with the result",
                                optional: true),
        FastlaneCore::ConfigItem.new(key: :timeout,
                                env_name: "LOADLY_TIMEOUT",
                             description: "Timeout for uploading file to Loadly. Default: 600, range: (60, 1800)",
                               is_string: false,
                                optional: true,
                           default_value: 600),
    ]
end

.callback(url, data) ⇒ Object



77
78
79
80
81
# File 'lib/fastlane/plugin/loadly/actions/loadly_action.rb', line 77

def self.callback(url, data)
    UI.success("Performing callback to #{url}")
    RestClient.post(url, data)
    UI.success("Callback sucessfully")
end

.default_file_pathObject



83
84
85
86
87
88
# File 'lib/fastlane/plugin/loadly/actions/loadly_action.rb', line 83

def self.default_file_path
    platform = Actions.lane_context[SharedValues::PLATFORM_NAME]
    ios_path = Actions.lane_context[SharedValues::IPA_OUTPUT_PATH]
    android_path = Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]
    return platform == :ios ? ios_path : android_path 
end

.descriptionObject



132
133
134
# File 'lib/fastlane/plugin/loadly/actions/loadly_action.rb', line 132

def self.description
    "Upload .ipa/.apk file to loadly.io"
end

.detailsObject



140
141
142
# File 'lib/fastlane/plugin/loadly/actions/loadly_action.rb', line 140

def self.details
    "This action upload .ipa/.apk file to https://loadly.io and return link to uploaded file."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/fastlane/plugin/loadly/actions/loadly_action.rb', line 144

def self.is_supported?(platform)
    [:ios, :android].include?(platform)
end

.outputObject



126
127
128
129
130
# File 'lib/fastlane/plugin/loadly/actions/loadly_action.rb', line 126

def self.output
    [
        ['UPLOADED_FILE_LINK_TO_LOADLY', 'URL to uploaded .ipa or .apk file to loadly.']
    ]
end

.run(options) ⇒ Object



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
# File 'lib/fastlane/plugin/loadly/actions/loadly_action.rb', line 15

def self.run(options)
    Actions.verify_gem!('rest-client')
    require 'rest-client'
    require 'json'

    if options[:file].nil?
        UI.important("File didn't come to LOADLY_plugin. Uploading is unavailable.")
        return
    end

    if options[:api_key].nil?
        UI.important("Diawi api_key is nil - uploading is unavailable.")
        UI.important("Try to upload file by yourself. Path: #{options[:file]}")
        return
    end

    upload_options = {
        _api_key: options[:api_key],
        buildPassword: options[:build_password],
        buildUpdateDescription: options[:build_description],
        file: File.new(options[:file], 'rb'),
    }

    timeout = options[:timeout]

    UI.success("Start uploading file to loadly. Please, be patient. This could take some time.")

    response = RestClient::Request.execute(
        method: :post,
        url: UPLOAD_URL,
        timeout: timeout,
        payload: upload_options
    )

    begin
        response
    rescue RestClient::ExceptionWithResponse => error
        UI.important("Failed to upload file to loadly, because of:")
        UI.important(error)
        UI.important("Try to upload file by yourself. Path: #{options[:file]}")
        return
    end

    data = JSON.parse(response.body)['data']
    
    if data
        download_url = "#{LOADLY_FILE_LINK}/#{data['buildKey']}"
        
        Actions.lane_context[SharedValues::UPLOADED_FILE_LINK_TO_LOADLY] = download_url
        
        UI.success("Upload completed successfully.")
        UI.important("Download URL: #{download_url}")

        if !options[:callback_url].nil?
            data['download_url'] = download_url
            self.callback(options[:callback_url], data)
        end
        
        return
    end
end