Class: Fastlane::Actions::PgyerAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



62
63
64
# File 'lib/fastlane/plugin/pgyer/actions/pgyer_action.rb', line 62

def self.authors
  ["rexshi"]
end

.available_optionsObject



75
76
77
78
79
80
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
107
108
109
110
111
112
# File 'lib/fastlane/plugin/pgyer/actions/pgyer_action.rb', line 75

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_key,
                            env_name: "PGYER_API_KEY",
                         description: "api_key in your pgyer account",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :user_key,
                            env_name: "PGYER_USER_KEY",
                         description: "user_key in your pgyer account",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :apk,
                                 env_name: "PGYER_APK",
                                 description: "Path to your APK file",
                                 default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH],
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find apk file at path '#{value}'") unless File.exist?(value)
                                 end,
                                 conflicting_options: [:ipa],
                                 conflict_block: proc do |value|
                                   UI.user_error!("You can't use 'apk' and '#{value.key}' options in one run")
                                 end),
    FastlaneCore::ConfigItem.new(key: :ipa,
                                 env_name: "PGYER_IPA",
                                 description: "Path to your IPA file. Optional if you use the _gym_ or _xcodebuild_ action. For Mac zip the .app. For Android provide path to .apk file",
                                 default_value: Actions.lane_context[SharedValues::IPA_OUTPUT_PATH],
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find ipa file at path '#{value}'") unless File.exist?(value)
                                 end,
                                 conflicting_options: [:apk],
                                 conflict_block: proc do |value|
                                   UI.user_error!("You can't use 'ipa' and '#{value.key}' options in one run")
                                 end),
  ]
end

.descriptionObject



58
59
60
# File 'lib/fastlane/plugin/pgyer/actions/pgyer_action.rb', line 58

def self.description
  "distribute app to pgyer beta testing service"
end

.detailsObject



70
71
72
73
# File 'lib/fastlane/plugin/pgyer/actions/pgyer_action.rb', line 70

def self.details
  # Optional:
  "distribute app to pgyer beta testing service"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
117
118
119
120
# File 'lib/fastlane/plugin/pgyer/actions/pgyer_action.rb', line 114

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

.return_valueObject



66
67
68
# File 'lib/fastlane/plugin/pgyer/actions/pgyer_action.rb', line 66

def self.return_value
  # If your method provides a return value, you can describe here what it does
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fastlane/plugin/pgyer/actions/pgyer_action.rb', line 8

def self.run(params)
  UI.message("The pgyer plugin is working!")

  api_host = "http://qiniu-storage.pgyer.com/apiv1/app/upload"
  api_key = params[:api_key]
  user_key = params[:user_key]

  build_file = [
      params[:ipa],
      params[:apk]
  ].detect { |e| !e.to_s.empty? }

  if build_file.nil?
      UI.user_error!("You have to provide a build file")
  end

  UI.message "build_file: #{build_file}"

  # start upload
  conn_options = {
    request: {
      timeout:       1000,
      open_timeout:  300
    }
  }

  pgyer_client = Faraday.new(nil, conn_options) do |c|
      c.request :multipart
      c.request :url_encoded
      c.response :json, content_type: /\bjson$/
      c.adapter :net_http
  end

  params = {
      '_api_key' => api_key,
      'uKey' => user_key,
      'file' => Faraday::UploadIO.new(build_file, 'application/octet-stream'),
    'installType' => 2,
      'password' => "123"
  }

  UI.message "Start upload #{build_file} to pgyer..."

  response = pgyer_client.post api_host, params
  info = response.body

  UI.success "Upload success. Visit this URL to see: https://www.pgyer.com/#{info['data']['appShortcutUrl']}"

end