chatwork 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,102 @@
1
+ describe ChatWork::Client::MessageMethods do
2
+ describe "#get_messages", type: :api do
3
+ subject { client.get_messages(room_id: room_id, force: force, &block) }
4
+
5
+ let(:room_id) { 123 }
6
+
7
+ before do
8
+ stub_chatwork_request(:get, "/rooms/#{room_id}/messages", "/rooms/{room_id}/messages")
9
+ end
10
+
11
+ context "when force is Integer" do
12
+ let(:force) { 0 }
13
+
14
+ it_behaves_like :a_chatwork_api, :get, "/rooms/{room_id}/messages"
15
+ end
16
+
17
+ context "when force is boolean" do
18
+ let(:force) { false }
19
+
20
+ it_behaves_like :a_chatwork_api, :get, "/rooms/{room_id}/messages"
21
+ end
22
+ end
23
+
24
+ describe "#create_message", type: :api do
25
+ subject { client.create_message(room_id: room_id, body: body, &block) }
26
+
27
+ let(:room_id) { 123 }
28
+ let(:body) { "Hello ChatWork!" }
29
+
30
+ before do
31
+ stub_chatwork_request(:post, "/rooms/#{room_id}/messages", "/rooms/{room_id}/messages")
32
+ end
33
+
34
+ it_behaves_like :a_chatwork_api, :post, "/rooms/{room_id}/messages"
35
+ end
36
+
37
+ describe "#read_message", type: :api do
38
+ subject { client.read_message(room_id: room_id, message_id: message_id, &block) }
39
+
40
+ let(:room_id) { 123 }
41
+ let(:message_id) { "101" }
42
+
43
+ before do
44
+ stub_chatwork_request(:put, "/rooms/#{room_id}/messages/read", "/rooms/{room_id}/messages/read")
45
+ end
46
+
47
+ it_behaves_like :a_chatwork_api, :put, "/rooms/{room_id}/messages/read"
48
+ end
49
+
50
+ describe "#unread_message", type: :api do
51
+ subject { client.unread_message(room_id: room_id, message_id: message_id, &block) }
52
+
53
+ let(:room_id) { 123 }
54
+ let(:message_id) { "101" }
55
+
56
+ before do
57
+ stub_chatwork_request(:put, "/rooms/#{room_id}/messages/unread", "/rooms/{room_id}/messages/unread")
58
+ end
59
+
60
+ it_behaves_like :a_chatwork_api, :put, "/rooms/{room_id}/messages/unread"
61
+ end
62
+
63
+ describe "#find_message", type: :api do
64
+ subject { client.find_message(room_id: room_id, message_id: message_id, &block) }
65
+
66
+ let(:room_id) { 123 }
67
+ let(:message_id) { "101" }
68
+
69
+ before do
70
+ stub_chatwork_request(:get, "/rooms/#{room_id}/messages/#{message_id}", "/rooms/{room_id}/messages/{message_id}")
71
+ end
72
+
73
+ it_behaves_like :a_chatwork_api, :get, "/rooms/{room_id}/messages/{message_id}"
74
+ end
75
+
76
+ describe "#update_message", type: :api do
77
+ subject { client.update_message(room_id: room_id, message_id: message_id, body: body, &block) }
78
+
79
+ let(:room_id) { 123 }
80
+ let(:message_id) { "101" }
81
+ let(:body) { "Hello ChatWork!" }
82
+
83
+ before do
84
+ stub_chatwork_request(:put, "/rooms/#{room_id}/messages/#{message_id}", "/rooms/{room_id}/messages/{message_id}")
85
+ end
86
+
87
+ it_behaves_like :a_chatwork_api, :put, "/rooms/{room_id}/messages/{message_id}"
88
+ end
89
+
90
+ describe "#destroy_message", type: :api do
91
+ subject { client.destroy_message(room_id: room_id, message_id: message_id, &block) }
92
+
93
+ let(:room_id) { 123 }
94
+ let(:message_id) { "101" }
95
+
96
+ before do
97
+ stub_chatwork_request(:delete, "/rooms/#{room_id}/messages/#{message_id}", "/rooms/{room_id}/messages/{message_id}")
98
+ end
99
+
100
+ it_behaves_like :a_chatwork_api, :delete, "/rooms/{room_id}/messages/{message_id}"
101
+ end
102
+ end
@@ -0,0 +1,11 @@
1
+ describe ChatWork::Client::MyStatusMethods do
2
+ describe "#get_my_status", type: :api do
3
+ subject { client.get_my_status(&block) }
4
+
5
+ before do
6
+ stub_chatwork_request(:get, "/my/status")
7
+ end
8
+
9
+ it_behaves_like :a_chatwork_api, :get, "/my/status"
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ describe ChatWork::Client::MyTaskMethods do
2
+ describe "#get_my_tasks", type: :api do
3
+ subject do
4
+ client.get_my_tasks(
5
+ assigned_by_account_id: assigned_by_account_id,
6
+ status: status,
7
+ &block
8
+ )
9
+ end
10
+
11
+ let(:assigned_by_account_id) { 78 }
12
+ let(:status) { "done" }
13
+
14
+ before do
15
+ stub_chatwork_request(:get, "/my/tasks")
16
+ end
17
+
18
+ it_behaves_like :a_chatwork_api, :get, "/my/tasks"
19
+ end
20
+ end
@@ -0,0 +1,111 @@
1
+ describe ChatWork::Client::RoomMethods do
2
+ describe "#get_rooms", type: :api do
3
+ subject { client.get_rooms(&block) }
4
+
5
+ let(:room_id) { 123 }
6
+
7
+ before do
8
+ stub_chatwork_request(:get, "/rooms")
9
+ end
10
+
11
+ it_behaves_like :a_chatwork_api, :get, "/rooms"
12
+ end
13
+
14
+ describe "#create_room", type: :api do
15
+ subject do
16
+ client.create_room(
17
+ description: description,
18
+ icon_preset: icon_preset,
19
+ members_admin_ids: members_admin_ids,
20
+ members_member_ids: members_member_ids,
21
+ members_readonly_ids: members_readonly_ids,
22
+ name: name,
23
+ link: link,
24
+ link_code: link_code,
25
+ link_need_acceptance: link_need_acceptance,
26
+ &block
27
+ )
28
+ end
29
+
30
+ let(:description) { "group chat description" }
31
+ let(:icon_preset) { "meeting" }
32
+ let(:name) { "Website renewal project" }
33
+ let(:link) { false }
34
+ let(:link_need_acceptance) { true }
35
+ let(:link_code) { nil }
36
+
37
+ before do
38
+ stub_chatwork_request(:post, "/rooms")
39
+ end
40
+
41
+ context "with String" do
42
+ let(:members_admin_ids) { "123,542,1001" }
43
+ let(:members_member_ids) { "21,344" }
44
+ let(:members_readonly_ids) { "15,103" }
45
+
46
+ it_behaves_like :a_chatwork_api, :post, "/rooms"
47
+ end
48
+
49
+ context "with Array" do
50
+ let(:members_admin_ids) { [123, 542, 1001] }
51
+ let(:members_member_ids) { [21, 344] }
52
+ let(:members_readonly_ids) { [15, 103] }
53
+
54
+ it_behaves_like :a_chatwork_api, :post, "/rooms"
55
+ end
56
+ end
57
+
58
+ describe "#find_room", type: :api do
59
+ subject { client.find_room(room_id: room_id, &block) }
60
+
61
+ let(:room_id) { 123 }
62
+
63
+ before do
64
+ stub_chatwork_request(:get, "/rooms/#{room_id}", "/rooms/{room_id}")
65
+ end
66
+
67
+ it_behaves_like :a_chatwork_api, :get, "/rooms/{room_id}"
68
+ end
69
+
70
+ describe "#update_room", type: :api do
71
+ subject do
72
+ client.update_room(
73
+ room_id: room_id,
74
+ description: description,
75
+ icon_preset: icon_preset,
76
+ name: name,
77
+ &block
78
+ )
79
+ end
80
+
81
+ let(:room_id) { 123 }
82
+ let(:description) { "group chat description" }
83
+ let(:icon_preset) { "meeting" }
84
+ let(:name) { "Website renewal project" }
85
+
86
+ before do
87
+ stub_chatwork_request(:put, "/rooms/#{room_id}", "/rooms/{room_id}")
88
+ end
89
+
90
+ it_behaves_like :a_chatwork_api, :put, "/rooms/{room_id}"
91
+ end
92
+
93
+ describe "#destroy_room", type: :api do
94
+ subject do
95
+ client.destroy_room(
96
+ room_id: room_id,
97
+ action_type: action_type,
98
+ &block
99
+ )
100
+ end
101
+
102
+ let(:room_id) { 123 }
103
+ let(:action_type) { "leave" }
104
+
105
+ before do
106
+ stub_chatwork_request(:delete, "/rooms/#{room_id}", "/rooms/{room_id}", 204)
107
+ end
108
+
109
+ it_behaves_like :a_chatwork_api, :delete, "/rooms/{room_id}", 204
110
+ end
111
+ end
@@ -0,0 +1,80 @@
1
+ describe ChatWork::Client::TaskMethods do
2
+ describe "#get_tasks", type: :api do
3
+ subject do
4
+ client.get_tasks(
5
+ room_id: room_id,
6
+ account_id: account_id,
7
+ assigned_by_account_id: assigned_by_account_id,
8
+ status: status,
9
+ &block
10
+ )
11
+ end
12
+
13
+ let(:room_id) { 123 }
14
+ let(:account_id) { 101 }
15
+ let(:assigned_by_account_id) { 78 }
16
+ let(:status) { "done" }
17
+
18
+ before do
19
+ stub_chatwork_request(:get, "/rooms/#{room_id}/tasks", "/rooms/{room_id}/tasks")
20
+ end
21
+
22
+ it_behaves_like :a_chatwork_api, :get, "/rooms/{room_id}/tasks"
23
+ end
24
+
25
+ describe "#create_task", type: :api do
26
+ subject do
27
+ client.create_task(
28
+ room_id: room_id,
29
+ body: body,
30
+ to_ids: to_ids,
31
+ limit: limit,
32
+ &block
33
+ )
34
+ end
35
+
36
+ let(:room_id) { 123 }
37
+ let(:body) { "Buy milk" }
38
+ let(:to_ids) { "1,3,6" }
39
+ let(:limit) { "1385996399" }
40
+
41
+ before do
42
+ stub_chatwork_request(:post, "/rooms/#{room_id}/tasks", "/rooms/{room_id}/tasks")
43
+ end
44
+
45
+ context "when to_ids and limit are String" do
46
+ it_behaves_like :a_chatwork_api, :post, "/rooms/{room_id}/tasks"
47
+ end
48
+
49
+ context "when to_ids is Array" do
50
+ let(:to_ids) { [1, 3, 6] }
51
+
52
+ it_behaves_like :a_chatwork_api, :post, "/rooms/{room_id}/tasks"
53
+ end
54
+
55
+ context "when limit is Time" do
56
+ let(:limit) { Time.at(1_385_996_399) }
57
+
58
+ it_behaves_like :a_chatwork_api, :post, "/rooms/{room_id}/tasks"
59
+ end
60
+ end
61
+
62
+ describe "#find_task", type: :api do
63
+ subject do
64
+ client.find_task(
65
+ room_id: room_id,
66
+ task_id: task_id,
67
+ &block
68
+ )
69
+ end
70
+
71
+ let(:room_id) { 123 }
72
+ let(:task_id) { 3 }
73
+
74
+ before do
75
+ stub_chatwork_request(:get, "/rooms/#{room_id}/tasks/#{task_id}", "/rooms/{room_id}/tasks/{task_id}")
76
+ end
77
+
78
+ it_behaves_like :a_chatwork_api, :get, "/rooms/{room_id}/tasks/{task_id}"
79
+ end
80
+ end
@@ -1,6 +1,13 @@
1
1
  describe ChatWork::Client do
