chatwork 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/README.md +113 -38
  4. data/lib/chatwork.rb +35 -3
  5. data/lib/chatwork/base_client.rb +9 -4
  6. data/lib/chatwork/client.rb +43 -8
  7. data/lib/chatwork/client/contacts_methods.rb +29 -0
  8. data/lib/chatwork/client/file_methods.rb +67 -0
  9. data/lib/chatwork/client/incoming_request_methods.rb +77 -0
  10. data/lib/chatwork/client/invitation_link_methods.rb +110 -0
  11. data/lib/chatwork/client/me_methods.rb +38 -0
  12. data/lib/chatwork/client/member_methods.rb +64 -0
  13. data/lib/chatwork/client/message_methods.rb +178 -0
  14. data/lib/chatwork/client/my_status_methods.rb +25 -0
  15. data/lib/chatwork/client/my_task_methods.rb +41 -0
  16. data/lib/chatwork/client/room_methods.rb +156 -0
  17. data/lib/chatwork/client/task_methods.rb +109 -0
  18. data/lib/chatwork/contacts.rb +6 -4
  19. data/lib/chatwork/converter.rb +18 -0
  20. data/lib/chatwork/file.rb +12 -6
  21. data/lib/chatwork/incoming_request.rb +18 -8
  22. data/lib/chatwork/invitation_link.rb +24 -20
  23. data/lib/chatwork/me.rb +6 -4
  24. data/lib/chatwork/member.rb +18 -12
  25. data/lib/chatwork/message.rb +42 -16
  26. data/lib/chatwork/my_status.rb +6 -4
  27. data/lib/chatwork/my_task.rb +6 -4
  28. data/lib/chatwork/oauth_client.rb +10 -2
  29. data/lib/chatwork/oauth_client/token_methods.rb +25 -0
  30. data/lib/chatwork/room.rb +37 -20
  31. data/lib/chatwork/task.rb +18 -14
  32. data/lib/chatwork/token.rb +1 -7
  33. data/lib/chatwork/version.rb +1 -1
  34. data/spec/lib/chatwork/client/contacts_methods_spec.rb +11 -0
  35. data/spec/lib/chatwork/client/file_methods_spec.rb +37 -0
  36. data/spec/lib/chatwork/client/incoming_request_methods_spec.rb +35 -0
  37. data/spec/lib/chatwork/client/invitation_link_methods_spec.rb +71 -0
  38. data/spec/lib/chatwork/client/me_methods_spec.rb +21 -0
  39. data/spec/lib/chatwork/client/member_methods_spec.rb +47 -0
  40. data/spec/lib/chatwork/client/message_methods_spec.rb +102 -0
  41. data/spec/lib/chatwork/client/my_status_methods_spec.rb +11 -0
  42. data/spec/lib/chatwork/client/my_task_methods_spec.rb +20 -0
  43. data/spec/lib/chatwork/client/room_methods_spec.rb +111 -0
  44. data/spec/lib/chatwork/client/task_methods_spec.rb +80 -0
  45. data/spec/lib/chatwork/client_spec.rb +8 -1
  46. data/spec/lib/chatwork/contacts_spec.rb +2 -2
  47. data/spec/lib/chatwork/{entity_methods_spec.rb → converter_spec.rb} +2 -2
  48. data/spec/lib/chatwork/file_spec.rb +2 -2
  49. data/spec/lib/chatwork/incoming_request_spec.rb +3 -3
  50. data/spec/lib/chatwork/invitation_link_spec.rb +4 -2
  51. data/spec/lib/chatwork/me_spec.rb +3 -21
  52. data/spec/lib/chatwork/member_spec.rb +2 -1
  53. data/spec/lib/chatwork/message_spec.rb +7 -7
  54. data/spec/lib/chatwork/my_status_spec.rb +1 -1
  55. data/spec/lib/chatwork/my_task_spec.rb +1 -0
  56. data/spec/lib/chatwork/{token_spec.rb → oauth_client/token_methods_spec.rb} +4 -7
  57. data/spec/lib/chatwork/oauth_client_spec.rb +7 -1
  58. data/spec/lib/chatwork/room_spec.rb +5 -2
  59. data/spec/lib/chatwork/task_spec.rb +3 -0
  60. data/spec/support/contexts/api_context.rb +4 -3
  61. data/spec/support/examples/a_chatwork_api.rb +22 -5
  62. data/spec/support/utils/raml_parser.rb +2 -3
  63. metadata +42 -8
  64. data/lib/chatwork/entity_methods.rb +0 -36
