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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +113 -38
- data/lib/chatwork.rb +35 -3
- data/lib/chatwork/base_client.rb +9 -4
- data/lib/chatwork/client.rb +43 -8
- data/lib/chatwork/client/contacts_methods.rb +29 -0
- data/lib/chatwork/client/file_methods.rb +67 -0
- data/lib/chatwork/client/incoming_request_methods.rb +77 -0
- data/lib/chatwork/client/invitation_link_methods.rb +110 -0
- data/lib/chatwork/client/me_methods.rb +38 -0
- data/lib/chatwork/client/member_methods.rb +64 -0
- data/lib/chatwork/client/message_methods.rb +178 -0
- data/lib/chatwork/client/my_status_methods.rb +25 -0
- data/lib/chatwork/client/my_task_methods.rb +41 -0
- data/lib/chatwork/client/room_methods.rb +156 -0
- data/lib/chatwork/client/task_methods.rb +109 -0
- data/lib/chatwork/contacts.rb +6 -4
- data/lib/chatwork/converter.rb +18 -0
- data/lib/chatwork/file.rb +12 -6
- data/lib/chatwork/incoming_request.rb +18 -8
- data/lib/chatwork/invitation_link.rb +24 -20
- data/lib/chatwork/me.rb +6 -4
- data/lib/chatwork/member.rb +18 -12
- data/lib/chatwork/message.rb +42 -16
- data/lib/chatwork/my_status.rb +6 -4
- data/lib/chatwork/my_task.rb +6 -4
- data/lib/chatwork/oauth_client.rb +10 -2
- data/lib/chatwork/oauth_client/token_methods.rb +25 -0
- data/lib/chatwork/room.rb +37 -20
- data/lib/chatwork/task.rb +18 -14
- data/lib/chatwork/token.rb +1 -7
- data/lib/chatwork/version.rb +1 -1
- data/spec/lib/chatwork/client/contacts_methods_spec.rb +11 -0
- data/spec/lib/chatwork/client/file_methods_spec.rb +37 -0
- data/spec/lib/chatwork/client/incoming_request_methods_spec.rb +35 -0
- data/spec/lib/chatwork/client/invitation_link_methods_spec.rb +71 -0
- data/spec/lib/chatwork/client/me_methods_spec.rb +21 -0
- data/spec/lib/chatwork/client/member_methods_spec.rb +47 -0
- data/spec/lib/chatwork/client/message_methods_spec.rb +102 -0
- data/spec/lib/chatwork/client/my_status_methods_spec.rb +11 -0
- data/spec/lib/chatwork/client/my_task_methods_spec.rb +20 -0
- data/spec/lib/chatwork/client/room_methods_spec.rb +111 -0
- data/spec/lib/chatwork/client/task_methods_spec.rb +80 -0
- data/spec/lib/chatwork/client_spec.rb +8 -1
- data/spec/lib/chatwork/contacts_spec.rb +2 -2
- data/spec/lib/chatwork/{entity_methods_spec.rb → converter_spec.rb} +2 -2
- data/spec/lib/chatwork/file_spec.rb +2 -2
- data/spec/lib/chatwork/incoming_request_spec.rb +3 -3
- data/spec/lib/chatwork/invitation_link_spec.rb +4 -2
- data/spec/lib/chatwork/me_spec.rb +3 -21
- data/spec/lib/chatwork/member_spec.rb +2 -1
- data/spec/lib/chatwork/message_spec.rb +7 -7
- data/spec/lib/chatwork/my_status_spec.rb +1 -1
- data/spec/lib/chatwork/my_task_spec.rb +1 -0
- data/spec/lib/chatwork/{token_spec.rb → oauth_client/token_methods_spec.rb} +4 -7
- data/spec/lib/chatwork/oauth_client_spec.rb +7 -1
- data/spec/lib/chatwork/room_spec.rb +5 -2
- data/spec/lib/chatwork/task_spec.rb +3 -0
- data/spec/support/contexts/api_context.rb +4 -3
- data/spec/support/examples/a_chatwork_api.rb +22 -5
- data/spec/support/utils/raml_parser.rb +2 -3
- metadata +42 -8
- data/lib/chatwork/entity_methods.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 301622474ab7870e4bc7b6d51888c6af0f16224de722f865925b180ac8aa55b5
|
4
|
+
data.tar.gz: 745b6eaae10a5911cfd14ea8e53d587e8891e41e803fae50ba6ba502bb3b481c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d3b4a9e19b02158ca9939980ab02e2f5665a98d5d004b8d63d4f2eda7e76eacddf253c1ef1c16cb17b24780bce853c04814bd3dd98763c372148fd777ca89dd
|
7
|
+
data.tar.gz: 0e65991b921fb0e541a50c2aa6cc92ac700ebcde31539bc8a562cb47d244956790f0dec64c033717fc87ca2315ef8c135fd42461d531c9a1353059357c494b58
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
## Unreleased
|
3
|
-
[Full Changelog](https://github.com/asonas/chatwork-ruby/compare/v0.
|
3
|
+
[Full Changelog](https://github.com/asonas/chatwork-ruby/compare/v0.8.0...master)
|
4
|
+
|
5
|
+
## v0.8.0
|
6
|
+
[Full Changelog](https://github.com/asonas/chatwork-ruby/compare/v0.7.0...v0.8.0)
|
7
|
+
|
8
|
+
* Add instance methods of `ChatWork::Client`
|
9
|
+
* https://github.com/asonas/chatwork-ruby/pull/49
|
10
|
+
* Fixed. API method did not accept block
|
11
|
+
* https://github.com/asonas/chatwork-ruby/pull/50
|
4
12
|
|
5
13
|
## v0.7.0
|
6
14
|
[Full Changelog](https://github.com/asonas/chatwork-ruby/compare/v0.6.2...v0.7.0)
|
data/README.md
CHANGED
@@ -22,50 +22,45 @@ Or install it yourself as:
|
|
22
22
|
$ gem install chatwork
|
23
23
|
|
24
24
|
## Usage
|
25
|
+
`chatwork` gem provides class method APIs and instance method APIs
|
25
26
|
|
26
|
-
###
|
27
|
+
### Class method APIs
|
28
|
+
At first, set `ChatWork.api_key` or `ChatWork.access_token`.
|
27
29
|
|
28
|
-
```
|
29
|
-
require "chatwork"
|
30
|
-
|
31
|
-
# Create message
|
30
|
+
```ruby
|
32
31
|
ChatWork.api_key = "XXX"
|
33
|
-
|
32
|
+
# or
|
33
|
+
ChatWork.access_token = "XXX"
|
34
34
|
```
|
35
35
|
|
36
|
-
or
|
37
|
-
|
38
|
-
``` sh
|
39
|
-
$ cat send_message.rb
|
40
|
-
require "chatwork"
|
36
|
+
Another way, you can use `ENV["CHATWORK_API_TOKEN"]` or `ENV["CHATWORK_ACCESS_TOKEN"]` instead of `ChatWork.api_key` or `ChatWork.access_token`.
|
41
37
|
|
42
|
-
|
43
|
-
$ CHATWORK_API_TOKEN=xxx ruby send_message.rb
|
44
|
-
```
|
38
|
+
Then call class methods.
|
45
39
|
|
46
|
-
|
47
|
-
``` ruby
|
48
|
-
require "chatwork"
|
40
|
+
e.g. post message.
|
49
41
|
|
50
|
-
|
51
|
-
ChatWork.access_token = "XXX"
|
42
|
+
```ruby
|
52
43
|
ChatWork::Message.create(room_id: 1234, body: "Hello, ChatWork!")
|
44
|
+
#=> #<Hashie::Mash message_id="1234567890">
|
53
45
|
```
|
54
46
|
|
55
|
-
|
56
|
-
|
57
|
-
``` sh
|
58
|
-
$ cat send_message_with_access_token.rb
|
59
|
-
require "chatwork"
|
47
|
+
All available APIs are followings.
|
60
48
|
|
61
|
-
ChatWork::
|
62
|
-
|
63
|
-
|
49
|
+
* [ChatWork::Contacts](lib/chatwork/contacts.rb)
|
50
|
+
* [ChatWork::File](lib/chatwork/file.rb)
|
51
|
+
* [ChatWork::IncomingRequest](lib/chatwork/incoming_request.rb)
|
52
|
+
* [ChatWork::InvitationLink](lib/chatwork/invitation_link.rb)
|
53
|
+
* [ChatWork::Me](lib/chatwork/me.rb)
|
54
|
+
* [ChatWork::Member](lib/chatwork/member.rb)
|
55
|
+
* [ChatWork::Message](lib/chatwork/message.rb)
|
56
|
+
* [ChatWork::MyStatus](lib/chatwork/my_status.rb)
|
57
|
+
* [ChatWork::MyTask](lib/chatwork/my_task.rb)
|
58
|
+
* [ChatWork::Room](lib/chatwork/room.rb)
|
59
|
+
* [ChatWork::Task](lib/chatwork/task.rb)
|
64
60
|
|
65
|
-
|
66
|
-
``` ruby
|
67
|
-
require "chatwork"
|
61
|
+
When you want to refresh access token, call [`ChatWork::Token.refresh_access_token`](lib/chatwork/token.rb).
|
68
62
|
|
63
|
+
```ruby
|
69
64
|
ChatWork.client_id = "XXX"
|
70
65
|
ChatWork.client_secret = "XXX"
|
71
66
|
refresh_token = "XXX"
|
@@ -77,19 +72,99 @@ ChatWork.access_token = new_access_token
|
|
77
72
|
ChatWork::Message.create(room_id: 1234, body: "Hello, ChatWork!")
|
78
73
|
```
|
79
74
|
|
80
|
-
or
|
75
|
+
Another way, you can use `ENV["CHATWORK_CLIENT_ID"]` or `ENV["CHATWORK_CLIENT_SECRET"]` instead of `ChatWork.api_key` or `ChatWork.access_token`.
|
76
|
+
|
77
|
+
### Instance method APIs
|
78
|
+
```ruby
|
79
|
+
client = ChatWork::Client.new(api_key: "XXX")
|
80
|
+
#or
|
81
|
+
client = ChatWork::Client.new(access_token: "XXX")
|
82
|
+
```
|
83
|
+
|
84
|
+
Then call instance methods.
|
85
|
+
|
86
|
+
e.g. post message.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
client.create_message(room_id: 1234, body: "Hello, ChatWork!")
|
90
|
+
#=> #<Hashie::Mash message_id="1234567890">
|
91
|
+
```
|
92
|
+
|
93
|
+
All available APIs are followings.
|
94
|
+
|
95
|
+
http://www.rubydoc.info/gems/chatwork/ChatWork/Client
|
81
96
|
|
82
|
-
|
83
|
-
$ cat refresh_access_token.rb
|
84
|
-
require "chatwork"
|
97
|
+
When you want to refresh access token, call [`ChatWork::OAuthClient#refresh_access_token`](lib/chatwork/oauth_client/token_methods.rb).
|
85
98
|
|
86
|
-
|
99
|
+
```ruby
|
100
|
+
refresh_token = "XXX"
|
101
|
+
oauth_client = ChatWork::OAuthClient.new(client_id: "xxx", client_secret: "xxx")
|
102
|
+
token = oauth_client.refresh_access_token(refresh_token)
|
87
103
|
new_access_token = token["access_token"]
|
88
104
|
|
89
105
|
# Create message
|
90
|
-
ChatWork.access_token
|
91
|
-
|
92
|
-
|
106
|
+
client = ChatWork::Client.new(access_token: new_access_token)
|
107
|
+
client.create_message(room_id: 1234, body: "Hello, ChatWork!")
|
108
|
+
```
|
109
|
+
|
110
|
+
### Pros/Cons
|
111
|
+
Class method APIs are simple, but **not threadsafe**. Instance method APIs are **threadsafe**.
|
112
|
+
|
113
|
+
If you are using multiple `api_key` or `access_token` in an app and using multithreaded server (e.g. [puma](https://github.com/puma/puma)), we recommend instance method APIs.
|
114
|
+
|
115
|
+
## Tips
|
116
|
+
### Hashie::Mash
|
117
|
+
All API methods returns `Hashie::Mash` instance.
|
118
|
+
|
119
|
+
https://github.com/intridea/hashie#mash
|
120
|
+
|
121
|
+
`Hashie::Mash` is very useful!
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
body = ChatWork::Message.create(room_id: 1234, body: "Hello, ChatWork!")
|
125
|
+
#=> #<Hashie::Mash message_id="1234567890">
|
126
|
+
|
127
|
+
body["message_id"]
|
128
|
+
#=> "1234567890"
|
129
|
+
|
130
|
+
body[:message_id]
|
131
|
+
#=> "1234567890"
|
132
|
+
|
133
|
+
body.message_id
|
134
|
+
#=> "1234567890"
|
135
|
+
```
|
136
|
+
|
137
|
+
### Block arguments
|
138
|
+
All API methods supports block argument.
|
139
|
+
|
140
|
+
If block was given, return response body and response header through block arguments.
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
ChatWork::Message.create(room_id: 1234, body: "Hello, ChatWork!") do |body, header|
|
144
|
+
body
|
145
|
+
#=> #<Hashie::Mash message_id="1234567890">
|
146
|
+
|
147
|
+
header["X-RateLimit-Limit"]
|
148
|
+
#=> "100"
|
149
|
+
header["X-RateLimit-Remaining"]
|
150
|
+
#=> "0"
|
151
|
+
header["X-RateLimit-Reset"]
|
152
|
+
#=> "1390941626"
|
153
|
+
end
|
154
|
+
```
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
client.create_message(room_id: 1234, body: "Hello, ChatWork!") do |body, header|
|
158
|
+
body
|
159
|
+
#=> #<Hashie::Mash message_id="1234567890">
|
160
|
+
|
161
|
+
header["X-RateLimit-Limit"]
|
162
|
+
#=> "100"
|
163
|
+
header["X-RateLimit-Remaining"]
|
164
|
+
#=> "0"
|
165
|
+
header["X-RateLimit-Reset"]
|
166
|
+
#=> "1390941626"
|
167
|
+
end
|
93
168
|
```
|
94
169
|
|
95
170
|
## Reference
|
data/lib/chatwork.rb
CHANGED
@@ -9,7 +9,7 @@ module ChatWork
|
|
9
9
|
autoload :ChatWorkError, "chatwork/chatwork_error"
|
10
10
|
autoload :Client, "chatwork/client"
|
11
11
|
autoload :Contacts, "chatwork/contacts"
|
12
|
-
autoload :
|
12
|
+
autoload :Converter, "chatwork/converter"
|
13
13
|
autoload :File, "chatwork/file"
|
14
14
|
autoload :IncomingRequest, "chatwork/incoming_request"
|
15
15
|
autoload :InvitationLink, "chatwork/invitation_link"
|
@@ -32,64 +32,96 @@ module ChatWork
|
|
32
32
|
@client_secret = nil
|
33
33
|
|
34
34
|
class << self
|
35
|
+
# @!attribute [r] api_base
|
36
|
+
# @return [String]
|
35
37
|
attr_reader :api_base
|
36
38
|
|
39
|
+
# @!attribute [r] oauth_api_base
|
40
|
+
# @return [String]
|
37
41
|
attr_reader :oauth_api_base
|
38
42
|
|
43
|
+
# @!attribute [r] api_version
|
44
|
+
# @return [String]
|
39
45
|
attr_reader :api_version
|
40
46
|
|
47
|
+
# @return [ChatWork::Client]
|
41
48
|
def client
|
42
|
-
@client ||= Client.new(api_key, access_token
|
49
|
+
@client ||= Client.new(api_key: api_key, access_token: access_token)
|
43
50
|
end
|
44
51
|
|
52
|
+
# @return [ChatWork::OAuthClient]
|
45
53
|
def oauth_client
|
46
|
-
@oauth_client ||= OAuthClient.new(client_id, client_secret
|
54
|
+
@oauth_client ||= OAuthClient.new(client_id: client_id, client_secret: client_secret)
|
47
55
|
end
|
48
56
|
|
57
|
+
# @param new_value [String]
|
49
58
|
def api_base=(new_value)
|
50
59
|
@api_base = new_value
|
51
60
|
@client = nil
|
52
61
|
end
|
53
62
|
|
63
|
+
# @param new_value [String]
|
64
|
+
def api_version=(new_value)
|
65
|
+
@api_version = new_value
|
66
|
+
@client = nil
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param new_value [String]
|
54
70
|
def oauth_api_base=(new_value)
|
55
71
|
@oauth_api_base = new_value
|
56
72
|
@oauth_client = nil
|
57
73
|
end
|
58
74
|
|
75
|
+
# @param new_value [String]
|
59
76
|
def api_key=(new_value)
|
60
77
|
@api_key = new_value
|
61
78
|
@access_token = nil
|
62
79
|
@client = nil
|
63
80
|
end
|
64
81
|
|
82
|
+
# @param new_value [String]
|
65
83
|
def access_token=(new_value)
|
66
84
|
@api_key = nil
|
67
85
|
@access_token = new_value
|
68
86
|
@client = nil
|
69
87
|
end
|
70
88
|
|
89
|
+
# @param new_value [String]
|
71
90
|
def client_id=(new_value)
|
72
91
|
@client_id = new_value
|
73
92
|
@oauth_client = nil
|
74
93
|
end
|
75
94
|
|
95
|
+
# @param new_value [String]
|
76
96
|
def client_secret=(new_value)
|
77
97
|
@client_secret = new_value
|
78
98
|
@oauth_client = nil
|
79
99
|
end
|
80
100
|
|
101
|
+
# @return [String]
|
102
|
+
#
|
103
|
+
# @note if {ChatWork.api_key} is not defined, returns `ENV["CHATWORK_API_TOKEN"]`
|
81
104
|
def api_key
|
82
105
|
@api_key || ENV["CHATWORK_API_TOKEN"]
|
83
106
|
end
|
84
107
|
|
108
|
+
# @return [String]
|
109
|
+
#
|
110
|
+
# @note if {ChatWork.access_token} is not defined, returns `ENV["CHATWORK_ACCESS_TOKEN"]`
|
85
111
|
def access_token
|
86
112
|
@access_token || ENV["CHATWORK_ACCESS_TOKEN"]
|
87
113
|
end
|
88
114
|
|
115
|
+
# @return [String]
|
116
|
+
#
|
117
|
+
# @note if {ChatWork.client_id} is not defined, returns `ENV["CHATWORK_CLIENT_ID"]`
|
89
118
|
def client_id
|
90
119
|
@client_id || ENV["CHATWORK_CLIENT_ID"]
|
91
120
|
end
|
92
121
|
|
122
|
+
# @return [String]
|
123
|
+
#
|
124
|
+
# @note if {ChatWork.client_secret} is not defined, returns `ENV["CHATWORK_CLIENT_SECRET"]`
|
93
125
|
def client_secret
|
94
126
|
@client_secret || ENV["CHATWORK_CLIENT_SECRET"]
|
95
127
|
end
|
data/lib/chatwork/base_client.rb
CHANGED
@@ -3,14 +3,19 @@ require "faraday_middleware"
|
|
3
3
|
|
4
4
|
module ChatWork
|
5
5
|
class BaseClient
|
6
|
-
|
6
|
+
include Converter
|
7
|
+
|
8
|
+
# @param api_base [String]
|
9
|
+
# @param api_version [String]
|
10
|
+
# @param header [Hash<String,String>]
|
11
|
+
def initialize(api_base:, api_version: "", header:)
|
7
12
|
default_header = {
|
8
13
|
"User-Agent" => "ChatWork#{api_version} RubyBinding/#{ChatWork::VERSION}",
|
9
14
|
}
|
10
15
|
|
11
16
|
default_header.merge!(header)
|
12
17
|
|
13
|
-
@conn = Faraday.new(
|
18
|
+
@conn = Faraday.new(api_base, headers: default_header) do |builder|
|
14
19
|
builder.request :url_encoded
|
15
20
|
builder.response :mashify
|
16
21
|
builder.response :json
|
@@ -29,9 +34,9 @@ module ChatWork
|
|
29
34
|
end
|
30
35
|
|
31
36
|
Faraday::Connection::METHODS.each do |method|
|
32
|
-
define_method(method) do |url,
|
37
|
+
define_method(method) do |url, args = {}, &block|
|
33
38
|
begin
|
34
|
-
response = @conn.__send__(method, @api_version + url,
|
39
|
+
response = @conn.__send__(method, @api_version + url, hash_compact(args))
|
35
40
|
rescue Faraday::Error::ClientError => e
|
36
41
|
raise ChatWork::APIConnectionError.faraday_error(e)
|
37
42
|
end
|
data/lib/chatwork/client.rb
CHANGED
@@ -1,13 +1,48 @@
|
|
1
1
|
module ChatWork
|
2
2
|
class Client < BaseClient
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
require "chatwork/client/contacts_methods"
|
4
|
+
require "chatwork/client/file_methods"
|
5
|
+
require "chatwork/client/incoming_request_methods"
|
6
|
+
require "chatwork/client/invitation_link_methods"
|
7
|
+
require "chatwork/client/me_methods"
|
8
|
+
require "chatwork/client/member_methods"
|
9
|
+
require "chatwork/client/message_methods"
|
10
|
+
require "chatwork/client/my_status_methods"
|
11
|
+
require "chatwork/client/my_task_methods"
|
12
|
+
require "chatwork/client/room_methods"
|
13
|
+
require "chatwork/client/task_methods"
|
14
|
+
|
15
|
+
include ContactsMethods
|
16
|
+
include FileMethods
|
17
|
+
include IncomingRequestMethods
|
18
|
+
include InvitationLinkMethods
|
19
|
+
include MeMethods
|
20
|
+
include MemberMethods
|
21
|
+
include MessageMethods
|
22
|
+
include MyStatusMethods
|
23
|
+
include MyTaskMethods
|
24
|
+
include RoomMethods
|
25
|
+
include TaskMethods
|
26
|
+
|
27
|
+
# @param api_key [String]
|
28
|
+
# @param access_token [String]
|
29
|
+
# @param api_base [String] default is {ChatWork.api_base}
|
30
|
+
# @param api_version [String] default is {ChatWork.api_version}
|
31
|
+
# @note Either api_key or access_token is required
|
32
|
+
def initialize(api_key: nil, access_token: nil, api_base: nil, api_version: nil)
|
33
|
+
api_base ||= ChatWork.api_base
|
34
|
+
api_version ||= ChatWork.api_version
|
35
|
+
|
36
|
+
header =
|
37
|
+
if api_key
|
38
|
+
{ "X-ChatWorkToken" => api_key }
|
39
|
+
elsif access_token
|
40
|
+
{ "Authorization" => "Bearer #{access_token}" }
|
41
|
+
else
|
42
|
+
raise "Either api_key or access_token is required"
|
43
|
+
end
|
44
|
+
|
45
|
+
super(api_base: api_base, api_version: api_version, header: header)
|
11
46
|
end
|
12
47
|
end
|
13
48
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ChatWork::Client::ContactsMethods
|
2
|
+
# Get the list of your contacts
|
3
|
+
#
|
4
|
+
# @see http://developer.chatwork.com/ja/endpoint_contacts.html#GET-contacts
|
5
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
6
|
+
#
|
7
|
+
# @yield [response_body, response_header] if block was given, return response body and response header through block arguments
|
8
|
+
# @yieldparam response_body [Array<Hashie::Mash>] response body
|
9
|
+
# @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
|
10
|
+
#
|
11
|
+
# @return [Array<Hashie::Mash>]
|
12
|
+
#
|
13
|
+
# @example response format
|
14
|
+
# [
|
15
|
+
# {
|
16
|
+
# "account_id": 123,
|
17
|
+
# "room_id": 322,
|
18
|
+
# "name": "John Smith",
|
19
|
+
# "chatwork_id": "tarochatworkid",
|
20
|
+
# "organization_id": 101,
|
21
|
+
# "organization_name": "Hello Company",
|
22
|
+
# "department": "Marketing",
|
23
|
+
# "avatar_image_url": "https://example.com/abc.png"
|
24
|
+
# }
|
25
|
+
# ]
|
26
|
+
def get_contacts(&block)
|
27
|
+
get("/contacts", &block)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module ChatWork::Client::FileMethods
|
2
|
+
# Get the list of files associated with the specified chat
|
3
|
+
#
|
4
|
+
# @param room_id [Integer]
|
5
|
+
# @param account_id [Integer]
|
6
|
+
#
|
7
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-files
|
8
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
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
|
+
#
|
14
|
+
# @return [Array<Hashie::Mash>]
|
15
|
+
#
|
16
|
+
# @example response format
|
17
|
+
# [
|
18
|
+
# {
|
19
|
+
# "file_id": 3,
|
20
|
+
# "account": {
|
21
|
+
# "account_id": 123,
|
22
|
+
# "name": "Bob",
|
23
|
+
# "avatar_image_url": "https://example.com/ico_avatar.png"
|
24
|
+
# },
|
25
|
+
# "message_id": "22",
|
26
|
+
# "filename": "README.md",
|
27
|
+
# "filesize": 2232,
|
28
|
+
# "upload_time": 1384414750
|
29
|
+
# }
|
30
|
+
# ]
|
31
|
+
def get_files(room_id:, account_id:, &block)
|
32
|
+
get("/rooms/#{room_id}/files", account_id: account_id, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get information about the specified file
|
36
|
+
#
|
37
|
+
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-files-file_id
|
38
|
+
# @see http://download.chatwork.com/ChatWork_API_Documentation.pdf
|
39
|
+
#
|
40
|
+
# @param room_id [Integer]
|
41
|
+
# @param file_id [Integer]
|
42
|
+
# @param create_download_url [Boolean] whether or not to create a download link.
|
43
|
+
# If set to true, download like will be created for 30 seconds
|
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
|
+
#
|
49
|
+
# @return [Hashie::Mash]
|
50
|
+
#
|
51
|
+
# @example response format
|
52
|
+
# {
|
53
|
+
# "file_id":3,
|
54
|
+
# "account": {
|
55
|
+
# "account_id":123,
|
56
|
+
# "name":"Bob",
|
57
|
+
# "avatar_image_url": "https://example.com/ico_avatar.png"
|
58
|
+
# },
|
59
|
+
# "message_id": "22",
|
60
|
+
# "filename": "README.md",
|
61
|
+
# "filesize": 2232,
|
62
|
+
# "upload_time": 1384414750
|
63
|
+
# }
|
64
|
+
def find_file(room_id:, file_id:, create_download_url: nil, &block)
|
65
|
+
get("/rooms/#{room_id}/files/#{file_id}", create_download_url: boolean_to_integer(create_download_url), &block)
|
66
|
+
end
|
67
|
+
end
|