Class: Fastlane::Actions::FlockAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/flock.rb

Constant Summary collapse

BASE_URL =
'https://api.flock.co/hooks/sendMessage'.freeze

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, lane_context, method_missing, other_action, output, return_value, sample_return_value, sh, step_text

Class Method Details

.authorObject



62
63
64
# File 'lib/fastlane/actions/flock.rb', line 62

def self.author
  "Manav"
end

.available_optionsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fastlane/actions/flock.rb', line 43

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :message,
                                 env_name: 'FL_FLOCK_MESSAGE',
                                 description: 'Message text'),
    FastlaneCore::ConfigItem.new(key: :token,
                                 env_name: 'FL_FLOCK_TOKEN',
                                 description: 'Token for the Flock incoming webhook'),
    FastlaneCore::ConfigItem.new(key: :base_url,
                                 env_name: 'FL_FLOCK_BASE_URL',
                                 description: 'Base URL of the Flock incoming message webhook',
                                 optional: true,
                                 default_value: BASE_URL,
                                 verify_block: proc do |value|
                                   UI.user_error! 'Invalid https URL' unless value.start_with? 'https://'
                                 end)
  ]
end

.categoryObject



75
76
77
# File 'lib/fastlane/actions/flock.rb', line 75

def self.category
  :notifications
end

.descriptionObject



32
33
34
# File 'lib/fastlane/actions/flock.rb', line 32

def self.description
  "Send a message to a Flock group"
end

.detailsObject



36
37
38
39
40
41
# File 'lib/fastlane/actions/flock.rb', line 36

def self.details
  [
    "To obtain the token, create a new [incoming message webhook](https://dev.flock.co/wiki/display/FlockAPI/Incoming+Webhooks)",
    "in your Flock admin panel."
  ].join("\n")
end

.example_codeObject



66
67
68
69
70
71
72
73
# File 'lib/fastlane/actions/flock.rb', line 66

def self.example_code
  [
    'flock(
      message: "Hello",
      token: "xxx"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/fastlane/actions/flock.rb', line 79

def self.is_supported?(platform)
  true
end

.notify_incoming_message_webhook(base_url, message, token) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fastlane/actions/flock.rb', line 14

def self.notify_incoming_message_webhook(base_url, message, token)
  uri = URI.join(base_url + '/', token)
  response = Net::HTTP.start(
    uri.host, uri.port, use_ssl: uri.scheme == 'https'
  ) do |http|
    request = Net::HTTP::Post.new uri.path
    request.content_type = 'application/json'
    request.body = JSON.generate("text" => message)
    http.request request
  end
  if response.kind_of? Net::HTTPSuccess
    UI.success 'Message sent to Flock.'
  else
    UI.error "HTTP request to '#{uri}' with message '#{message}' failed with a #{response.code} response."
    UI.user_error! 'Error sending message to Flock. Please verify the Flock webhook token.'
  end
end

.run(options) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fastlane/actions/flock.rb', line 6

def self.run(options)
  require 'net/http'
  require 'uri'
  require 'json'

  notify_incoming_message_webhook(options[:base_url], options[:message], options[:token])
end