ActiveResource classes for Chatwork API
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
spec
.editorconfig
.gitignore
.rspec
.rubocop.yml
.travis.yml
Gemfile
LICENSE
LICENSE.txt
README.md
Rakefile
activeresource-chatwork.gemspec
circle.yml

README.md

activeresource-chatwork

CircleCI codecov Gem Version

ActiveResource classes for Chatwork API

Installation

Add this line to your application's Gemfile:

gem 'activeresource-chatwork'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activeresource-chatwork

Usage

Setup

ENV['CHATWORK_TOKEN'] = 'YOUR_CHATWORK_API_TOKEN'

Contacts

# GET /v1/contacts
contacts = Chatwork::Contact.all

My

# GET /v1/my/status
status = Chatwork::My.status

# GET /v1/my/tasks?status=open
tasks = Chatwork::My.tasks status: Chatwork::Task::STATUS_OPEN

Rooms

# GET /v1/rooms
rooms = Chatwork::Room.all

# GET /v1/rooms/xxx
room = Chatwork::Room.find xxx

# POST /v1/rooms
params = {
  name: 'xxx',
  members_admin_ids: [yyy],
  icon_preset: Chatwork::Room::ICON_GROUP
  # show all icon constants -> Chatwork::Room.constants.grep(/ICON_/)
}
room = Chatwork::Room.create params

# PUT /v1/rooms/xxx
room.name = 'xxx'
room.save

# DELETE /v1/rooms/xxx
# show all action constants -> Chatwork::Room.constants.grep(/ACTION_/)
Chatwork::Room.delete(room.id, action_type: Chatwork::Room::ACTION_DELETE)

Messages

# GET /v1/rooms/xxx/messages
params = {params: {force: 1, room_id: xxx}}
messages = Chatwork::Message.all params
# or
room = Chatwork::Room.find xxx
messages = room.messages

# GET /v1/rooms/xxx/messages/yyy
params = {params: {room_id: xxx}}
message = Chatwork::Message.find yyy, params
# or
room = Chatwork::Room.find xxx
message = room.message yyy

# POST /v1/rooms/xxx/messages
message = Chatwork::Message.new body: 'yyy'
message.prefix_options[:room_id] = xxx
message.save

Members

# GET /v1/rooms/xxx/members
params = {params: {room_id: xxx}}
members = Chatwork::Member.all params
# or
room = Chatwork::Room.find xxx
members = room.members

# PUT /v1/rooms/xxx/members
room = Chatwork::Room.find xxx
room.update_members members_admin_ids: [yyy, zzz].join(',')

Tasks

# GET /v1/rooms/xxx/tasks
tasks = Chatwork::Contact.all
# or
room = Chatwork::Room.find xxx
tasks = room.tasks

# GET /v1/rooms/xxx/tasks/yyy
params = { params: { room_id: xxx } }
tasks = Chatwork::Task.all params
# or
room = Chatwork::Room.find xxx
task = room.task(yyy)

# POST /v1/rooms/xxx/tasks
task = Chatwork::Task.new(body: 'some task', to_ids: [yyy, zzz])
task.prefix_options[:room_id] = xxx
task.save

Files

# GET /v1/rooms/xxx/files
params = { params: { room_id: xxx } }
files = Chatwork::File.all params
# or
room = Chatwork::Room.find xxx
files = room.files

# GET /v1/rooms/xxx/files/yyy
file = Chatwork::Contact.all
# or
room = Chatwork::Room.find xxx
file = room.file(yyy)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Leko/activeresource-chatwork.

License

The gem is available as open source under the terms of the MIT License.