@@ -1,7 +1,5 @@
1
1
  module ChatWork
2
2
  module InvitationLink
3
- extend EntityMethods
4
-
5
3
  # Get invitation link
6
4
  #
7
5
  # @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-link
@@ -9,6 +7,10 @@ module ChatWork
9
7
  #
10
8
  # @param room_id [Integer]
11
9
  #
10
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
11
+ # @yieldparam response_body [Hashie::Mash] response body
12
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
13
+ #
12
14
  # @return [Hashie::Mash]
13
15
  #
14
16
  # @example response format
@@ -18,8 +20,8 @@ module ChatWork
18
20
  # "need_acceptance": true,
19
21
  # "description": "Link description text"
20
22
  # }
21
- def self.get(room_id:)
22
- _get("/rooms/#{room_id}/link")
23
+ def self.get(room_id:, &block)
24
+ ChatWork.client.get_invitation_link(room_id: room_id, &block)
23
25
  end
24
26
 
25
27
  # Create invitation link
@@ -32,6 +34,10 @@ module ChatWork
32
34
  # @param description [String] description of link page
33
35
  # @param need_acceptance [Boolean] Approval necessity. Whether participation requires administrator approval.
34
36
  #
37
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
38
+ # @yieldparam response_body [Hashie::Mash] response body
39
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
40
+ #
35
41
  # @return [Hashie::Mash]
36
42
  #
37
43
  # @example response format
@@ -41,13 +47,8 @@ module ChatWork
41
47
  # "need_acceptance": true,
42
48
  # "description": "This is a public room for topic A."
43
49
  # }
44
- def self.create(room_id:, code: nil, description: nil, need_acceptance: nil)
45
- params = {
46
- code: code,
47
- description: description,
48
- need_acceptance: boolean_to_integer(need_acceptance),
49
- }
50
- _post("/rooms/#{room_id}/link", params)
50
+ def self.create(room_id:, code: nil, description: nil, need_acceptance: nil, &block)
51
+ ChatWork.client.create_invitation_link(room_id: room_id, code: code, description: description, need_acceptance: need_acceptance, &block)
51
52
  end
52
53
 
53
54
  # Update invitation link
@@ -60,6 +61,10 @@ module ChatWork
60
61
  # @param description [String] description of link page
61
62
  # @param need_acceptance [Boolean] Approval necessity. Whether participation requires administrator approval.
62
63
  #
64
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
65
+ # @yieldparam response_body [Hashie::Mash] response body
66
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
67
+ #
63
68
  # @return [Hashie::Mash]
64
69
  #
65
70
  # @example response format
@@ -69,13 +74,8 @@ module ChatWork
69
74
  # "need_acceptance": false,
70
75
  # "description": "Public room for everybody"
71
76
  # }
72
- def self.update(room_id:, code: nil, description: nil, need_acceptance: nil)
73
- params = {
74
- code: code,
75
- description: description,
76
- need_acceptance: boolean_to_integer(need_acceptance),
77
- }
78
- _put("/rooms/#{room_id}/link", params)
77
+ def self.update(room_id:, code: nil, description: nil, need_acceptance: nil, &block)
78
+ ChatWork.client.update_invitation_link(room_id: room_id, code: code, description: description, need_acceptance: need_acceptance, &block)
79
79
  end
80
80
 
81
81
  # Delete invitation link
@@ -85,14 +85,18 @@ module ChatWork
85
85
  #
86
86
  # @param room_id [Integer]
87
87
  #
88
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
89
+ # @yieldparam response_body [Hashie::Mash] response body
90
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
91
+ #
88
92
  # @return [Hashie::Mash]
89
93
  #
90
94
  # @example response format
91
95
  # {
92
96
  # "public": false
93
97
  # }
94
- def self.destroy(room_id:)
95
- _delete("/rooms/#{room_id}/link")
98
+ def self.destroy(room_id:, &block)
99
+ ChatWork.client.destroy_invitation_link(room_id: room_id, &block)
96
100
  end
97
101
  end
98
102
  end
@@ -1,12 +1,14 @@
1
1
  module ChatWork
2
2
  module Me
3
- extend EntityMethods
4
-
5
3
  # Get your account information
6
4
  #
7
5
  # @see http://developer.chatwork.com/ja/endpoint_me.html#GET-me
