esa 1.12.0 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bd1ffc2820c7403537f4bb3a6297e1d10e35001
4
- data.tar.gz: 2ed3370fa2fa196c62a902c54e2dbfc2b75795ce
3
+ metadata.gz: e539e9e9dd98be681d769ee35e195c2521953f88
4
+ data.tar.gz: 00565e222da28955c9a003da10cd3c1eb32ef437
5
5
  SHA512:
6
- metadata.gz: 2d06a51e5e1d2b19e074d4eb49ab466ca87b960343e654392c465b137bcb05075c53578796179845b220fa86774072ae58158926a3d44ff257ba3f3bb2b658be
7
- data.tar.gz: f6784daa050a78c64cb46190b2e1db9a60a960d9ee2a1c80baf4b7ddddd106e464a6067bc5d1c2fbe10d86e45a139e2130435938852106f50cd6e788edc02324
6
+ metadata.gz: a591ef1455f940ef94d2bfa2cb67bffe4fc9b746d12542b325cfd62fad072689e798a49f7449f4b0e0d081d9c8438b6ca12ca0a2c2cf14c5f067e3bcde9f6243
7
+ data.tar.gz: f1dd8a14cd8313c0c8e1bb89a6633cbcb35f7a7caddf4b98e34f3a6957d85a2f02ce0c7003408248de44e0203aaa94ed33030b8dc0bf60949ab8e255ca1ae088
@@ -1,3 +1,8 @@
1
+ ## 1.13.0 (2017-11-01)
2
+ - **changed**: [Retry on rate limit exceeded by default](https://github.com/esaio/esa-ruby/pull/31)
3
+ - Use `Esa::Client.new(retry_on_rate_limit_exceeded: false, ...)` for previous behavior.
4
+ - doc: [Fixed README typo](https://github.com/esaio/esa-ruby/pull/30)
5
+
1
6
  ## 1.12.0 (2017-10-03)
2
7
  - add: [Support /api/v1/comments API by ppworks · Pull Request #29 · esaio/esa-ruby](https://github.com/esaio/esa-ruby/pull/29)
3
8
 
data/README.md CHANGED
@@ -132,7 +132,7 @@ client.batch_move_category(from: '/esa/', to: '/tori/piyo/')
132
132
  client.tags
133
133
  #=> GET /v1/teams/foobar/tags
134
134
 
135
- # Infitation API
135
+ # Invitation API
136
136
  client.invitation
137
137
  #=> GET /v1/teams/foobar/invitation
138
138
 
@@ -4,14 +4,18 @@ require "esa/response"
4
4
 
5
5
  module Esa
6
6
  class Client
7
+ class TooManyRequestError < StandardError; end
8
+
7
9
  include ApiMethods
8
10
 
9
- def initialize(access_token: nil, api_endpoint: nil, current_team: nil)
11
+ def initialize(access_token: nil, api_endpoint: nil, current_team: nil, retry_on_rate_limit_exceeded: true)
10
12
  @access_token = access_token
11
13
  @api_endpoint = api_endpoint
12
14
  @current_team = current_team
15
+
16
+ @retry_on_rate_limit_exceeded = retry_on_rate_limit_exceeded
13
17
  end
14
- attr_accessor :current_team
18
+ attr_accessor :current_team, :retry_on_rate_limit_exceeded
15
19
 
16
20
  def current_team!
17
21
  raise TeamNotSpecifiedError, "current_team is not specified" unless @current_team
@@ -39,7 +43,14 @@ module Esa
39
43
  end
40
44
 
41
45
  def send_request(method, path, params = nil, headers = nil)
42
- Esa::Response.new(esa_connection.send(method, path, params, headers))
46
+ response = esa_connection.send(method, path, params, headers)
47
+ raise TooManyRequestError if retry_on_rate_limit_exceeded && response.status == 429 # too_many_requests
48
+ Esa::Response.new(response)
49
+ rescue TooManyRequestError
50
+ wait_sec = response.headers['retry-after'].to_i
51
+ puts "Rate limit exceeded: will retry after #{wait_sec} seconds."
52
+ wait_for(wait_sec)
53
+ retry
43
54
  end
44
55
 
45
56
  def send_s3_request(method, path, params = nil, headers = nil)
@@ -101,5 +112,15 @@ module Esa
101
112
  def faraday_url
102
113
  @api_endpoint || ENV["ESA_API_ENDPOINT"] || "https://api.esa.io"
103
114
  end
115
+
116
+ def wait_for(wait_sec)
117
+ return if wait_sec <= 0
118
+
119
+ (wait_sec / 10).times do
120
+ print '.'
121
+ sleep 10
122
+ end
123
+ puts
124
+ end
104
125
  end
105
126
  end
@@ -1,3 +1,3 @@
1
1
  module Esa
2
- VERSION = '1.12.0'
2
+ VERSION = '1.13.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fukayatsu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-03 00:00:00.000000000 Z
11
+ date: 2017-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday