Class: Ruboty::Adapters::Chatwork
- Inherits:
-
Base
- Object
- Base
- Ruboty::Adapters::Chatwork
- Includes:
- Mem
- Defined in:
- lib/ruboty/adapters/chatwork.rb
Instance Method Summary collapse
- #chatwork_api_rate ⇒ Object
- #chatwork_api_token ⇒ Object
- #chatwork_messages_url ⇒ Object
- #chatwork_room ⇒ Object
- #chatwork_url ⇒ Object
- #headers ⇒ Object
- #listen ⇒ Object
- #run ⇒ Object
- #say(message) ⇒ Object
Instance Method Details
#chatwork_api_rate ⇒ Object
48 49 50 |
# File 'lib/ruboty/adapters/chatwork.rb', line 48 def chatwork_api_rate ENV["CHATWORK_API_RATE"].to_i end |
#chatwork_api_token ⇒ Object
33 34 35 |
# File 'lib/ruboty/adapters/chatwork.rb', line 33 def chatwork_api_token ENV["CHATWORK_API_TOKEN"] end |
#chatwork_messages_url ⇒ Object
43 44 45 |
# File 'lib/ruboty/adapters/chatwork.rb', line 43 def URI.join(chatwork_url, "/v1/rooms/#{chatwork_room}/messages") end |
#chatwork_room ⇒ Object
38 39 40 |
# File 'lib/ruboty/adapters/chatwork.rb', line 38 def chatwork_room ENV["CHATWORK_ROOM"] end |
#chatwork_url ⇒ Object
28 29 30 |
# File 'lib/ruboty/adapters/chatwork.rb', line 28 def chatwork_url URI.parse(ENV["CHATWORK_URL"] || "https://api.chatwork.com/") end |
#headers ⇒ Object
53 54 55 56 57 |
# File 'lib/ruboty/adapters/chatwork.rb', line 53 def headers { 'X-ChatWorkToken' => chatwork_api_token, } end |
#listen ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ruboty/adapters/chatwork.rb', line 60 def listen loop do req = Net::HTTP::Get.new(.path, headers) https = Net::HTTP.new(.host, .port) https.use_ssl = true res = https.start {|https| https.request(req) } pp res.body unless res.body.nil? = JSON.parse(res.body) robot.receive( body: [0]['body'], from_name: [0]['account']['name'] ) end sleep (60 * 60) / chatwork_api_rate end end |
#run ⇒ Object
15 16 17 |
# File 'lib/ruboty/adapters/chatwork.rb', line 15 def run listen end |
#say(message) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/ruboty/adapters/chatwork.rb', line 19 def say() pp req = Net::HTTP::Post.new(.path, headers) req.form_data = { 'body' => [:body] } https = Net::HTTP.new(.host, .port) https.use_ssl = true https.start {|https| https.request(req) } end |