docbase 2.1.1 → 2.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6c70d4491502f49f4510006bcc8f630d7b207c2e33b4d40dc11cbd4749b0ae4
4
- data.tar.gz: 206860601acdc3d22e1a315c0ddce113f6b6776a309570cbe4804e7f878a0cf4
3
+ metadata.gz: 20af66cc5d5085854e9aef5f65e57383291a8f217961a4fa6cead0bb2e678941
4
+ data.tar.gz: 24cf39072ac1eaf9c4cc700f6ee2bcc694939b5c4d26427cb932aedeabf499f0
5
5
  SHA512:
6
- metadata.gz: dbe5ff0494d2605b6aacea6a1b95b417ca710e302233bce291da160cd6b311785e684a4d5492f5c2824500d9a6b0d67f1966cc1d5733dedb8283c5d88f9bf8a9
7
- data.tar.gz: a9b8d6813eb18db3599a1ad4019f9d45f29441caea3c0e5d47ee33734e7eacd8b1837e9cdffbee281c6cc726dd08e8e006d81d61c972e83607296db395ea2468
6
+ metadata.gz: 12a494552034d86ba01f68a95e30a438ed068307223d83dd23b9e92fa23f15a85dc98cee60577342696b123ec2b5153f0935d77b58a3887f810da919beb7b0f8
7
+ data.tar.gz: d5dc0fea1f5d08a13ea5df13c38c504e11a80b5a82f121ce9afe7d087cb1d4b06d48188434939bd41758a67029aacc692fd7db8466fd5db9c1f2fe6023a3ef7c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.1.2
2
+
3
+ * 利用制限時にリトライできるように
4
+
1
5
  ## 2.1.1
2
6
 
3
7
  * グループ取得APIにグループ名/ページネーションが渡せてるように fix: #17
data/README.md CHANGED
@@ -26,6 +26,16 @@ Or install it yourself as:
26
26
  client = DocBase::Client.new(access_token: 'your_access_token', team: 'your_team')
27
27
  ```
28
28
 
29
+ ### Docbase::Client.new options
30
+
31
+ * access_token
32
+ * access token
33
+ * team
34
+ * team subdomain
35
+ * retry_on_rate_limit_exceeded
36
+ * [#16](https://github.com/krayinc/docbase-ruby/issues/16)
37
+ * true or false
38
+
29
39
  ### users
30
40
 
31
41
  ```ruby
@@ -5,13 +5,15 @@ module DocBase
5
5
 
6
6
  class NotSetTeamError < StandardError; end
7
7
  class NotSetPostIdError < StandardError; end
8
+ class TooManyRequestError < StandardError; end
8
9
 
9
- attr_accessor :team, :access_token
10
+ attr_accessor :team, :access_token, :retry_on_rate_limit_exceeded
10
11
 
11
- def initialize(access_token: nil, url: nil, team: nil)
12
+ def initialize(access_token: nil, url: nil, team: nil, retry_on_rate_limit_exceeded: false)
12
13
  self.access_token = access_token
13
14
  self.team = team
14
15
  @url = url || DEFAULT_URL
16
+ self.retry_on_rate_limit_exceeded = retry_on_rate_limit_exceeded
15
17
  end
16
18
 
17
19
  def team!
@@ -20,23 +22,23 @@ module DocBase
20
22
  end
21
23
 
22
24
  def users(q: nil, page: 1, per_page: 100, include_user_groups: false)
23
- connection.get("/teams/#{team!}/users", q: q, page: page, per_page: per_page, include_user_groups: include_user_groups)
25
+ request(method: :get, path: "/teams/#{team!}/users", params: { q: q, page: page, per_page: per_page, include_user_groups: include_user_groups })
24
26
  end
25
27
 
26
28
  def tags
27
- connection.get("/teams/#{team!}/tags")
29
+ request(method: :get, path: "/teams/#{team!}/tags")
28
30
  end
29
31
 
30
32
  def groups(name: nil, page: 1, per_page: 100)
31
- connection.get("/teams/#{team!}/groups", name: name, page: page, per_page: per_page)
33
+ request(method: :get, path: "/teams/#{team!}/groups", params: { name: name, page: page, per_page: per_page })
32
34
  end
33
35
 
34
36
  def group(id)
35
- connection.get("/teams/#{team!}/groups/#{id}")
37
+ request(method: :get, path: "/teams/#{team!}/groups/#{id}")
36
38
  end
37
39
 
38
40
  def create_group(params)
39
- connection.post("/teams/#{team!}/groups", params)
41
+ request(method: :post, path: "/teams/#{team!}/groups", params: params)
40
42
  end
41
43
 
42
44
  def add_users_to_group(params)
@@ -44,7 +46,7 @@ module DocBase
44
46
  raise NotSetTeamError if group_id <= 0
45
47
 
46
48
  users_params = except(params, :group_id)
47
- connection.post("/teams/#{team!}/groups/#{group_id}/users", users_params)
49
+ request(method: :post, path: "/teams/#{team!}/groups/#{group_id}/users", params: users_params)
48
50
  end
