Class: Chatworkify::Cw

Inherits:
Object
  • Object
show all
Defined in:
lib/chatworkify/cw.rb

Overview

Chatwork service

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil) ⇒ Cw

Returns a new instance of Cw.



6
7
8
9
# File 'lib/chatworkify/cw.rb', line 6

def initialize(api_key = nil)
  @api_key = api_key || ENV['CHATWORK_API_TOKEN']
  @room_id = fetch(:chatwork_room_id) || ENV['CHATWORK_ROOM_ID']
end

Instance Method Details

#call(body = nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/chatworkify/cw.rb', line 11

def call(body = nil)
  ChatWork.api_key = @api_key
  body ||= 'No body input!'
  ChatWork::Message.create(room_id: @room_id, body: body)
rescue ChatWork::APIError => e
  puts e.message
end