2
2
  describe "#initialize" do
3
- subject { ChatWork::Client.new(api_key, access_token, api_base, api_version) }
3
+ subject do
4
+ ChatWork::Client.new(
5
+ api_key: api_key,
6
+ access_token: access_token,
7
+ api_base: api_base,
8
+ api_version: api_version,
9
+ )
10
+ end
4
11
 
5
12
  let(:api_key) { nil }
6
13
  let(:access_token) { nil }
@@ -1,11 +1,11 @@
1
1
  describe ChatWork::Contacts do
2
2
  describe ".get", type: :api do
3
- subject { ChatWork::Contacts.get }
3
+ subject { ChatWork::Contacts.get(&block) }
4
4
 
5
5
  before do
6
6
  stub_chatwork_request(:get, "/contacts")
7
7
  end
8
8
 
9
- it_behaves_like :a_chatwork_api, :get, "contacts"
9
+ it_behaves_like :a_chatwork_api, :get, "/contacts"
10
10
  end
11
11
  end
@@ -1,5 +1,5 @@
1
- describe ChatWork::EntityMethods do
2
- include ChatWork::EntityMethods
1
+ describe ChatWork::Converter do
2
+ include ChatWork::Converter
3
3
 
4
4
  describe "#boolean_to_integer" do
5
5
  subject { boolean_to_integer(value) }