8
6
  # @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
9
7
  #
8
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
9
+ # @yieldparam response_body [Hashie::Mash] response body
10
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
11
+ #
10
12
  # @return [Hashie::Mash]
11
13
  #
12
14
  # @example response format
@@ -31,8 +33,8 @@ module ChatWork
31
33
  # "avatar_image_url": "https://example.com/abc.png",
32
34
  # "login_mail": "account@example.com"
33
35
  # }
34
- def self.get
35
- _get("/me")
36
+ def self.get(&block)
37
+ ChatWork.client.get_me(&block)
36
38
  end
37
39
  end
38
40
  end
@@ -1,7 +1,5 @@
1
1
  module ChatWork
2
2
  module Member
3
- extend EntityMethods
4
-
5
3
  # Get the list of all chat members associated with the specified chat
6
4
  #
7
5
  # @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-members
@@ -9,6 +7,10 @@ module ChatWork
9
7
  #
10
8
  # @param room_id [Integer]
11
9
  #
10
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
11
+ # @yieldparam response_body [Array<Hashie::Mash>] response body
12
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
13
+ #
12
14
  # @return [Array<Hashie::Mash>]
13
15
  #
14
16
  # @example response format
@@ -24,8 +26,8 @@ module ChatWork
24
26
  # "avatar_image_url": "https://example.com/abc.png"
25
27
  # }
26
28
  # ]
27
- def self.get(room_id:)
28
- _get("/rooms/#{room_id}/members")
29
+ def self.get(room_id:, &block)
30
+ ChatWork.client.get_members(room_id: room_id, &block)
29
31
  end
30
32
 
31
33
  # Change associated members of group chat at once
@@ -39,6 +41,10 @@ module ChatWork
39
41
  # @param members_member_ids [Array<Integer>, String] List of user IDs who will be given member permission for the group chat.
40
42
  # @param members_readonly_ids [Array<Integer>, String] List of user IDs who will be given read-only permission for the group chat.
41
43
  #
44
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
45
+ # @yieldparam response_body [Hashie::Mash] response body
46
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
47
+ #
42
48
  # @return [Hashie::Mash]
43
49
  #
44
50
  # @example response format
@@ -47,14 +53,14 @@ module ChatWork
47
53
  # "member": [10, 103],
48
54
  # "readonly": [6, 11]
49
55
  # }
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)
56
+ def self.update_all(room_id:, members_admin_ids:, members_member_ids: nil, members_readonly_ids: nil, &block)
57
+ ChatWork.client.update_all_members(
58
+ room_id: room_id,
59
+ members_admin_ids: members_admin_ids,
60
+ members_member_ids: members_member_ids,
61
+ members_readonly_ids: members_readonly_ids,
62
+ &block
63
+ )
58
64
  end
59
65
  end
60
66
  end
@@ -1,7 +1,5 @@
1
1
  module ChatWork
2
2
  module Message
3
- extend EntityMethods
4
-
5
3
  # Get all messages associated with the specified chat (returns up to 100 entries).
6
4
  #
7
5
  # If the parameter is not set, it returns the next 100 entries from previous call.
@@ -12,6 +10,10 @@ module ChatWork
12
10
  # @param room_id [Integer]
13
11
  # @param force [Boolean, Integer] Flag which forces to get 100 newest entries regardless of previous calls.
14
12
  #
13
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
14
+ # @yieldparam response_body [Array<Hashie::Mash>] response body
15
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
16
+ #
15
17
  # @return [Array<Hashie::Mash>]
16
18
  #
17
19
  # @example response format
@@ -28,8 +30,8 @@ module ChatWork
28
30
  # "update_time": 0
29
31
  # }
30
32
  # ]
31
- def self.get(room_id:, force: nil)
32
- _get("/rooms/#{room_id}/messages", force: boolean_to_integer(force))
33
+ def self.get(room_id:, force: nil, &block)
34
+ ChatWork.client.get_messages(room_id: room_id, force: force, &block)
33
35
  end
34
36
 
35
37
  # Add new message to the chat
@@ -40,14 +42,18 @@ module ChatWork
40
42
  # @param room_id [Integer]
41
43
  # @param body [String] message body
42
44
  #
45
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
46
+ # @yieldparam response_body [Hashie::Mash] response body
47
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
48
+ #
43
49
  # @return [Hashie::Mash]
