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,6 +1,6 @@
1
1
  describe ChatWork::Member do
2
2
  describe ".get", type: :api do
3
- subject { ChatWork::Member.get(room_id: room_id) }
3
+ subject { ChatWork::Member.get(room_id: room_id, &block) }
4
4
 
5
5
  let(:room_id) { 123 }
6
6
 
@@ -18,6 +18,7 @@ describe ChatWork::Member do
18
18
  members_admin_ids: members_admin_ids,
19
19
  members_member_ids: members_member_ids,
20
20
  members_readonly_ids: members_readonly_ids,
21
+ &block
21
22
  )
22
23
  end
23
24
 
@@ -1,6 +1,6 @@
1
1
  describe ChatWork::Message do
2
2
  describe ".get", type: :api do
3
- subject { ChatWork::Message.get(room_id: room_id, force: force) }
3
+ subject { ChatWork::Message.get(room_id: room_id, force: force, &block) }
4
4
 
5
5
  let(:room_id) { 123 }
6
6
 
@@ -22,7 +22,7 @@ describe ChatWork::Message do
22
22
  end
23
23
 
24
24
  describe ".create", type: :api do
25
- subject { ChatWork::Message.create(room_id: room_id, body: body) }
25
+ subject { ChatWork::Message.create(room_id: room_id, body: body, &block) }
26
26
 
27
27
  let(:room_id) { 123 }
28
28
  let(:body) { "Hello ChatWork!" }
@@ -35,7 +35,7 @@ describe ChatWork::Message do
35
35
  end
36
36
 
37
37
  describe ".read", type: :api do
38
- subject { ChatWork::Message.read(room_id: room_id, message_id: message_id) }
38
+ subject { ChatWork::Message.read(room_id: room_id, message_id: message_id, &block) }
39
39
 
40
40
  let(:room_id) { 123 }
41
41
  let(:message_id) { "101" }
@@ -48,7 +48,7 @@ describe ChatWork::Message do
48
48
  end
49
49
 
50
50
  describe ".unread", type: :api do
51
- subject { ChatWork::Message.unread(room_id: room_id, message_id: message_id) }
51
+ subject { ChatWork::Message.unread(room_id: room_id, message_id: message_id, &block) }
52
52
 
53
53
  let(:room_id) { 123 }
54
54
  let(:message_id) { "101" }
@@ -61,7 +61,7 @@ describe ChatWork::Message do
61
61
  end
62
62
 
63
63
  describe ".find", type: :api do
64
- subject { ChatWork::Message.find(room_id: room_id, message_id: message_id) }
64
+ subject { ChatWork::Message.find(room_id: room_id, message_id: message_id, &block) }
65
65
 
66
66
  let(:room_id) { 123 }
67
67
  let(:message_id) { "101" }
@@ -74,7 +74,7 @@ describe ChatWork::Message do
74
74
  end
75
75
 
76
76
  describe ".update", type: :api do
77
- subject { ChatWork::Message.update(room_id: room_id, message_id: message_id, body: body) }
77
+ subject { ChatWork::Message.update(room_id: room_id, message_id: message_id, body: body, &block) }
78
78
 
79
79
  let(:room_id) { 123 }
80
80
  let(:message_id) { "101" }
@@ -88,7 +88,7 @@ describe ChatWork::Message do
88
88
  end
89
89
 
90
90
  describe ".destroy", type: :api do
91
- subject { ChatWork::Message.destroy(room_id: room_id, message_id: message_id) }
91
+ subject { ChatWork::Message.destroy(room_id: room_id, message_id: message_id, &block) }
92
92
 
93
93
  let(:room_id) { 123 }
94
94
  let(:message_id) { "101" }
@@ -1,7 +1,7 @@
1
1
  describe ChatWork::MyStatus do
2
2
  describe ".get", type: :api do
3
3
  subject do
4
- ChatWork::MyStatus.get
4
+ ChatWork::MyStatus.get(&block)
5
5
  end
6
6
 
7
7
  before do
@@ -4,6 +4,7 @@ describe ChatWork::MyTask do
4
4
  ChatWork::MyTask.get(
5
5
  assigned_by_account_id: assigned_by_account_id,
6
6
  status: status,
7
+ &block
7
8
  )
8
9
  end
9
10
 