@@ -1,6 +1,6 @@
1
1
  describe ChatWork::File do
2
2
  describe ".get", type: :api do
3
- subject { ChatWork::File.get(room_id: room_id, account_id: account_id) }
3
+ subject { ChatWork::File.get(room_id: room_id, account_id: account_id, &block) }
4
4
 
5
5
  before do
6
6
  stub_chatwork_request(:get, "/rooms/#{room_id}/files", "/rooms/{room_id}/files")
@@ -13,7 +13,7 @@ describe ChatWork::File do
13
13
  end
14
14
 
15
15
  describe ".find", type: :api do
16
- subject { ChatWork::File.find(room_id: room_id, file_id: file_id, create_download_url: create_download_url) }
16
+ subject { ChatWork::File.find(room_id: room_id, file_id: file_id, create_download_url: create_download_url, &block) }
17
17
 
18
18
  before do
19
19
  stub_chatwork_request(:get, "/rooms/#{room_id}/files/#{file_id}", "/rooms/{room_id}/files/{file_id}")
@@ -1,6 +1,6 @@
1
1
  describe ChatWork::IncomingRequest do
2
2
  describe ".get", type: :api do
3
- subject { ChatWork::IncomingRequest.get }
3
+ subject { ChatWork::IncomingRequest.get(&block) }
4
4
 
