-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
758 additions
and
177 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CHATWORK_API_TOKEN= | ||
CHATWORK_ACCESS_TOKEN= | ||
CHATWORK_CLIENT_ID= | ||
CHATWORK_CLIENT_SECRET= |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ test/version_tmp | |
tmp | ||
.ruby-gemset | ||
.ruby-version | ||
.env |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "bundler/setup" | ||
require "chatwork" | ||
require "dotenv" | ||
|
||
Dotenv.load | ||
|
||
require "pry" | ||
Pry.start |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module ChatWork | ||
module EntityMethods | ||
private | ||
|
||
def _get(path, params = {}, &block) | ||
ChatWork.client.get(path, hash_compact(params), &block) | ||
end | ||
|
||
def _post(path, params = {}, &block) | ||
ChatWork.client.post(path, hash_compact(params), &block) | ||
end | ||
|
||
def _put(path, params = {}, &block) | ||
ChatWork.client.put(path, hash_compact(params), &block) | ||
end | ||
|
||
def _delete(path, params = {}, &block) | ||
ChatWork.client.delete(path, hash_compact(params), &block) | ||
end | ||
|
||
def hash_compact(hash) | ||
hash.reject { |_k, v| v.nil? } | ||
end | ||
|
||
def boolean_to_integer(value) | ||
case value | ||
when true | ||
1 | ||
when false | ||
0 | ||
else | ||
value | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module ChatWork | ||
module File | ||
extend EntityMethods | ||
|
||
# Get the list of files associated with the specified chat | ||
# | ||
# @param room_id [Integer] | ||
# @param account_id [Integer] | ||
# | ||
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-files | ||
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf | ||
# | ||
# @return [Array<Hash>] | ||
# | ||
# @example response format | ||
# [ | ||
# { | ||
# "file_id": 3, | ||
# "account": { | ||
# "account_id": 123, | ||
# "name": "Bob", | ||
# "avatar_image_url": "https://example.com/ico_avatar.png" | ||
# }, | ||
# "message_id": "22", | ||
# "filename": "README.md", | ||
# "filesize": 2232, | ||
# "upload_time": 1384414750 | ||
# } | ||
# ] | ||
def self.get(room_id:, account_id:) | ||
_get("/rooms/#{room_id}/files", account_id: account_id) | ||
end | ||
|
||
# Get information about the specified file | ||
# | ||
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-files-file_id | ||
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf | ||
# | ||
# @param room_id [Integer] | ||
# @param file_id [Integer] | ||
# @param create_download_url [Boolean] whether or not to create a download link. | ||
# If set to true, download like will be created for 30 seconds | ||
# | ||
# @return [Array<Hash>] | ||
# | ||
# @example response format | ||
# { | ||
# "file_id":3, | ||
# "account": { | ||
# "account_id":123, | ||
# "name":"Bob", | ||
# "avatar_image_url": "https://example.com/ico_avatar.png" | ||
# }, | ||
# "message_id": "22", | ||
# "filename": "README.md", | ||
# "filesize": 2232, | ||
# "upload_time": 1384414750 | ||
# } | ||
def self.find(room_id:, file_id:, create_download_url: nil) | ||
_get("/rooms/#{room_id}/files/#{file_id}", create_download_url: boolean_to_integer(create_download_url)) | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
module ChatWork | ||
module IncomingRequest | ||
extend EntityMethods | ||
|
||
# You can get the list of contact approval request you received | ||
# | ||
# (*This method returns up to 100 entries. We are planning to implement pagination to support larger number of data retrieval) | ||
# | ||
# @see http://developer.chatwork.com/ja/endpoint_incoming_requests.html#GET-incoming_requests | ||
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf | ||
# | ||
# @return [Array<Hash>] | ||
# | ||
# @example response format | ||
# [ | ||
# { | ||
# "request_id": 123, | ||
# "account_id": 363, | ||
# "message": "hogehoge", | ||
# "name": "John Smith", | ||
# "chatwork_id": "tarochatworkid", | ||
# "organization_id": 101, | ||
# "organization_name": "Hello Company", | ||
# "department": "Marketing", | ||
# "avatar_image_url": "https://example.com/abc.png" | ||
# } | ||
# ] | ||
def self.get | ||
_get("/incoming_requests") | ||
end | ||
|
||
# You can approve a contact approval request you received | ||
# | ||
# @see http://developer.chatwork.com/ja/endpoint_incoming_requests.html#PUT-incoming_requests-request_id | ||
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf | ||
# | ||
# @param request_id [Integer] | ||
# | ||
# @return [Hash] | ||
# | ||
# @example response format | ||
# { | ||
# "account_id": 363, | ||
# "room_id": 1234, | ||
# "name": "John Smith", | ||
# "chatwork_id": "tarochatworkid", | ||
# "organization_id": 101, | ||
# "organization_name": "Hello Company", | ||
# "department": "Marketing", | ||
# "avatar_image_url": "https://example.com/abc.png" | ||
# } | ||
def self.update(request_id:) | ||
_put("/incoming_requests/#{request_id}") | ||
end | ||
|
||
# You can decline a contact approval request you received | ||
# | ||
# @see http://developer.chatwork.com/ja/endpoint_incoming_requests.html#DELETE-incoming_requests-request_id | ||
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf | ||
# | ||
# @param request_id [Integer] | ||
def self.destroy(request_id:) | ||
_delete("/incoming_requests/#{request_id}") | ||
end | ||
|
||
class << self | ||
alias_method :approve, :update | ||
alias_method :decline, :destroy | ||
end | ||
end | ||
end |
This file contains 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
Oops, something went wrong.