Class: Fastlane::Actions::TypetalkAction

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/actions/typetalk.rb

Class Method Summary collapse

Class Method Details

.check_response(response) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/fastlane/actions/typetalk.rb', line 37

def self.check_response(response)
  case response.code.to_i
    when 200, 204
      true
    else
      raise "Could not sent Typetalk notification".red
  end
end

.post_to_typetalk(message, topicId, typetalk_token) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/fastlane/actions/typetalk.rb', line 26

def self.post_to_typetalk(message, topicId, typetalk_token)
  require 'net/http'
  require 'uri'

  uri = URI.parse("https://typetalk.in/api/v1/topics/#{topicId}")
  response = Net::HTTP.post_form(uri, {'message' => message,
                                       'typetalk_token' => typetalk_token})

  self.check_response(response)
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fastlane/actions/typetalk.rb', line 4

def self.run(params)
  options = {
      message: nil,
      success: true,
      topicId: nil,
      typetalk_token: nil,
  }.merge(params.first || {})

  [:message, :topicId, :typetalk_token].each { |key|
    raise "No #{key} given.".red unless options[key]
  }

  emoticon = (options[:success] ? ':smile:' : ':rage:')
  message = "#{emoticon} #{options[:message].to_s}"
  topicId = options[:topicId]
  typetalk_token = options[:typetalk_token]

  self.post_to_typetalk(message, topicId, typetalk_token)

  Helper.log.info 'Successfully sent Typetalk notification'.green
end