44
50
  #
45
51
  # @example response format
46
52
  # {
47
53
  # "message_id": "1234"
48
54
  # }
49
- def self.create(room_id:, body:)
50
- _post("/rooms/#{room_id}/messages", body: body)
55
+ def self.create(room_id:, body:, &block)
56
+ ChatWork.client.create_message(room_id: room_id, body: body, &block)
51
57
  end
52
58
 
53
59
  # Mark messages as read
@@ -58,6 +64,10 @@ module ChatWork
58
64
  # @param room_id [Integer]
59
65
  # @param message_id [String]
60
66
  #
67
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
68
+ # @yieldparam response_body [Hashie::Mash] response body
69
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
70
+ #
61
71
  # @return [Hashie::Mash]
62
72
  #
63
73
  # @example response format
@@ -65,8 +75,8 @@ module ChatWork
65
75
  # "unread_num": 461,
66
76
  # "mention_num": 0
67
77
  # }
68
- def self.read(room_id:, message_id: nil)
69
- _put("/rooms/#{room_id}/messages/read", message_id: message_id)
78
+ def self.read(room_id:, message_id: nil, &block)
79
+ ChatWork.client.read_message(room_id: room_id, message_id: message_id, &block)
70
80
  end
71
81
 
72
82
  # Mark messages as unread
@@ -77,6 +87,10 @@ module ChatWork
77
87
  # @param room_id [Integer]
78
88
  # @param message_id [String]
79
89
  #
90
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
91
+ # @yieldparam response_body [Hashie::Mash] response body
92
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
93
+ #
80
94
  # @return [Hashie::Mash]
81
95
  #
82
96
  # @example response format
@@ -84,8 +98,8 @@ module ChatWork
84
98
  # "unread_num": 3,
85
99
  # "mention_num": 0
86
100
  # }
87
- def self.unread(room_id:, message_id:)
88
- _put("/rooms/#{room_id}/messages/unread", message_id: message_id)
101
+ def self.unread(room_id:, message_id:, &block)
102
+ ChatWork.client.unread_message(room_id: room_id, message_id: message_id, &block)
89
103
  end
90
104
 
91
105
  # Get information about the specified message
@@ -96,6 +110,10 @@ module ChatWork
96
110
  # @param room_id [Integer]
97
111
  # @param message_id [String]
98
112
  #
113
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
114
+ # @yieldparam response_body [Hashie::Mash] response body
115
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
116
+ #
99
117
  # @return [Hashie::Mash]
100
118
  #
101
119
  # @example response format
@@ -110,8 +128,8 @@ module ChatWork
110
128
  # "send_time": 1384242850,
111
129
  # "update_time": 0
112
130
  # }
113
- def self.find(room_id:, message_id:)
114
- _get("/rooms/#{room_id}/messages/#{message_id}")
131
+ def self.find(room_id:, message_id:, &block)
132
+ ChatWork.client.find_message(room_id: room_id, message_id: message_id, &block)
115
133
  end
116
134
 
117
135
  # Update the specified message
@@ -123,14 +141,18 @@ module ChatWork
123
141
  # @param message_id [String]
124
142
  # @param body [String] message body
125
143
  #
144
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
145
+ # @yieldparam response_body [Hashie::Mash] response body
146
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
147
+ #
126
148
  # @return [Hashie::Mash]
127
149
  #
128
150
  # @example response format
129
151
  # {
130
152
  # "message_id": "1234"
131
153
  # }
132
- def self.update(room_id:, message_id:, body:)
133
- _put("/rooms/#{room_id}/messages/#{message_id}", body: body)
154
+ def self.update(room_id:, message_id:, body:, &block)
155
+ ChatWork.client.update_message(room_id: room_id, message_id: message_id, body: body, &block)
134
156
  end
135
157
 
136
158
  # Destroy the specified message
@@ -141,14 +163,18 @@ module ChatWork
141
163
  # @param room_id [Integer]
142
164
  # @param message_id [String]
143
165
  #
166
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
167
+ # @yieldparam response_body [Hashie::Mash] response body
168
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
169
+ #
144
170
  # @return [Hashie::Mash]
145
171
  #
146
172
  # @example response format
147
173
  # {
148
174
  # "message_id": "1234"
149
175
  # }