@@ -1,11 +1,8 @@
1
- describe ChatWork::Token do
2
- describe ".refresh_access_token" do
3
- subject { ChatWork::Token.refresh_access_token(refresh_token, scope) }
1
+ describe ChatWork::OAuthClient::TokenMethods do
2
+ let(:oauth_client) { ChatWork::OAuthClient.new(client_id: client_id, client_secret: client_secret) }
4
3
 
5
- before do
6
- allow(ChatWork).to receive(:client_id) { client_id }
7
- allow(ChatWork).to receive(:client_secret) { client_secret }
8
- end
4
+ describe ".refresh_access_token" do
5
+ subject { oauth_client.refresh_access_token(refresh_token, scope) }
9
6
 
10
7
  let(:client_id) { "client_id" }
11
8
  let(:client_secret) { "client_secret" }
@@ -1,6 +1,12 @@
1
1
  describe ChatWork::OAuthClient do
2
2
  describe "#initialize" do
3
- subject { ChatWork::OAuthClient.new(client_id, client_secret, api_base) }
3
+ subject do
4
+ ChatWork::OAuthClient.new(
5
+ client_id: client_id,
6
+ client_secret: client_secret,
7
+ api_base: api_base,
8
+ )
9
+ end
4
10
 
5
11
  let(:client_id) { "client_id" }
6
12
  let(:client_secret) { "client_secret" }
@@ -1,6 +1,6 @@
1
1
  describe ChatWork::Room do
2
2
  describe ".get", type: :api do
3
- subject { ChatWork::Room.get }
3
+ subject { ChatWork::Room.get(&block) }
4
4
 
5
5
  let(:room_id) { 123 }
6
6
 
@@ -23,6 +23,7 @@ describe ChatWork::Room do
23
23
  link: link,
24
24
  link_code: link_code,
25
25
  link_need_acceptance: link_need_acceptance,
26
+ &block
26
27
  )
27
28
  end
28
29
 
@@ -55,7 +56,7 @@ describe ChatWork::Room do
55
56
  end
56
57
 
57
58
  describe ".find", type: :api do
58
- subject { ChatWork::Room.find(room_id: room_id) }
59
+ subject { ChatWork::Room.find(room_id: room_id, &block) }
59
60
 
60
61
  let(:room_id) { 123 }
61
62
 
@@ -73,6 +74,7 @@ describe ChatWork::Room do
73
74
  description: description,
74
75
  icon_preset: icon_preset,
75
76
  name: name,
77
+ &block
76
78
  )
77
79
  end
78
80
 
@@ -93,6 +95,7 @@ describe ChatWork::Room do
93
95
  ChatWork::Room.destroy(
94
96
  room_id: room_id,
95
97
  action_type: action_type,
98
+ &block
96
99
  )
97
100
  end
98
101
 
@@ -6,6 +6,7 @@ describe ChatWork::Task do
6
6
  account_id: account_id,
7
7
  assigned_by_account_id: assigned_by_account_id,
8
8
  status: status,
9
+ &block
9
10
  )
10
11
  end
11
12
 
@@ -28,6 +29,7 @@ describe ChatWork::Task do
28
29
  body: body,
29
30
  to_ids: to_ids,
30
31
  limit: limit,
32
+ &block
31
33
  )
32
34
  end
33
35
 
@@ -62,6 +64,7 @@ describe ChatWork::Task do
62
64
  ChatWork::Task.find(
63
65
  room_id: room_id,
64
66
  task_id: task_id,
67
+ &block
65
68
  )
66
69
  end
67
70
 
@@ -1,5 +1,6 @@
1
1
  RSpec.shared_context :api_context, type: :api do
2
2
  let(:api_key) { "api_key" }
3
+ let(:client) { ChatWork::Client.new(api_key: api_key) }
3
4
 
4
5
  let(:response_headers) do
5
6
  {
@@ -10,9 +11,9 @@ RSpec.shared_context :api_context, type: :api do
10
11
  }
11
12
  end
12
13
 
13
- let(:ratelimit_limit) { 100 }
14
- let(:ratelimit_remaining) { 44 }
15
- let(:ratelimit_reset) { 1_390_941_626 }
14
+ let(:ratelimit_limit) { "100" }
15
+ let(:ratelimit_remaining) { "44" }
16
+ let(:ratelimit_reset) { "1390941626" }
16
17
 