49
51
 
50
52
  def remove_users_from_group(params)
@@ -52,19 +54,19 @@ module DocBase
52
54
  raise NotSetTeamError if group_id <= 0
53
55
 
54
56
  users_params = except(params, :group_id)
55
- connection.delete("/teams/#{team!}/groups/#{group_id}/users", users_params)
57
+ request(method: :delete, path: "/teams/#{team!}/groups/#{group_id}/users", params: users_params)
56
58
  end
57
59
 
58
60
  def post(id)
59
- connection.get("/teams/#{team!}/posts/#{id}")
61
+ request(method: :get, path: "/teams/#{team!}/posts/#{id}")
60
62
  end
61
63
 
62
64
  def posts(q: '*', page: 1, per_page: 20)
63
- connection.get("/teams/#{team!}/posts", q: q, page: page, per_page: per_page)
65
+ request(method: :get, path: "/teams/#{team!}/posts", params: { q: q, page: page, per_page: per_page })
64
66
  end
65
67
 
66
68
  def create_post(params)
67
- connection.post("/teams/#{team!}/posts", params)
69
+ request(method: :post, path: "/teams/#{team!}/posts", params: params)
68
70
  end
69
71
 
70
72
  def update_post(params)
@@ -72,19 +74,19 @@ module DocBase
72
74
  raise NotSetTeamError if post_id <= 0
73
75
 
74
76
  post_params = except(params, :id)
75
- connection.patch("/teams/#{team!}/posts/#{post_id}", post_params)
77
+ request(method: :patch, path: "/teams/#{team!}/posts/#{post_id}", params: post_params)
76
78
  end
77
79
 
78
80
  def delete_post(id)
79
- connection.delete("/teams/#{team!}/posts/#{id}")
81
+ request(method: :delete, path: "/teams/#{team!}/posts/#{id}")
80
82
  end
81
83
 
82
84
  def archive_post(id)
83
- connection.put("/teams/#{team!}/posts/#{id}/archive")
85
+ request(method: :put, path: "/teams/#{team!}/posts/#{id}/archive")
84
86
  end
85
87
 
86
88
  def unarchive_post(id)
87
- connection.put("/teams/#{team!}/posts/#{id}/unarchive")
89
+ request(method: :put, path: "/teams/#{team!}/posts/#{id}/unarchive")
88
90
  end
89
91
 
90
92
  def create_comment(params)
@@ -92,11 +94,11 @@ module DocBase
92
94
  raise NotSetTeamError if post_id <= 0
93
95
 
94
96
  comment_params = except(params, :post_id)
95
- connection.post("/teams/#{team!}/posts/#{post_id}/comments", params)
97
+ request(method: :post, path: "/teams/#{team!}/posts/#{post_id}/comments", params: params)
96
98
  end
97
99
 
98
100
  def delete_comment(id)
99
- connection.delete("/teams/#{team!}/comments/#{id}")
101
+ request(method: :delete, path: "/teams/#{team!}/comments/#{id}")
100
102
  end
101
103
 
102
104
  def upload(paths)
@@ -110,11 +112,11 @@ module DocBase
110
112
  }
111
113
  end
112
114
 
113
- connection.post("/teams/#{team!}/attachments", params)
115
+ request(method: :post, path: "/teams/#{team!}/attachments", params: params)
114
116
  end
115
117
 
116
118
  def attachment(id)
117
- connection_for_binary.get("/teams/#{team!}/attachments/#{id}")
119
+ request(method: :get, path: "/teams/#{team!}/attachments/#{id}", for_binary: true)
118
120
  end
119
121
 
120
122
  private
@@ -146,5 +148,22 @@ module DocBase
146
148
  'X-Api-Version' => '2',
147
149
  }
148
150
  end
151
+
152
+ def request(method:, path:, params: nil, for_binary: false)
153
+ response = for_binary ? connection_for_binary.send(method, path, params) : connection.send(method, path, params)
154
+ raise TooManyRequestError if retry_on_rate_limit_exceeded && response.status == 429
155
+ response
156
+ rescue TooManyRequestError
157
+ reset_time = response.headers['x-ratelimit-reset'].to_i
158
+ puts "DocBase API Rate limit exceeded: will retry at #{Time.at(reset_time).strftime("%Y/%m/%d %H:%M:%S")}."
159
+ wait_for(reset_time)
160
+ retry
161
+ end
162
+
163
+ def wait_for(reset_time)
164
+ wait_time = reset_time - Time.now.to_i
165
+ return if wait_time <= 0
166
+ sleep wait_time
167
+ end
149
168
  end
150
169
  end
@@ -1,3 +1,3 @@
1
1
  module DocBase
2
- VERSION = '2.1.1'
2
+ VERSION = '2.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ttakuru88
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-30 00:00:00.000000000 Z
11
+ date: 2021-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.2.3
82
+ rubygems_version: 3.1.4
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: DocBase API Client, written in Ruby