150
- def self.destroy(room_id:, message_id:)
151
- _delete("/rooms/#{room_id}/messages/#{message_id}")
176
+ def self.destroy(room_id:, message_id:, &block)
177
+ ChatWork.client.destroy_message(room_id: room_id, message_id: message_id, &block)
152
178
  end
153
179
  end
154
180
  end
@@ -1,12 +1,14 @@
1
1
  module ChatWork
2
2
  module MyStatus
3
- extend EntityMethods
4
-
5
3
  # Get the number of: unread messages, unread To messages, and unfinished tasks.
6
4
  #
7
5
  # @see http://developer.chatwork.com/ja/endpoint_my.html#GET-my-status
8
6
  # @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
9
7
  #
8
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
9
+ # @yieldparam response_body [Hashie::Mash] response body
10
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
11
+ #
10
12
  # @return [Hashie::Mash]
11
13
  #
12
14
  # @example response format
@@ -18,8 +20,8 @@ module ChatWork
18
20
  # "mention_num": 1,
19
21
  # "mytask_num": 8
20
22
  # }
21
- def self.get
22
- _get("/my/status")
23
+ def self.get(&block)
24
+ ChatWork.client.get_my_status(&block)
23
25
  end
24
26
  end
25
27
  end
@@ -1,7 +1,5 @@
1
1
  module ChatWork
2
2
  module MyTask
3
- extend EntityMethods
4
-
5
3
  # Get the list of all unfinished tasks
6
4
  #
7
5
  # (*This method returns up to 100 entries. We are planning to implement pagination to support larger number of data retrieval)
@@ -12,6 +10,10 @@ module ChatWork
12
10
  # @param assigned_by_account_id [Integer] Account ID of the person who assigned task
13
11
  # @param status [String] Task status (open, done)
14
12
  #
13
+ # @yield [response_body, response_header] if block was given, return response body and response header through block arguments
14
+ # @yieldparam response_body [Array<Hashie::Mash>] response body
15
+ # @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
16
+ #
15
17
  # @return [Array<Hashie::Mash>]
16
18
  #
17
19
  # @example response format
@@ -34,8 +36,8 @@ module ChatWork
34
36
  # "status": "open"
35
37
  # }
36
38
  # ]
37
- def self.get(assigned_by_account_id: nil, status: nil)
38
- _get("/my/tasks", assigned_by_account_id: assigned_by_account_id, status: status)
39
+ def self.get(assigned_by_account_id: nil, status: nil, &block)
40
+ ChatWork.client.get_my_tasks(assigned_by_account_id: assigned_by_account_id, status: status, &block)
39
41
  end
40
42
  end
41
43
  end
@@ -2,9 +2,17 @@ require "base64"
2
2
 
3
3
  module ChatWork
4
4
  class OAuthClient < BaseClient
5
- def initialize(client_id, client_secret, oauth_api_base)
5
+ require "chatwork/oauth_client/token_methods"
6
+
7
+ include TokenMethods
8
+
9
+ # @param client_id [String]
10
+ # @param client_secret [String]
11
+ # @param api_base [String] default is {ChatWork.oauth_api_base}
12
+ def initialize(client_id:, client_secret:, api_base: nil)
13
+ api_base ||= ChatWork.oauth_api_base
6
14
  signature = Base64.encode64("#{client_id}:#{client_secret}").delete("\n")
7
- super(oauth_api_base, "", { "Authorization" => "Basic #{signature}" })
15
+ super(api_base: api_base, header: { "Authorization" => "Basic #{signature}" })
8
16
  end
9
17
  end
10
18
  end
@@ -0,0 +1,25 @@
1
+ module ChatWork::OAuthClient::TokenMethods
2
+ # refresh access_token with refresh_token
3
+ #
4
+ # @param refresh_token [String]
5
+ # @param scope [Array<String>]
6
+ #
7
+ # @return [Hash]
8
+ # @example response
9
+ # {
10
+ # "access_token" => "new_access_token",
11
+ # "token_type" => "Bearer",
12
+ # "expires_in" => "1800",
13
+ # "refresh_token" => "refresh_token",
14
+ # "scope" => "users.all:read rooms.all:read_write contacts.all:read_write",
15
+ # }
16
+ def refresh_access_token(refresh_token, scope = [])
17
+ params = {
18
+ grant_type: "refresh_token",
19
+ refresh_token: refresh_token,
20
+ }
21
+ params[:scope] = scope.join(" ") unless scope.empty?
22
+
23
+ post("/token", params)
24
+ end
25
+ end