17
18
  before do
18
19
  allow(ChatWork).to receive(:api_key) { api_key }
@@ -1,11 +1,28 @@
1
1
  RSpec.shared_examples :a_chatwork_api do |verb, resource, status = 200|
2
- it { should match_example(verb, resource, status) }
2
+ context "without block" do
3
+ let(:block) { nil }
4
+
5
+ it { should match_example(verb, resource, status) }
6
+ end
7
+
8
+ context "with block" do
9
+ let(:block) do
10
+ ->(body, header) do
11
+ @body = body
12
+ @header = header
13
+ end
14
+ end
15
+
16
+ it "works with block" do
17
+ subject
3
18
 
4
- it "works with block" do
5
- subject do |body, headers|
6
19
  aggregate_failures do
7
- expect(body).to match_example(verb, resource, status)
8
- expect(headers).to eq response_headers
20
+ expect(@body).to match_example(verb, resource, status)
21
+
22
+ expect(@header["Content-Type"]).to eq "application/json"
23
+ expect(@header["X-RateLimit-Limit"]).to eq ratelimit_limit
24
+ expect(@header["X-RateLimit-Remaining"]).to eq ratelimit_remaining
25
+ expect(@header["X-RateLimit-Reset"]).to eq ratelimit_reset
9
26
  end
10
27
  end
11
28
  end
@@ -33,7 +33,7 @@ module RamlParser
33
33
  nil
34
34
  end
35
35
 
36
- def self.find_query_parameter_example(verb, path) # rubocop:disable Metrics/MethodLength
36
+ def self.find_query_parameter_example(verb, path)
37
37
  resource = find_resource(verb, path)
38
38
  return {} unless resource
39
39
 
@@ -49,8 +49,7 @@ module RamlParser
49
49
  if resource["is"]
50
50
  resource["is"].each do |trait_name|
51
51
  trait = find_trait(trait_name)
52
- next unless trait
53
- next unless trait["queryParameters"]
52
+ next if !trait || !trait["queryParameters"]
54
53
 
55
54
  trait["queryParameters"].each do |name, value|
56
55
  example = find_example(value)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatwork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - asonas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-04 00:00:00.000000000 Z
12
+ date: 2018-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -275,8 +275,19 @@ files:
275
275
  - lib/chatwork/base_client.rb
276
276
  - lib/chatwork/chatwork_error.rb
277
277
  - lib/chatwork/client.rb
278
+ - lib/chatwork/client/contacts_methods.rb
279
+ - lib/chatwork/client/file_methods.rb
280
+ - lib/chatwork/client/incoming_request_methods.rb
281
+ - lib/chatwork/client/invitation_link_methods.rb
282
+ - lib/chatwork/client/me_methods.rb
283
+ - lib/chatwork/client/member_methods.rb
284
+ - lib/chatwork/client/message_methods.rb
285
+ - lib/chatwork/client/my_status_methods.rb
286
+ - lib/chatwork/client/my_task_methods.rb
287
+ - lib/chatwork/client/room_methods.rb
288
+ - lib/chatwork/client/task_methods.rb
278
289
  - lib/chatwork/contacts.rb
279
- - lib/chatwork/entity_methods.rb
290
+ - lib/chatwork/converter.rb
280
291
  - lib/chatwork/file.rb
281
292
  - lib/chatwork/incoming_request.rb
282
293
  - lib/chatwork/invitation_link.rb
@@ -286,14 +297,26 @@ files:
286
297
  - lib/chatwork/my_status.rb
287
298
  - lib/chatwork/my_task.rb
288
299
  - lib/chatwork/oauth_client.rb
300
+ - lib/chatwork/oauth_client/token_methods.rb
289
301
  - lib/chatwork/room.rb
290
302
  - lib/chatwork/task.rb
291
303
  - lib/chatwork/token.rb
292
304
  - lib/chatwork/version.rb
293
305
  - spec/lib/chatwork/chatwork_error_spec.rb
