Class: Fastlane::Actions::ChatworkAction

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

Constant Summary

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


66
67
68
# File 'fastlane/lib/fastlane/actions/chatwork.rb', line 66

def self.author
  "astronaughts"
end

.available_optionsObject


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'fastlane/lib/fastlane/actions/chatwork.rb', line 38

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "CHATWORK_API_TOKEN",
                                 description: "ChatWork API Token",
                                 sensitive: true,
                                 verify_block: proc do |value|
                                   unless value.to_s.length > 0
                                     UI.error("Please add 'ENV[\"CHATWORK_API_TOKEN\"] = \"your token\"' to your Fastfile's `before_all` section.")
                                     UI.user_error!("No CHATWORK_API_TOKEN given.")
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :message,
                                 env_name: "FL_CHATWORK_MESSAGE",
                                 description: "The message to post on ChatWork"),
    FastlaneCore::ConfigItem.new(key: :roomid,
                                 env_name: "FL_CHATWORK_ROOMID",
                                 description: "The room ID",
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :success,
                                 env_name: "FL_CHATWORK_SUCCESS",
                                 description: "Was this build successful? (true/false)",
                                 optional: true,
                                 default_value: true,
                                 is_string: false)
  ]
end

.categoryObject


89
90
91
# File 'fastlane/lib/fastlane/actions/chatwork.rb', line 89

def self.category
  :notifications
end

.descriptionObject


34
35
36
# File 'fastlane/lib/fastlane/actions/chatwork.rb', line 34

def self.description
  "Send a success/error message to [ChatWork](https://go.chatwork.com/)"
end

.detailsObject


74
75
76
# File 'fastlane/lib/fastlane/actions/chatwork.rb', line 74

def self.details
  "Information on how to obtain an API token: [http://developer.chatwork.com/ja/authenticate.html](http://developer.chatwork.com/ja/authenticate.html)"
end

.example_codeObject


78
79
80
81
82
83
84
85
86
87
# File 'fastlane/lib/fastlane/actions/chatwork.rb', line 78

def self.example_code
  [
    'chatwork(
      message: "App successfully released!",
      roomid: 12345,
      success: true,
      api_token: "Your Token"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:


70
71
72
# File 'fastlane/lib/fastlane/actions/chatwork.rb', line 70

def self.is_supported?(platform)
  true
end

.run(options) ⇒ Object


7
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
# File 'fastlane/lib/fastlane/actions/chatwork.rb', line 7

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

  emoticon = (options[:success] ? '(dance)' : ';(')

  uri = URI.parse("https://api.chatwork.com/v2/rooms/#{options[:roomid]}/messages")
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true

  req = Net::HTTP::Post.new(uri.request_uri)
  req['X-ChatWorkToken'] = options[:api_token]
  req.set_form_data({
    'body' => "[info][title]Notification from fastlane[/title]#{emoticon} #{options[:message]}[/info]"
  })

  response = https.request(req)
  case response.code.to_i
  when 200..299
    UI.success('Successfully sent notification to ChatWork right now 📢')
  else
    require 'json'
    json = JSON.parse(response.body)
    UI.user_error!("HTTP Error: #{response.code} #{json['errors']}")
  end
end