etre-client 0.8.3 → 0.8.4
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/README.md +5 -0
- data/lib/etre-client/client.rb +44 -15
- data/lib/etre-client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c0c27ca99e636fe368d12b0adcc385bb695b74e
|
4
|
+
data.tar.gz: d147ec9aebe97c2190abdf6f13c4adabb32fe2fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85745cb3cc557539c3140e4e58d5247706074e253f0f9458b5e1d78e616bc73dfc9854927c21f6abd695e274892303bfe50fad543d1ca85bd69f8d290c1b9487
|
7
|
+
data.tar.gz: b34d5b094f7aafd896dfb382572815d69794099080af88f9aeff6ab5d9900c1a7c105f5d54a61baf5471042bc09def2e81b1a8c87219124574035f68969f8250
|
data/README.md
CHANGED
@@ -102,6 +102,11 @@ Run the tests
|
|
102
102
|
bundle exec rake spec
|
103
103
|
```
|
104
104
|
|
105
|
+
Publish a new version of the gem:
|
106
|
+
1. Bump the version in lib/etre-client/version.rb
|
107
|
+
2. Build the gem with `gem build etre-client.gemspec`
|
108
|
+
3. Publish the new gem with `gem push etre-client-#{GEM_VERSION}.gem`
|
109
|
+
|
105
110
|
## License
|
106
111
|
|
107
112
|
Copyright (c) 2017 Square Inc. Distributed under the Apache 2.0 License.
|
data/lib/etre-client/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'etre-client/errors'
|
2
|
+
require 'logger'
|
2
3
|
require 'rest-client'
|
3
4
|
require 'json'
|
4
5
|
|
@@ -10,10 +11,14 @@ module Etre
|
|
10
11
|
META_LABEL_ID = "_id"
|
11
12
|
META_LABEL_TYPE = "_type"
|
12
13
|
|
13
|
-
def initialize(entity_type:, url:, options: {})
|
14
|
+
def initialize(entity_type:, url:, retry_count: 0, retry_wait: 1, options: {})
|
14
15
|
@entity_type = entity_type
|
15
16
|
@url = url
|
17
|
+
@retry_count = retry_count # retry count on network or API error
|
18
|
+
@retry_wait = retry_wait # wait time between retries
|
16
19
|
@options = options
|
20
|
+
|
21
|
+
@logger = Logger.new(STDOUT)
|
17
22
|
end
|
18
23
|
|
19
24
|
# query returns an array of entities that satisfy a query.
|
@@ -236,29 +241,37 @@ module Etre
|
|
236
241
|
private
|
237
242
|
|
238
243
|
def etre_get(route)
|
239
|
-
|
240
|
-
|
241
|
-
|
244
|
+
rest_retry {
|
245
|
+
resource_for_route(route).get(
|
246
|
+
get_headers,
|
247
|
+
)
|
248
|
+
}
|
242
249
|
end
|
243
250
|
|
244
251
|
def etre_post(route, params = nil)
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
252
|
+
rest_retry {
|
253
|
+
resource_for_route(route).post(
|
254
|
+
params.to_json,
|
255
|
+
post_headers,
|
256
|
+
)
|
257
|
+
}
|
249
258
|
end
|
250
259
|
|
251
260
|
def etre_put(route, params = nil)
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
261
|
+
rest_retry {
|
262
|
+
resource_for_route(route).put(
|
263
|
+
params.to_json,
|
264
|
+
put_headers,
|
265
|
+
)
|
266
|
+
}
|
256
267
|
end
|
257
268
|
|
258
269
|
def etre_delete(route)
|
259
|
-
|
260
|
-
|
261
|
-
|
270
|
+
rest_retry {
|
271
|
+
resource_for_route(route).delete(
|
272
|
+
delete_headers,
|
273
|
+
)
|
274
|
+
}
|
262
275
|
end
|
263
276
|
|
264
277
|
def get_headers
|
@@ -287,5 +300,21 @@ module Etre
|
|
287
300
|
def parse_response(response)
|
288
301
|
JSON.parse(response)
|
289
302
|
end
|
303
|
+
|
304
|
+
def rest_retry(&block)
|
305
|
+
retries = 0
|
306
|
+
|
307
|
+
begin
|
308
|
+
yield
|
309
|
+
rescue => e
|
310
|
+
if (retries += 1) <= @retry_count
|
311
|
+
@logger.warn("Error querying etre (#{e}). Sleeping for #{@retry_wait} seconds before trying again (attmept #{retries}/#{@retry_count}).")
|
312
|
+
sleep(@retry_wait)
|
313
|
+
retry
|
314
|
+
else
|
315
|
+
raise
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
290
319
|
end
|
291
320
|
end
|
data/lib/etre-client/version.rb
CHANGED