Class: Fastlane::Actions::FlockAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/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, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



60
61
62
# File 'fastlane/lib/fastlane/actions/flock.rb', line 60

def self.author
  "Manav"
end

.available_optionsObject



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

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',
                                 sensitive: true,
                                 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



73
74
75
# File 'fastlane/lib/fastlane/actions/flock.rb', line 73

def self.category
  :notifications
end

.descriptionObject



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

def self.description
  "Send a message to a [Flock](https://flock.com/) group"
end

.detailsObject



36
37
38
# File 'fastlane/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."
end

.example_codeObject



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

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

.is_supported?(platform) ⇒ Boolean

Returns:



77
78
79
# File 'fastlane/lib/fastlane/actions/flock.rb', line 77

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 'fastlane/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 'fastlane/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