chatwork 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.env.example +4 -0
- data/.gitignore +1 -0
- data/.gitmodules +3 -0
- data/.rubocop.yml +10 -0
- data/.travis.yml +26 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +33 -1
- data/Gemfile +13 -1
- data/README.md +15 -2
- data/Rakefile +2 -2
- data/bin/console +10 -0
- data/chatwork.gemspec +20 -9
- data/lib/chatwork.rb +32 -36
- data/lib/chatwork/base_client.rb +8 -11
- data/lib/chatwork/chatwork_error.rb +6 -16
- data/lib/chatwork/client.rb +2 -2
- data/lib/chatwork/contacts.rb +24 -8
- data/lib/chatwork/entity_methods.rb +36 -0
- data/lib/chatwork/file.rb +63 -0
- data/lib/chatwork/incoming_request.rb +71 -0
- data/lib/chatwork/me.rb +33 -8
- data/lib/chatwork/member.rb +55 -4
- data/lib/chatwork/message.rb +147 -6
- data/lib/chatwork/my_status.rb +25 -0
- data/lib/chatwork/my_task.rb +36 -8
- data/lib/chatwork/oauth_client.rb +3 -3
- data/lib/chatwork/room.rb +119 -6
- data/lib/chatwork/task.rb +96 -4
- data/lib/chatwork/token.rb +2 -2
- data/lib/chatwork/version.rb +1 -1
- data/spec/lib/chatwork/chatwork_error_spec.rb +10 -8
- data/spec/lib/chatwork/client_spec.rb +14 -14
- data/spec/lib/chatwork/contacts_spec.rb +11 -0
- data/spec/lib/chatwork/entity_methods_spec.rb +21 -0
- data/spec/lib/chatwork/file_spec.rb +37 -0
- data/spec/lib/chatwork/incoming_request_spec.rb +35 -0
- data/spec/lib/chatwork/me_spec.rb +39 -0
- data/spec/lib/chatwork/member_spec.rb +40 -9
- data/spec/lib/chatwork/message_spec.rb +102 -0
- data/spec/lib/chatwork/my_status_spec.rb +13 -0
- data/spec/lib/chatwork/my_task_spec.rb +19 -0
- data/spec/lib/chatwork/oauth_client_spec.rb +7 -7
- data/spec/lib/chatwork/room_spec.rb +102 -0
- data/spec/lib/chatwork/task_spec.rb +77 -0
- data/spec/lib/chatwork/token_spec.rb +26 -7
- data/spec/lib/chatwork_spec.rb +26 -19
- data/spec/lib/support/utils/raml_parser_spec.rb +96 -0
- data/spec/spec_helper.rb +32 -6
- data/spec/support/contexts/api_context.rb +43 -0
- data/spec/support/examples/a_chatwork_api.rb +12 -0
- data/spec/support/matchers/match_example.rb +16 -0
- data/spec/support/utils/raml_parser.rb +86 -0
- metadata +214 -10
- data/lib/chatwork/entity.rb +0 -29
- data/lib/chatwork/operations.rb +0 -48
- data/spec/shared_oauth_stubs.rb +0 -49
- data/spec/shared_stubs.rb +0 -39
@@ -0,0 +1,36 @@
|
|
1
|
+
module ChatWork
|
2
|
+
module EntityMethods
|
3
|
+
private
|
4
|
+
|
5
|
+
def _get(path, params = {}, &block)
|
6
|
+
ChatWork.client.get(path, hash_compact(params), &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def _post(path, params = {}, &block)
|
10
|
+
ChatWork.client.post(path, hash_compact(params), &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def _put(path, params = {}, &block)
|
14
|
+
ChatWork.client.put(path, hash_compact(params), &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def _delete(path, params = {}, &block)
|
18
|
+
ChatWork.client.delete(path, hash_compact(params), &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def hash_compact(hash)
|
22
|
+
hash.reject { |_k, v| v.nil? }
|
23
|
+
end
|
24
|
+
|
25
|
+
def boolean_to_integer(value)
|
26
|
+
case value
|
27
|
+
when true
|
28
|
+
1
|
29
|
+
when false
|
30
|
+
0
|
31
|
+
else
|
32
|
+
value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module ChatWork
|
2
|
+
module File
|
3
|
+
extend EntityMethods
|
4
|
+
|
5
|
+
# Get the list of files associated with the specified chat
|
6
|
+
#
|
7
|
+
# @param room_id [Integer]
|
8
|
+
# @param account_id [Integer]
|
9
|
+
#
|
10
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-files
|
11
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
12
|
+
#
|
13
|
+
# @return [Array<Hashie::Mash>]
|
14
|
+
#
|
15
|
+
# @example response format
|
16
|
+
# [
|
17
|
+
# {
|
18
|
+
# "file_id": 3,
|
19
|
+
# "account": {
|
20
|
+
# "account_id": 123,
|
21
|
+
# "name": "Bob",
|
22
|
+
# "avatar_image_url": "https://example.com/ico_avatar.png"
|
23
|
+
# },
|
24
|
+
# "message_id": "22",
|
25
|
+
# "filename": "README.md",
|
26
|
+
# "filesize": 2232,
|
27
|
+
# "upload_time": 1384414750
|
28
|
+
# }
|
29
|
+
# ]
|
30
|
+
def self.get(room_id:, account_id:)
|
31
|
+
_get("/rooms/#{room_id}/files", account_id: account_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Get information about the specified file
|
35
|
+
#
|
36
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-files-file_id
|
37
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
38
|
+
#
|
39
|
+
# @param room_id [Integer]
|
40
|
+
# @param file_id [Integer]
|
41
|
+
# @param create_download_url [Boolean] whether or not to create a download link.
|
42
|
+
# If set to true, download like will be created for 30 seconds
|
43
|
+
#
|
44
|
+
# @return [Array<Hashie::Mash>]
|
45
|
+
#
|
46
|
+
# @example response format
|
47
|
+
# {
|
48
|
+
# "file_id":3,
|
49
|
+
# "account": {
|
50
|
+
# "account_id":123,
|
51
|
+
# "name":"Bob",
|
52
|
+
# "avatar_image_url": "https://example.com/ico_avatar.png"
|
53
|
+
# },
|
54
|
+
# "message_id": "22",
|
55
|
+
# "filename": "README.md",
|
56
|
+
# "filesize": 2232,
|
57
|
+
# "upload_time": 1384414750
|
58
|
+
# }
|
59
|
+
def self.find(room_id:, file_id:, create_download_url: nil)
|
60
|
+
_get("/rooms/#{room_id}/files/#{file_id}", create_download_url: boolean_to_integer(create_download_url))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module ChatWork
|
2
|
+
module IncomingRequest
|
3
|
+
extend EntityMethods
|
4
|
+
|
5
|
+
# You can get the list of contact approval request you received
|
6
|
+
#
|
7
|
+
# (*This method returns up to 100 entries. We are planning to implement pagination to support larger number of data retrieval)
|
8
|
+
#
|
9
|
+
# @see http://developer.chatwork.com/ja/endpoint_incoming_requests.html#GET-incoming_requests
|
10
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
11
|
+
#
|
12
|
+
# @return [Array<Hashie::Mash>]
|
13
|
+
#
|
14
|
+
# @example response format
|
15
|
+
# [
|
16
|
+
# {
|
17
|
+
# "request_id": 123,
|
18
|
+
# "account_id": 363,
|
19
|
+
# "message": "hogehoge",
|
20
|
+
# "name": "John Smith",
|
21
|
+
# "chatwork_id": "tarochatworkid",
|
22
|
+
# "organization_id": 101,
|
23
|
+
# "organization_name": "Hello Company",
|
24
|
+
# "department": "Marketing",
|
25
|
+
# "avatar_image_url": "https://example.com/abc.png"
|
26
|
+
# }
|
27
|
+
# ]
|
28
|
+
def self.get
|
29
|
+
_get("/incoming_requests")
|
30
|
+
end
|
31
|
+
|
32
|
+
# You can approve a contact approval request you received
|
33
|
+
#
|
34
|
+
# @see http://developer.chatwork.com/ja/endpoint_incoming_requests.html#PUT-incoming_requests-request_id
|
35
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
36
|
+
#
|
37
|
+
# @param request_id [Integer]
|
38
|
+
#
|
39
|
+
# @return [Hashie::Mash]
|
40
|
+
#
|
41
|
+
# @example response format
|
42
|
+
# {
|
43
|
+
# "account_id": 363,
|
44
|
+
# "room_id": 1234,
|
45
|
+
# "name": "John Smith",
|
46
|
+
# "chatwork_id": "tarochatworkid",
|
47
|
+
# "organization_id": 101,
|
48
|
+
# "organization_name": "Hello Company",
|
49
|
+
# "department": "Marketing",
|
50
|
+
# "avatar_image_url": "https://example.com/abc.png"
|
51
|
+
# }
|
52
|
+
def self.update(request_id:)
|
53
|
+
_put("/incoming_requests/#{request_id}")
|
54
|
+
end
|
55
|
+
|
56
|
+
# You can decline a contact approval request you received
|
57
|
+
#
|
58
|
+
# @see http://developer.chatwork.com/ja/endpoint_incoming_requests.html#DELETE-incoming_requests-request_id
|
59
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
60
|
+
#
|
61
|
+
# @param request_id [Integer]
|
62
|
+
def self.destroy(request_id:)
|
63
|
+
_delete("/incoming_requests/#{request_id}")
|
64
|
+
end
|
65
|
+
|
66
|
+
class << self
|
67
|
+
alias_method :approve, :update
|
68
|
+
alias_method :decline, :destroy
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/chatwork/me.rb
CHANGED
@@ -1,13 +1,38 @@
|
|
1
1
|
module ChatWork
|
2
|
-
|
3
|
-
|
2
|
+
module Me
|
3
|
+
extend EntityMethods
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
# Get your account information
|
6
|
+
#
|
7
|
+
# @see http://developer.chatwork.com/ja/endpoint_me.html#GET-me
|
8
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
9
|
+
#
|
10
|
+
# @return [Hashie::Mash]
|
11
|
+
#
|
12
|
+
# @example response format
|
13
|
+
# {
|
14
|
+
# "account_id": 123,
|
15
|
+
# "room_id": 322,
|
16
|
+
# "name": "John Smith",
|
17
|
+
# "chatwork_id": "tarochatworkid",
|
18
|
+
# "organization_id": 101,
|
19
|
+
# "organization_name": "Hello Company",
|
20
|
+
# "department": "Marketing",
|
21
|
+
# "title": "CMO",
|
22
|
+
# "url": "http://mycompany.example.com",
|
23
|
+
# "introduction": "Self Introduction",
|
24
|
+
# "mail": "taro@example.com",
|
25
|
+
# "tel_organization": "XXX-XXXX-XXXX",
|
26
|
+
# "tel_extension": "YYY-YYYY-YYYY",
|
27
|
+
# "tel_mobile": "ZZZ-ZZZZ-ZZZZ",
|
28
|
+
# "skype": "myskype_id",
|
29
|
+
# "facebook": "myfacebook_id",
|
30
|
+
# "twitter": "mytwitter_id",
|
31
|
+
# "avatar_image_url": "https://example.com/abc.png",
|
32
|
+
# "login_mail": "account@example.com"
|
33
|
+
# }
|
34
|
+
def self.get
|
35
|
+
_get("/me")
|
11
36
|
end
|
12
37
|
end
|
13
38
|
end
|
data/lib/chatwork/member.rb
CHANGED
@@ -1,9 +1,60 @@
|
|
1
1
|
module ChatWork
|
2
|
-
|
3
|
-
|
2
|
+
module Member
|
3
|
+
extend EntityMethods
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
# Get the list of all chat members associated with the specified chat
|
6
|
+
#
|
7
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-members
|
8
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
9
|
+
#
|
10
|
+
# @param room_id [Integer]
|
11
|
+
#
|
12
|
+
# @return [Array<Hashie::Mash>]
|
13
|
+
#
|
14
|
+
# @example response format
|
15
|
+
# [
|
16
|
+
# {
|
17
|
+
# "account_id": 123,
|
18
|
+
# "role": "member",
|
19
|
+
# "name": "John Smith",
|
20
|
+
# "chatwork_id": "tarochatworkid",
|
21
|
+
# "organization_id": 101,
|
22
|
+
# "organization_name": "Hello Company",
|
23
|
+
# "department": "Marketing",
|
24
|
+
# "avatar_image_url": "https://example.com/abc.png"
|
25
|
+
# }
|
26
|
+
# ]
|
27
|
+
def self.get(room_id:)
|
28
|
+
_get("/rooms/#{room_id}/members")
|
29
|
+
end
|
30
|
+
|
31
|
+
# Change associated members of group chat at once
|
32
|
+
#
|
33
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#PUT-rooms-room_id-members
|
34
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
35
|
+
#
|
36
|
+
# @param room_id [Integer]
|
37
|
+
# @param members_admin_ids [Array<Integer>, String] List of user IDs who will be given administrator permission for the group chat.
|
38
|
+
# At least one user must be specified as an administrator.
|
39
|
+
# @param members_member_ids [Array<Integer>, String] List of user IDs who will be given member permission for the group chat.
|
40
|
+
# @param members_readonly_ids [Array<Integer>, String] List of user IDs who will be given read-only permission for the group chat.
|
41
|
+
#
|
42
|
+
# @return [Hashie::Mash]
|
43
|
+
#
|
44
|
+
# @example response format
|
45
|
+
# {
|
46
|
+
# "admin": [123, 542, 1001],
|
47
|
+
# "member": [10, 103],
|
48
|
+
# "readonly": [6, 11]
|
49
|
+
# }
|
50
|
+
def self.update_all(room_id:, members_admin_ids:, members_member_ids: nil, members_readonly_ids: nil)
|
51
|
+
params = {
|
52
|
+
members_admin_ids: Array(members_admin_ids).join(","),
|
53
|
+
}
|
54
|
+
params[:members_member_ids] = Array(members_member_ids).join(",") if members_member_ids
|
55
|
+
params[:members_readonly_ids] = Array(members_readonly_ids).join(",") if members_readonly_ids
|
56
|
+
|
57
|
+
_put("/rooms/#{room_id}/members", params)
|
7
58
|
end
|
8
59
|
end
|
9
60
|
end
|
data/lib/chatwork/message.rb
CHANGED
@@ -1,13 +1,154 @@
|
|
1
1
|
module ChatWork
|
2
|
-
|
3
|
-
|
2
|
+
module Message
|
3
|
+
extend EntityMethods
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
# Get all messages associated with the specified chat (returns up to 100 entries).
|
6
|
+
#
|
7
|
+
# If the parameter is not set, it returns the next 100 entries from previous call.
|
8
|
+
#
|
9
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-messages
|
10
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
11
|
+
#
|
12
|
+
# @param room_id [Integer]
|
13
|
+
# @param force [Boolean, Integer] Flag which forces to get 100 newest entries regardless of previous calls.
|
14
|
+
#
|
15
|
+
# @return [Array<Hashie::Mash>]
|
16
|
+
#
|
17
|
+
# @example response format
|
18
|
+
# [
|
19
|
+
# {
|
20
|
+
# "message_id": "5",
|
21
|
+
# "account": {
|
22
|
+
# "account_id": 123,
|
23
|
+
# "name": "Bob",
|
24
|
+
# "avatar_image_url": "https://example.com/ico_avatar.png"
|
25
|
+
# },
|
26
|
+
# "body": "Hello Chatwork!",
|
27
|
+
# "send_time": 1384242850,
|
28
|
+
# "update_time": 0
|
29
|
+
# }
|
30
|
+
# ]
|
31
|
+
def self.get(room_id:, force: nil)
|
32
|
+
_get("/rooms/#{room_id}/messages", force: boolean_to_integer(force))
|
7
33
|
end
|
8
34
|
|
9
|
-
|
10
|
-
|
35
|
+
# Add new message to the chat
|
36
|
+
#
|
37
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#POST-rooms-room_id-messages
|
38
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
39
|
+
#
|
40
|
+
# @param room_id [Integer]
|
41
|
+
# @param body [String] message body
|
42
|
+
#
|
43
|
+
# @return [Hashie::Mash]
|
44
|
+
#
|
45
|
+
# @example response format
|
46
|
+
# {
|
47
|
+
# "message_id": "1234"
|
48
|
+
# }
|
49
|
+
def self.create(room_id:, body:)
|
50
|
+
_post("/rooms/#{room_id}/messages", body: body)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Mark messages as read
|
54
|
+
#
|
55
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#PUT-rooms-room_id-messages-read
|
56
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
57
|
+
#
|
58
|
+
# @param room_id [Integer]
|
59
|
+
# @param message_id [String]
|
60
|
+
#
|
61
|
+
# @return [Hashie::Mash]
|
62
|
+
#
|
63
|
+
# @example response format
|
64
|
+
# {
|
65
|
+
# "unread_num": 461,
|
66
|
+
# "mention_num": 0
|
67
|
+
# }
|
68
|
+
def self.read(room_id:, message_id: nil)
|
69
|
+
_put("/rooms/#{room_id}/messages/read", message_id: message_id)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Mark messages as unread
|
73
|
+
#
|
74
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#PUT-rooms-room_id-messages-unread
|
75
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
76
|
+
#
|
77
|
+
# @param room_id [Integer]
|
78
|
+
# @param message_id [String]
|
79
|
+
#
|
80
|
+
# @return [Hashie::Mash]
|
81
|
+
#
|
82
|
+
# @example response format
|
83
|
+
# {
|
84
|
+
# "unread_num": 3,
|
85
|
+
# "mention_num": 0
|
86
|
+
# }
|
87
|
+
def self.unread(room_id:, message_id:)
|
88
|
+
_put("/rooms/#{room_id}/messages/unread", message_id: message_id)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Get information about the specified message
|
92
|
+
#
|
93
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-messages-message_id
|
94
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
95
|
+
#
|
96
|
+
# @param room_id [Integer]
|
97
|
+
# @param message_id [String]
|
98
|
+
#
|
99
|
+
# @return [Hashie::Mash]
|
100
|
+
#
|
101
|
+
# @example response format
|
102
|
+
# {
|
103
|
+
# "message_id": "5",
|
104
|
+
# "account": {
|
105
|
+
# "account_id": 123,
|
106
|
+
# "name": "Bob",
|
107
|
+
# "avatar_image_url": "https://example.com/ico_avatar.png"
|
108
|
+
# },
|
109
|
+
# "body": "Hello Chatwork!",
|
110
|
+
# "send_time": 1384242850,
|
111
|
+
# "update_time": 0
|
112
|
+
# }
|
113
|
+
def self.find(room_id:, message_id:)
|
114
|
+
_get("/rooms/#{room_id}/messages/#{message_id}")
|
115
|
+
end
|
116
|
+
|
117
|
+
# Update the specified message
|
118
|
+
#
|
119
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#PUT-rooms-room_id-messages-message_id
|
120
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
121
|
+
#
|
122
|
+
# @param room_id [Integer]
|
123
|
+
# @param message_id [String]
|
124
|
+
# @param body [String] message body
|
125
|
+
#
|
126
|
+
# @return [Hashie::Mash]
|
127
|
+
#
|
128
|
+
# @example response format
|
129
|
+
# {
|
130
|
+
# "message_id": "1234"
|
131
|
+
# }
|
132
|
+
def self.update(room_id:, message_id:, body:)
|
133
|
+
_put("/rooms/#{room_id}/messages/#{message_id}", body: body)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Destroy the specified message
|
137
|
+
#
|
138
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#PUT-rooms-room_id-messages-message_id
|
139
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
140
|
+
#
|
141
|
+
# @param room_id [Integer]
|
142
|
+
# @param message_id [String]
|
143
|
+
#
|
144
|
+
# @return [Hashie::Mash]
|
145
|
+
#
|
146
|
+
# @example response format
|
147
|
+
# {
|
148
|
+
# "message_id": "1234"
|
149
|
+
# }
|
150
|
+
def self.destroy(room_id:, message_id:)
|
151
|
+
_delete("/rooms/#{room_id}/messages/#{message_id}")
|
11
152
|
end
|
12
153
|
end
|
13
154
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ChatWork
|
2
|
+
module MyStatus
|
3
|
+
extend EntityMethods
|
4
|
+
|
5
|
+
# Get the number of: unread messages, unread To messages, and unfinished tasks.
|
6
|
+
#
|
7
|
+
# @see http://developer.chatwork.com/ja/endpoint_my.html#GET-my-status
|
8
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
9
|
+
#
|
10
|
+
# @return [Hashie::Mash]
|
11
|
+
#
|
12
|
+
# @example response format
|
13
|
+
# {
|
14
|
+
# "unread_room_num": 2,
|
15
|
+
# "mention_room_num": 1,
|
16
|
+
# "mytask_room_num": 3,
|
17
|
+
# "unread_num": 12,
|
18
|
+
# "mention_num": 1,
|
19
|
+
# "mytask_num": 8
|
20
|
+
# }
|
21
|
+
def self.get
|
22
|
+
_get("/my/status")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|