306
+ - spec/lib/chatwork/client/contacts_methods_spec.rb
307
+ - spec/lib/chatwork/client/file_methods_spec.rb
308
+ - spec/lib/chatwork/client/incoming_request_methods_spec.rb
309
+ - spec/lib/chatwork/client/invitation_link_methods_spec.rb
310
+ - spec/lib/chatwork/client/me_methods_spec.rb
311
+ - spec/lib/chatwork/client/member_methods_spec.rb
312
+ - spec/lib/chatwork/client/message_methods_spec.rb
313
+ - spec/lib/chatwork/client/my_status_methods_spec.rb
314
+ - spec/lib/chatwork/client/my_task_methods_spec.rb
315
+ - spec/lib/chatwork/client/room_methods_spec.rb
316
+ - spec/lib/chatwork/client/task_methods_spec.rb
294
317
  - spec/lib/chatwork/client_spec.rb
295
318
  - spec/lib/chatwork/contacts_spec.rb
296
- - spec/lib/chatwork/entity_methods_spec.rb
319
+ - spec/lib/chatwork/converter_spec.rb
297
320
  - spec/lib/chatwork/file_spec.rb
298
321
  - spec/lib/chatwork/incoming_request_spec.rb
299
322
  - spec/lib/chatwork/invitation_link_spec.rb
@@ -302,10 +325,10 @@ files:
302
325
  - spec/lib/chatwork/message_spec.rb
303
326
  - spec/lib/chatwork/my_status_spec.rb
304
327
  - spec/lib/chatwork/my_task_spec.rb
328
+ - spec/lib/chatwork/oauth_client/token_methods_spec.rb
305
329
  - spec/lib/chatwork/oauth_client_spec.rb
306
330
  - spec/lib/chatwork/room_spec.rb
307
331
  - spec/lib/chatwork/task_spec.rb
308
- - spec/lib/chatwork/token_spec.rb
309
332
  - spec/lib/chatwork_spec.rb
310
333
  - spec/lib/support/utils/raml_parser_spec.rb
311
334
  - spec/spec_helper.rb
@@ -333,15 +356,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
333
356
  version: '0'
334
357
  requirements: []
335
358
  rubyforge_project:
336
- rubygems_version: 2.7.4
359
+ rubygems_version: 2.7.6
337
360
  signing_key:
338
361
  specification_version: 4
339
362
  summary: Ruby bindings of ChatWork API
340
363
  test_files:
341
364
  - spec/lib/chatwork/chatwork_error_spec.rb
365
+ - spec/lib/chatwork/client/contacts_methods_spec.rb
366
+ - spec/lib/chatwork/client/file_methods_spec.rb
367
+ - spec/lib/chatwork/client/incoming_request_methods_spec.rb
368
+ - spec/lib/chatwork/client/invitation_link_methods_spec.rb
369
+ - spec/lib/chatwork/client/me_methods_spec.rb
370
+ - spec/lib/chatwork/client/member_methods_spec.rb
371
+ - spec/lib/chatwork/client/message_methods_spec.rb
372
+ - spec/lib/chatwork/client/my_status_methods_spec.rb
373
+ - spec/lib/chatwork/client/my_task_methods_spec.rb
374
+ - spec/lib/chatwork/client/room_methods_spec.rb
375
+ - spec/lib/chatwork/client/task_methods_spec.rb
342
376
  - spec/lib/chatwork/client_spec.rb
343
377
  - spec/lib/chatwork/contacts_spec.rb
344
- - spec/lib/chatwork/entity_methods_spec.rb
378
+ - spec/lib/chatwork/converter_spec.rb
345
379
  - spec/lib/chatwork/file_spec.rb
346
380
  - spec/lib/chatwork/incoming_request_spec.rb
347
381
  - spec/lib/chatwork/invitation_link_spec.rb
@@ -350,10 +384,10 @@ test_files:
350
384
  - spec/lib/chatwork/message_spec.rb
351
385
  - spec/lib/chatwork/my_status_spec.rb
352
386
  - spec/lib/chatwork/my_task_spec.rb
387
+ - spec/lib/chatwork/oauth_client/token_methods_spec.rb
353
388
  - spec/lib/chatwork/oauth_client_spec.rb
354
389
  - spec/lib/chatwork/room_spec.rb
355
390
  - spec/lib/chatwork/task_spec.rb
356
- - spec/lib/chatwork/token_spec.rb
357
391
  - spec/lib/chatwork_spec.rb
358
392
  - spec/lib/support/utils/raml_parser_spec.rb
359
393
  - spec/spec_helper.rb
@@ -1,36 +0,0 @@
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