Created
December 10, 2013 14:11
-
-
Save tadyjp/7891166 to your computer and use it in GitHub Desktop.
30秒でChatwork APIを使ってマイチャットに投稿する方法 ref: http://qiita.com/tady/items/ac6de448e228a2f631db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gem install faraday | |
Successfully installed faraday-0.8.8 | |
Parsing documentation for faraday-0.8.8 | |
Installing ri documentation for faraday-0.8.8 | |
1 gem installed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby main.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faraday' | |
ROOM_ID = '<ここに2で取得したマイチャットIDを入れる>' # my chat | |
CHATWORK_TOKEN = '<ここに3で取得したトークンを入れる>' | |
conn = Faraday::Connection.new(url: 'https://api.chatwork.com') do |builder| | |
builder.use Faraday::Request::UrlEncoded | |
builder.use Faraday::Response::Logger | |
builder.use Faraday::Adapter::NetHttp | |
end | |
response = conn.post do |request| | |
request.url "/v1/rooms/#{ROOM_ID}/messages" | |
request.headers = { | |
'X-ChatWorkToken' => CHATWORK_TOKEN | |
} | |
request.params[:body] = "Hello World!" # => ここに入れる文字が投稿される | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment