ChatWork

Ruby bindings of ChatWork API

Gem Version Build Status Coverage Status Dependency Status

Installation

Add this line to your application's Gemfile:

gem 'chatwork'

And then execute:

$ bundle

Or install it yourself as:

$ gem install chatwork

Usage

Case 1. with API Key

require "chatwork"

# Create message
ChatWork.api_key = "XXX"
ChatWork::Message.create(room_id: 1234, body: "Hello, ChatWork!")

or

$ cat send_message.rb
require "chatwork"

ChatWork::Message.create(room_id: 1234, body: "Hello, ChatWork!")
$ CHATWORK_API_TOKEN=xxx ruby send_message.rb

Case 2. with OAuth access token

require "chatwork"

# Create message
ChatWork.access_token = "XXX"
ChatWork::Message.create(room_id: 1234, body: "Hello, ChatWork!")

or

$ cat send_message_with_access_token.rb
require "chatwork"

ChatWork::Message.create(room_id: 1234, body: "Hello, ChatWork!")
$ CHATWORK_ACCESS_TOKEN=xxx ruby send_message_with_access_token.rb

Case 3. Refresh access token with refresh token

require "chatwork"

ChatWork.client_id = "XXX"
ChatWork.client_secret = "XXX"
refresh_token = "XXX"
token = ChatWork::Token.refresh_access_token(refresh_token)
new_access_token = token["access_token"]

# Create message
ChatWork.access_token = new_access_token
ChatWork::Message.create(room_id: 1234, body: "Hello, ChatWork!")

or

$ cat refresh_access_token.rb
require "chatwork"

token = ChatWork::Token.refresh_access_token(ENV["REFRESH_TOKEN"])
new_access_token = token["access_token"]

# Create message
ChatWork.access_token = new_access_token
ChatWork::Message.create(room_id: 1234, body: "Hello, ChatWork!")
$ CHATWORK_CLIENT_ID=xxx CHATWORK_CLIENT_SECRET=xxx REFRESH_TOKEN=xxx ruby refresh_access_token.rb

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request