5
5
  before do
6
6
  stub_chatwork_request(:get, "/incoming_requests")
@@ -10,7 +10,7 @@ describe ChatWork::IncomingRequest do
10
10
  end
11
11
 
12
12
  describe ".update", type: :api do
13
- subject { ChatWork::IncomingRequest.update(request_id: request_id) }
13
+ subject { ChatWork::IncomingRequest.update(request_id: request_id, &block) }
14
14
 
15
15
  let(:request_id) { 123 }
16
16
 
@@ -22,7 +22,7 @@ describe ChatWork::IncomingRequest do
22
22
  end
23
23
 
24
24
  describe ".destroy", type: :api do
25
- subject { ChatWork::IncomingRequest.destroy(request_id: request_id) }
25
+ subject { ChatWork::IncomingRequest.destroy(request_id: request_id, &block) }
26
26
 
27
27
  let(:request_id) { 123 }
28
28
 
@@ -1,6 +1,6 @@
1
1
  describe ChatWork::InvitationLink do
2
2
  describe ".get", type: :api do
3
- subject { ChatWork::InvitationLink.get(room_id: room_id) }
3
+ subject { ChatWork::InvitationLink.get(room_id: room_id, &block) }
4
4
 
5
5
  let(:room_id) { 123 }
6
6
 
@@ -18,6 +18,7 @@ describe ChatWork::InvitationLink do
18
18
  code: code,
19
19
  description: description,
20
20
  need_acceptance: need_acceptance,
21
+ &block
21
22
  )
22
23
  end
23
24
 
@@ -40,6 +41,7 @@ describe ChatWork::InvitationLink do
40
41
  code: code,
41
42
  description: description,
42
43
  need_acceptance: need_acceptance,
44
+ &block
43
45
  )
44
46
  end
45
47
 
@@ -56,7 +58,7 @@ describe ChatWork::InvitationLink do
56
58
  end
57
59
 
58
60
  describe ".destroy", type: :api do
59
- subject { ChatWork::InvitationLink.destroy(room_id: room_id) }
61
+ subject { ChatWork::InvitationLink.destroy(room_id: room_id, &block) }
60
62
 
61
63
  let(:room_id) { 123 }
62
64
 
@@ -1,6 +1,6 @@
1
1
  describe ChatWork::Me do
2
2
  describe ".get", type: :api do
3
- subject { ChatWork::Me.get }
3
+ subject { ChatWork::Me.get(&block) }
4
4
 
5
5
  before do
6
6
  stub_chatwork_request(:get, "/me")
@@ -8,31 +8,13 @@ describe ChatWork::Me do
8
8
 
9
9
  it_behaves_like :a_chatwork_api, :get, "/me"
10
10
 
11
- its(:account_id) { should eq 123 }
12
- its(:room_id) { should eq 322 }
13
- its(:name) { should eq "John Smith" }
14
- its(:chatwork_id) { should eq "tarochatworkid" }
15
- its(:organization_id) { should eq 101 }
16
- its(:organization_name) { should eq "Hello Company" }
17
- its(:department) { should eq "Marketing" }
18
- its(:title) { should eq "CMO" }
19
- its(:url) { should eq "http://mycompany.example.com" }
20
- its(:introduction) { should eq "Self Introduction" }
21
- its(:mail) { should eq "taro@example.com" }
22
- its(:tel_organization) { should eq "XXX-XXXX-XXXX" }
23
- its(:tel_extension) { should eq "YYY-YYYY-YYYY" }
24
- its(:tel_mobile) { should eq "ZZZ-ZZZZ-ZZZZ" }
25
- its(:skype) { should eq "myskype_id" }
26
- its(:facebook) { should eq "myfacebook_id" }
27
- its(:twitter) { should eq "mytwitter_id" }
28
- its(:avatar_image_url) { should eq "https://example.com/abc.png" }
29
- its(:login_mail) { should eq "account@example.com" }
30
-
31
11
  context "when unauthorized" do
32
12
  before do
33
13
  stub_chatwork_request(:get, "/me", "/me", 401)
34
14
  end
35
15
 
16
+ let(:block) { nil }
17
+
36
18
  it { expect { subject }.to raise_error(ChatWork::APIError, "Invalid API token") }
37
19
  end
38
20
  end