Class: Fastlane::Actions::HockeyDevicesAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



68
69
70
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 68

def self.authors
  ["viktorasl"]
end

.available_optionsObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 80

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "FL_HOCKEY_API_TOKEN",
                                 sensitive: true,
                                 description: "API Token for Hockey Access",
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :public_identifier,
                                env_name: "FL_HOCKEY_PUBLIC_IDENTIFIER",
                                description: "App id of the app you are targeting",
                                optional: false),
    FastlaneCore::ConfigItem.new(key: :unprovisioned,
                                env_name: "HOCKEY_DEVICES_UNPROVISIONED",
                                description: "Only retrieve unprovisioned devices list",
                                optional: true,
                                is_string: false,
                                default_value: true)
  ]
end

.connection(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 4

def self.connection(options)
  require 'faraday'
  require 'faraday_middleware'

  base_url = "https://rink.hockeyapp.net"
  foptions = {
    url: base_url
  }
  Faraday.new(foptions) do |builder|
    builder.request :url_encoded
    builder.response :json, content_type: /\bjson$/
    builder.adapter :net_http
  end
end

.descriptionObject



64
65
66
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 64

def self.description
  "Retrieves a list of devices from Hockey which can then be used with Match"
end

.detailsObject



76
77
78
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 76

def self.details
  "Retrieves all or unprovisioned list of devices from Hockey. List then can be used either to register new devices using Match etc."
end

.example_codeObject



104
105
106
107
108
109
110
111
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 104

def self.example_code
  [
    'hockey_devices(
      api_token: "XXXXYYYYZZZZWWWW",
      public_identifier: "aaaabbbbccccdddd"
    )'
  ]
end

.get_devices(api_token, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 19

def self.get_devices(api_token, options)
  connection = self.connection(options)
  app_id = options.delete(:public_identifier)
  only_unprovisioned = options.delete(:unprovisioned) ? 1 : 0

  return connection.get do |req|
    req.url("/api/2/apps/#{app_id}/devices?unprovisioned=#{only_unprovisioned}")
    req.headers['X-HockeyAppToken'] = api_token
  end
end

.get_devices_hash(devices) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 30

def self.get_devices_hash(devices)
  devices_hash = {}
  used_names = {}
  devices.each do |d|
    agg_name = d["name"]
    if used_names[agg_name]
      num = used_names[agg_name] + 1
      used_names[agg_name] = num
      agg_name += " (#{num})"
    else
      used_names[agg_name] = 1
    end
    devices_hash[agg_name] = d["udid"]
  end
  devices_hash
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 100

def self.is_supported?(platform)
  true
end

.return_valueObject



72
73
74
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 72

def self.return_value
  "The hash of devices"
end

.run(options) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/hockey_devices/actions/hockey_devices_action.rb', line 47

def self.run(options)
  values = options.values
  api_token = values.delete(:api_token)

  values.delete_if { |k, v| v.nil? }

  response = self.get_devices(api_token, values)
  case response.status
  when 200...300
    devices_hash = get_devices_hash(response.body['devices'])
    UI.message("successfully got devices list")
    devices_hash
  else
    UI.user_error!("Error trying to get devices list:  #{response.status} - #{response.body}")
  end
end