contentful-management 1.2.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1844d46d629774fbe7c768093c7231e16398315a
4
- data.tar.gz: a0d6f81a64b1476ded7a6b7b84733da67587f6f0
3
+ metadata.gz: 0b787e1a5b3f2fe80bbc12f9038fd772c01e8df6
4
+ data.tar.gz: 235ebb4b563abeafe6509dc2fbffb72ccd6e0005
5
5
  SHA512:
6
- metadata.gz: 476e62803a1c5c19e19eec87a980cd7e31ea195b432a4e8c2c36bb403cb978632bb8d20fc4e231888456570b76677ab46af1c35792b668cc74040c49208cdb8a
7
- data.tar.gz: 4c5c1d5f4f053284c28c250da4fe08dd3ee6d03665380007df353d90c64c641ea0e2afc4b19478952fa38153b41ecff81059360efa04333b3029864c862d7ed5
6
+ metadata.gz: 980359feab17c1e33be85f684a3a17191dacc9038da4e6186c848ef9c398ba9123895bb5015d784900b3ae2c0f76d92f06406e85120cc9e9a27435e0dd920646
7
+ data.tar.gz: 8199a7f8698c2ff4201a9e7c82f1becd9e032f6087321a214ec1f158fd29d29282eed49afbd37fd782dd8189946788a66819461b4e1a7a008219414ba1982aad
data/.rubocop_todo.yml CHANGED
@@ -1,24 +1,24 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-02-01 08:50:00 -0300 using RuboCop version 0.34.2.
3
+ # on 2016-08-25 10:16:28 -0300 using RuboCop version 0.35.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 16
9
+ # Offense count: 12
10
10
  Metrics/AbcSize:
11
- Max: 50
11
+ Max: 41
12
12
 
13
13
  # Offense count: 4
14
14
  Metrics/CyclomaticComplexity:
15
15
  Max: 10
16
16
 
17
- # Offense count: 21
17
+ # Offense count: 18
18
18
  # Configuration parameters: CountComments.
19
19
  Metrics/MethodLength:
20
- Max: 48
20
+ Max: 24
21
21
 
22
22
  # Offense count: 2
23
23
  Metrics/PerceivedComplexity:
24
- Max: 8
24
+ Max: 9
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 1.3.0
6
+ ### Added
7
+ * Added Rate Limit automatic handling
8
+
5
9
  ## 1.2.0
6
10
  ### Added
7
11
  * Add support for `::Contentful::Entry` and `::Contentful::Asset` serialization when using the CDA SDK along side this client [#105](https://github.com/contentful/contentful-management.rb/pull/105)
data/README.md CHANGED
@@ -734,6 +734,22 @@ client = Contributing::Management::Client.new(
734
734
  )
735
735
  ```
736
736
 
737
+ # Rate Limit Management
738
+
739
+ With the following configuration options you can handle how rate limits are handled within your applications.
740
+
741
+ ## :max_rate_limit_retries
742
+
743
+ To increase or decrease the retry attempts after a 429 Rate Limit error. Default value is 1. Using 0 will disable retry behaviour.
744
+ Each retry will be attempted after the value (in seconds) of the `X-Contentful-RateLimit-Reset` header, which contains the amount of seconds until the next
745
+ non rate limited request is available, has passed. This is blocking per execution thread.
746
+
747
+ ## :max_rate_limit_wait
748
+
749
+ Maximum time to wait for next available request (in seconds). Default value is 60 seconds. Keep in mind that if you hit the houly rate limit maximum, you
750
+ can have up to 60 minutes of blocked requests. It is set to a default of 60 seconds in order to avoid blocking processes for too long, as rate limit retry behaviour
751
+ is blocking per execution thread.
752
+
737
753
  ## Contributing
738
754
 
739
755
  1. Fork it ( https://github.com/[my-github-username]/contentful-management/fork )
@@ -44,8 +44,12 @@ module Contentful
44
44
  proxy_host: nil,
45
45
  proxy_port: nil,
46
46
  proxy_username: nil,
47
- proxy_password: nil
47
+ proxy_password: nil,
48
+ max_rate_limit_retries: 1,
49
+ max_rate_limit_wait: 60
48
50
  }
51
+ # Rate Limit Reset Header Key
52
+ RATE_LIMIT_RESET_HEADER_KEY = 'x-contentful-ratelimit-reset'
49
53
 
50
54
  # @param [String] access_token
51
55
  # @param [Hash] configuration
@@ -208,17 +212,40 @@ module Contentful
208
212
 
209
213
  # @private
210
214
  def execute_request(request)
215
+ retries_left = configuration[:max_rate_limit_retries]
211
216
  request_url = request.url
212
217
  url = request.absolute? ? request_url : base_url + request_url
213
- logger.info(request: { url: url, query: request.query, header: request_headers }) if logger
214
- raw_response = yield(url)
215
- logger.debug(response: raw_response) if logger
216
- clear_headers
217
- result = Response.new(raw_response, request)
218
- fail result.object if result.object.is_a?(Error) && configuration[:raise_errors]
218
+
219
+ begin
220
+ logger.info(request: { url: url, query: request.query, header: request_headers }) if logger
221
+ raw_response = yield(url)
222
+ logger.debug(response: raw_response) if logger
223
+ clear_headers
224
+ result = Response.new(raw_response, request)
225
+ fail result.object if result.object.is_a?(Error) && configuration[:raise_errors]
226
+ rescue Contentful::Management::RateLimitExceeded => rate_limit_error
227
+ reset_time = rate_limit_error.response.raw[RATE_LIMIT_RESET_HEADER_KEY].to_i
228
+ if should_retry(retries_left, reset_time, configuration[:max_rate_limit_wait])
229
+ retries_left -= 1
230
+ retry_message = 'Contentful Management API Rate Limit Hit! '
231
+ retry_message += "Retrying - Retries left: #{retries_left}"
232
+ retry_message += "- Time until reset (seconds): #{reset_time}"
233
+ logger.info(retry_message) if logger
234
+ sleep(reset_time * Random.new.rand(1.0..1.2))
235
+ retry
236
+ end
237
+
238
+ raise
239
+ end
240
+
219
241
  result
220
242
  end
221
243
 
244
+ # @private
245
+ def should_retry(retries_left, reset_time, max_wait)
246
+ retries_left > 0 && max_wait > reset_time
247
+ end
248
+
222
249
  # @private
223
250
  def clear_headers
224
251
  self.content_type_id = nil
@@ -3,6 +3,6 @@ module Contentful
3
3
  # Management Namespace
4
4
  module Management
5
5
  # Gem Version
6
- VERSION = '1.2.0'
6
+ VERSION = '1.3.0'
7
7
  end
8
8
  end
@@ -0,0 +1,840 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/286arvy86ry9
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContentfulManagementGem/0.5.0
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Content-Length:
17
+ - '0'
18
+ Host:
19
+ - api.contentful.com
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Accept-Ranges:
26
+ - bytes
27
+ Access-Control-Allow-Headers:
28
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation
29
+ Access-Control-Allow-Methods:
30
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Expose-Headers:
34
+ - Etag
35
+ Access-Control-Max-Age:
36
+ - '1728000'
37
+ Cache-Control:
38
+ - max-age=0
39
+ Content-Type:
40
+ - application/vnd.contentful.management.v1+json
41
+ Date:
42
+ - Thu, 18 Dec 2014 12:21:23 GMT
43
+ Etag:
44
+ - '"91d2291b87bce2aa62bc5aeadb61793a"'
45
+ Server:
46
+ - nginx
47
+ Status:
48
+ - 200 OK
49
+ X-Contentful-Request-Id:
50
+ - f1c-653450314
51
+ Content-Length:
52
+ - '453'
53
+ Connection:
54
+ - keep-alive
55
+ body:
56
+ encoding: UTF-8
57
+ string: |
58
+ {
59
+ "sys":{
60
+ "type":"Space",
61
+ "id":"286arvy86ry9",
62
+ "version":1,
63
+ "createdBy":{
64
+ "sys":{
65
+ "type":"Link",
66
+ "linkType":"User",
67
+ "id":"1E7acJL8I5XUXAMHQt9Grs"
68
+ }
69
+ },
70
+ "createdAt":"2014-12-15T08:12:42Z",
71
+ "updatedBy":{
72
+ "sys":{
73
+ "type":"Link",
74
+ "linkType":"User",
75
+ "id":"1E7acJL8I5XUXAMHQt9Grs"
76
+ }
77
+ },
78
+ "updatedAt":"2014-12-15T08:12:42Z"
79
+ },
80
+ "name":"TestingRspec"}
81
+ http_version:
82
+ recorded_at: Thu, 18 Dec 2014 12:21:23 GMT
83
+ - request:
84
+ method: get
85
+ uri: https://api.contentful.com/spaces/286arvy86ry9/content_types
86
+ body:
87
+ encoding: US-ASCII
88
+ string: ''
89
+ headers:
90
+ User-Agent:
91
+ - RubyContentfulManagementGem/0.5.0
92
+ Authorization:
93
+ - Bearer <ACCESS_TOKEN>
94
+ Content-Type:
95
+ - application/vnd.contentful.management.v1+json
96
+ Content-Length:
97
+ - '0'
98
+ Host:
99
+ - api.contentful.com
100
+ response:
101
+ status:
102
+ code: 200
103
+ message: OK
104
+ headers:
105
+ Access-Control-Allow-Headers:
106
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation
107
+ Access-Control-Allow-Methods:
108
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
109
+ Access-Control-Allow-Origin:
110
+ - "*"
111
+ Access-Control-Expose-Headers:
112
+ - Etag
113
+ Access-Control-Max-Age:
114
+ - '1728000'
115
+ Cf-Space-Id:
116
+ - 286arvy86ry9
117
+ Content-Type:
118
+ - application/vnd.contentful.management.v1+json
119
+ Date:
120
+ - Thu, 18 Dec 2014 12:21:23 GMT
121
+ Etag:
122
+ - '"0042a1083a298261f6f010e5e28a8f1f"'
123
+ Server:
124
+ - nginx
125
+ X-Powered-By:
126
+ - Express
127
+ Content-Length:
128
+ - '4644'
129
+ Connection:
130
+ - keep-alive
131
+ body:
132
+ encoding: UTF-8
133
+ string: |
134
+ {
135
+ "sys": {
136
+ "type": "Array"
137
+ },
138
+ "total": 3,
139
+ "skip": 0,
140
+ "limit": 100,
141
+ "items": [
142
+ {
143
+ "fields": [
144
+ {
145
+ "name": "text",
146
+ "id": "text",
147
+ "type": "Text"
148
+ },
149
+ {
150
+ "name": "number2",
151
+ "id": "number2",
152
+ "type": "Integer"
153
+ },
154
+ {
155
+ "name": "entry2",
156
+ "id": "entry2",
157
+ "type": "Link",
158
+ "linkType": "Entry"
159
+ }
160
+ ],
161
+ "name": "Test2",
162
+ "sys": {
163
+ "id": "4dsDWisVl6WAAYuk60E4QC",
164
+ "type": "ContentType",
165
+ "createdAt": "2014-12-15T08:13:47.342Z",
166
+ "createdBy": {
167
+ "sys": {
168
+ "type": "Link",
169
+ "linkType": "User",
170
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
171
+ }
172
+ },
173
+ "space": {
174
+ "sys": {
175
+ "type": "Link",
176
+ "linkType": "Space",
177
+ "id": "286arvy86ry9"
178
+ }
179
+ },
180
+ "firstPublishedAt": "2014-12-15T08:14:20.807Z",
181
+ "publishedCounter": 1,
182
+ "publishedAt": "2014-12-15T08:14:20.807Z",
183
+ "publishedBy": {
184
+ "sys": {
185
+ "type": "Link",
186
+ "linkType": "User",
187
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
188
+ }
189
+ },
190
+ "publishedVersion": 39,
191
+ "version": 40,
192
+ "updatedAt": "2014-12-15T08:14:20.852Z",
193
+ "updatedBy": {
194
+ "sys": {
195
+ "type": "Link",
196
+ "linkType": "User",
197
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
198
+ }
199
+ }
200
+ },
201
+ "description": "test",
202
+ "displayField": "text"
203
+ },
204
+ {
205
+ "fields": [
206
+ {
207
+ "name": "name",
208
+ "id": "name",
209
+ "type": "Text"
210
+ },
211
+ {
212
+ "name": "number",
213
+ "id": "number",
214
+ "type": "Integer"
215
+ },
216
+ {
217
+ "name": "entry",
218
+ "id": "entry",
219
+ "type": "Link",
220
+ "linkType": "Entry",
221
+ "validations": [
222
+ {
223
+ "linkContentType": [
224
+ "4dsDWisVl6WAAYuk60E4QC"
225
+ ]
226
+ }
227
+ ]
228
+ }
229
+ ],
230
+ "name": "Test1",
231
+ "sys": {
232
+ "id": "5lIEiXrCIoKoIKaSW2C8aa",
233
+ "type": "ContentType",
234
+ "createdAt": "2014-12-15T08:13:15.767Z",
235
+ "createdBy": {
236
+ "sys": {
237
+ "type": "Link",
238
+ "linkType": "User",
239
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
240
+ }
241
+ },
242
+ "space": {
243
+ "sys": {
244
+ "type": "Link",
245
+ "linkType": "Space",
246
+ "id": "286arvy86ry9"
247
+ }
248
+ },
249
+ "firstPublishedAt": "2014-12-15T08:13:43.070Z",
250
+ "publishedCounter": 2,
251
+ "publishedAt": "2014-12-18T12:02:02.366Z",
252
+ "publishedBy": {
253
+ "sys": {
254
+ "type": "Link",
255
+ "linkType": "User",
256
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
257
+ }
258
+ },
259
+ "publishedVersion": 30,
260
+ "version": 31,
261
+ "updatedAt": "2014-12-18T12:02:02.409Z",
262
+ "updatedBy": {
263
+ "sys": {
264
+ "type": "Link",
265
+ "linkType": "User",
266
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
267
+ }
268
+ }
269
+ },
270
+ "description": "test1",
271
+ "displayField": "name"
272
+ },
273
+ {
274
+ "fields": [
275
+ {
276
+ "name": "name",
277
+ "id": "name",
278
+ "type": "Text",
279
+ "validations": [
280
+ {
281
+ "size": {
282
+ "min": 1,
283
+ "max": 2
284
+ }
285
+ }
286
+ ]
287
+ }
288
+ ],
289
+ "name": "Test3",
290
+ "sys": {
291
+ "id": "2PqKsSmwKASkM6sWiqMuqi",
292
+ "type": "ContentType",
293
+ "createdAt": "2014-12-18T12:01:49.830Z",
294
+ "createdBy": {
295
+ "sys": {
296
+ "type": "Link",
297
+ "linkType": "User",
298
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
299
+ }
300
+ },
301
+ "space": {
302
+ "sys": {
303
+ "type": "Link",
304
+ "linkType": "Space",
305
+ "id": "286arvy86ry9"
306
+ }
307
+ },
308
+ "firstPublishedAt": "2014-12-18T12:01:59.077Z",
309
+ "publishedCounter": 2,
310
+ "publishedAt": "2014-12-18T12:16:31.529Z",
311
+ "publishedBy": {
312
+ "sys": {
313
+ "type": "Link",
314
+ "linkType": "User",
315
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
316
+ }
317
+ },
318
+ "publishedVersion": 14,
319
+ "version": 15,
320
+ "updatedAt": "2014-12-18T12:16:31.576Z",
321
+ "updatedBy": {
322
+ "sys": {
323
+ "type": "Link",
324
+ "linkType": "User",
325
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
326
+ }
327
+ }
328
+ },
329
+ "displayField": "name"
330
+ }
331
+ ]
332
+ }
333
+ http_version:
334
+ recorded_at: Thu, 18 Dec 2014 12:21:23 GMT
335
+ - request:
336
+ method: get
337
+ uri: https://api.contentful.com/spaces/286arvy86ry9/entries/1YNepnMpXGiMWikaKC4GG0
338
+ body:
339
+ encoding: US-ASCII
340
+ string: ''
341
+ headers:
342
+ User-Agent:
343
+ - RubyContentfulManagementGem/0.5.0
344
+ Authorization:
345
+ - Bearer <ACCESS_TOKEN>
346
+ Content-Type:
347
+ - application/vnd.contentful.management.v1+json
348
+ Content-Length:
349
+ - '0'
350
+ Host:
351
+ - api.contentful.com
352
+ response:
353
+ status:
354
+ code: 200
355
+ message: OK
356
+ headers:
357
+ Access-Control-Allow-Headers:
358
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation
359
+ Access-Control-Allow-Methods:
360
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
361
+ Access-Control-Allow-Origin:
362
+ - "*"
363
+ Access-Control-Expose-Headers:
364
+ - Etag
365
+ Access-Control-Max-Age:
366
+ - '1728000'
367
+ Cf-Space-Id:
368
+ - 286arvy86ry9
369
+ Content-Type:
370
+ - application/vnd.contentful.management.v1+json
371
+ Date:
372
+ - Thu, 18 Dec 2014 12:21:24 GMT
373
+ Etag:
374
+ - '"9458b849a96cdf2ff9d50bffce2300ee"'
375
+ Server:
376
+ - nginx
377
+ X-Powered-By:
378
+ - Express
379
+ Content-Length:
380
+ - '1105'
381
+ Connection:
382
+ - keep-alive
383
+ body:
384
+ encoding: UTF-8
385
+ string: |
386
+ {
387
+ "sys": {
388
+ "id": "1YNepnMpXGiMWikaKC4GG0",
389
+ "type": "Entry",
390
+ "createdAt": "2014-12-18T12:02:39.207Z",
391
+ "createdBy": {
392
+ "sys": {
393
+ "type": "Link",
394
+ "linkType": "User",
395
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
396
+ }
397
+ },
398
+ "space": {
399
+ "sys": {
400
+ "type": "Link",
401
+ "linkType": "Space",
402
+ "id": "286arvy86ry9"
403
+ }
404
+ },
405
+ "contentType": {
406
+ "sys": {
407
+ "type": "Link",
408
+ "linkType": "ContentType",
409
+ "id": "2PqKsSmwKASkM6sWiqMuqi"
410
+ }
411
+ },
412
+ "firstPublishedAt": "2014-12-18T12:02:49.757Z",
413
+ "publishedCounter": 1,
414
+ "publishedAt": "2014-12-18T12:02:49.757Z",
415
+ "publishedBy": {
416
+ "sys": {
417
+ "type": "Link",
418
+ "linkType": "User",
419
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
420
+ }
421
+ },
422
+ "publishedVersion": 18,
423
+ "version": 19,
424
+ "updatedAt": "2014-12-18T12:02:49.806Z",
425
+ "updatedBy": {
426
+ "sys": {
427
+ "type": "Link",
428
+ "linkType": "User",
429
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
430
+ }
431
+ }
432
+ },
433
+ "fields": {
434
+ "name": {
435
+ "en-US": "Entry Test 3"
436
+ }
437
+ }
438
+ }
439
+ http_version:
440
+ recorded_at: Thu, 18 Dec 2014 12:21:24 GMT
441
+ - request:
442
+ method: get
443
+ uri: https://api.contentful.com/spaces/286arvy86ry9/content_types/5lIEiXrCIoKoIKaSW2C8aa
444
+ body:
445
+ encoding: US-ASCII
446
+ string: ''
447
+ headers:
448
+ User-Agent:
449
+ - RubyContentfulManagementGem/0.5.0
450
+ Authorization:
451
+ - Bearer <ACCESS_TOKEN>
452
+ Content-Type:
453
+ - application/vnd.contentful.management.v1+json
454
+ Content-Length:
455
+ - '0'
456
+ Host:
457
+ - api.contentful.com
458
+ response:
459
+ status:
460
+ code: 200
461
+ message: OK
462
+ headers:
463
+ Access-Control-Allow-Headers:
464
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation
465
+ Access-Control-Allow-Methods:
466
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
467
+ Access-Control-Allow-Origin:
468
+ - "*"
469
+ Access-Control-Expose-Headers:
470
+ - Etag
471
+ Access-Control-Max-Age:
472
+ - '1728000'
473
+ Cf-Space-Id:
474
+ - 286arvy86ry9
475
+ Content-Type:
476
+ - application/vnd.contentful.management.v1+json
477
+ Date:
478
+ - Thu, 18 Dec 2014 12:21:24 GMT
479
+ Etag:
480
+ - '"bf0d1213c4389c275fe7d30e0e84631a"'
481
+ Server:
482
+ - nginx
483
+ X-Powered-By:
484
+ - Express
485
+ Content-Length:
486
+ - '1378'
487
+ Connection:
488
+ - keep-alive
489
+ body:
490
+ encoding: UTF-8
491
+ string: |
492
+ {
493
+ "fields": [
494
+ {
495
+ "name": "name",
496
+ "id": "name",
497
+ "type": "Text"
498
+ },
499
+ {
500
+ "name": "number",
501
+ "id": "number",
502
+ "type": "Integer"
503
+ },
504
+ {
505
+ "name": "entry",
506
+ "id": "entry",
507
+ "type": "Link",
508
+ "linkType": "Entry",
509
+ "validations": [
510
+ {
511
+ "linkContentType": [
512
+ "4dsDWisVl6WAAYuk60E4QC"
513
+ ]
514
+ }
515
+ ]
516
+ }
517
+ ],
518
+ "name": "Test1",
519
+ "sys": {
520
+ "id": "5lIEiXrCIoKoIKaSW2C8aa",
521
+ "type": "ContentType",
522
+ "createdAt": "2014-12-15T08:13:15.767Z",
523
+ "createdBy": {
524
+ "sys": {
525
+ "type": "Link",
526
+ "linkType": "User",
527
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
528
+ }
529
+ },
530
+ "space": {
531
+ "sys": {
532
+ "type": "Link",
533
+ "linkType": "Space",
534
+ "id": "286arvy86ry9"
535
+ }
536
+ },
537
+ "firstPublishedAt": "2014-12-15T08:13:43.070Z",
538
+ "publishedCounter": 2,
539
+ "publishedAt": "2014-12-18T12:02:02.366Z",
540
+ "publishedBy": {
541
+ "sys": {
542
+ "type": "Link",
543
+ "linkType": "User",
544
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
545
+ }
546
+ },
547
+ "publishedVersion": 30,
548
+ "version": 31,
549
+ "updatedAt": "2014-12-18T12:02:02.409Z",
550
+ "updatedBy": {
551
+ "sys": {
552
+ "type": "Link",
553
+ "linkType": "User",
554
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
555
+ }
556
+ }
557
+ },
558
+ "description": "test1",
559
+ "displayField": "name"
560
+ }
561
+ http_version:
562
+ recorded_at: Thu, 18 Dec 2014 12:21:25 GMT
563
+ - request:
564
+ method: post
565
+ uri: https://api.contentful.com/spaces/286arvy86ry9/entries
566
+ body:
567
+ encoding: UTF-8
568
+ string: '{"fields":{"name":{"en-US":"Create test"},"entry":{"en-US":{"sys":{"type":"Link","linkType":"Entry","id":"1YNepnMpXGiMWikaKC4GG0"}}}}}'
569
+ headers:
570
+ User-Agent:
571
+ - RubyContentfulManagementGem/0.5.0
572
+ Authorization:
573
+ - Bearer <ACCESS_TOKEN>
574
+ Content-Type:
575
+ - application/vnd.contentful.management.v1+json
576
+ X-Contentful-Content-Type:
577
+ - 5lIEiXrCIoKoIKaSW2C8aa
578
+ Host:
579
+ - api.contentful.com
580
+ response:
581
+ status:
582
+ code: 201
583
+ message: Created
584
+ headers:
585
+ Access-Control-Allow-Headers:
586
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation
587
+ Access-Control-Allow-Methods:
588
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
589
+ Access-Control-Allow-Origin:
590
+ - "*"
591
+ Access-Control-Expose-Headers:
592
+ - Etag
593
+ Access-Control-Max-Age:
594
+ - '1728000'
595
+ Cf-Space-Id:
596
+ - 286arvy86ry9
597
+ Content-Type:
598
+ - application/vnd.contentful.management.v1+json
599
+ Date:
600
+ - Thu, 18 Dec 2014 12:21:26 GMT
601
+ Etag:
602
+ - '"50fcfbbef32b283c8528932f23a158ec"'
603
+ Server:
604
+ - nginx
605
+ X-Powered-By:
606
+ - Express
607
+ Content-Length:
608
+ - '979'
609
+ Connection:
610
+ - keep-alive
611
+ body:
612
+ encoding: UTF-8
613
+ string: |
614
+ {
615
+ "fields": {
616
+ "name": {
617
+ "en-US": "Create test"
618
+ },
619
+ "entry": {
620
+ "en-US": {
621
+ "sys": {
622
+ "type": "Link",
623
+ "linkType": "Entry",
624
+ "id": "1YNepnMpXGiMWikaKC4GG0"
625
+ }
626
+ }
627
+ }
628
+ },
629
+ "sys": {
630
+ "id": "7cMVEy1toAWaMKUYsSAmC4",
631
+ "type": "Entry",
632
+ "version": 1,
633
+ "createdAt": "2014-12-18T12:21:26.306Z",
634
+ "createdBy": {
635
+ "sys": {
636
+ "type": "Link",
637
+ "linkType": "User",
638
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
639
+ }
640
+ },
641
+ "space": {
642
+ "sys": {
643
+ "type": "Link",
644
+ "linkType": "Space",
645
+ "id": "286arvy86ry9"
646
+ }
647
+ },
648
+ "contentType": {
649
+ "sys": {
650
+ "type": "Link",
651
+ "linkType": "ContentType",
652
+ "id": "5lIEiXrCIoKoIKaSW2C8aa"
653
+ }
654
+ },
655
+ "updatedAt": "2014-12-18T12:21:26.306Z",
656
+ "updatedBy": {
657
+ "sys": {
658
+ "type": "Link",
659
+ "linkType": "User",
660
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
661
+ }
662
+ }
663
+ }
664
+ }
665
+ http_version:
666
+ recorded_at: Thu, 18 Dec 2014 12:21:26 GMT
667
+ - request:
668
+ method: put
669
+ uri: https://api.contentful.com/spaces/286arvy86ry9/entries/7cMVEy1toAWaMKUYsSAmC4/published
670
+ body:
671
+ encoding: US-ASCII
672
+ string: ''
673
+ headers:
674
+ User-Agent:
675
+ - RubyContentfulManagementGem/0.5.0
676
+ Authorization:
677
+ - Bearer <ACCESS_TOKEN>
678
+ Content-Type:
679
+ - application/vnd.contentful.management.v1+json
680
+ X-Contentful-Version:
681
+ - '1'
682
+ Content-Length:
683
+ - '0'
684
+ Host:
685
+ - api.contentful.com
686
+ response:
687
+ status:
688
+ code: 429
689
+ message: Rate Limit Exceeded
690
+ headers:
691
+ Access-Control-Allow-Headers:
692
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation
693
+ Access-Control-Allow-Methods:
694
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
695
+ Access-Control-Allow-Origin:
696
+ - "*"
697
+ Access-Control-Expose-Headers:
698
+ - Etag
699
+ Access-Control-Max-Age:
700
+ - '1728000'
701
+ Content-Type:
702
+ - application/vnd.contentful.management.v1+json
703
+ Date:
704
+ - Thu, 18 Dec 2014 12:21:27 GMT
705
+ Server:
706
+ - nginx
707
+ X-Powered-By:
708
+ - Express
709
+ Content-Length:
710
+ - '609'
711
+ Connection:
712
+ - keep-alive
713
+ body:
714
+ encoding: UTF-8
715
+ string: |
716
+ {
717
+ "sys": {
718
+ "type": "Error",
719
+ "id": "RateLimitExceeded"
720
+ },
721
+ "message": "You have exceeded the rate limit of the Organization this Space belongs to by making too many API requests within a short timespan. Please wait a moment before trying the request again.",
722
+ "details": {
723
+ "errors": [
724
+ {
725
+ "details": "You have exceeded the rate limit of the Organization this Space belongs to by making too many API requests within a short timespan. Please wait a moment before trying the request again."
726
+ }
727
+ ]
728
+ }
729
+ }
730
+ http_version:
731
+ recorded_at: Thu, 18 Dec 2014 12:21:27 GMT
732
+ - request:
733
+ method: put
734
+ uri: https://api.contentful.com/spaces/286arvy86ry9/entries/7cMVEy1toAWaMKUYsSAmC4/published
735
+ body:
736
+ encoding: US-ASCII
737
+ string: ''
738
+ headers:
739
+ User-Agent:
740
+ - RubyContenfulManagementGem/0.0.1
741
+ Authorization:
742
+ - Bearer <ACCESS_TOKEN>
743
+ Content-Type:
744
+ - application/vnd.contentful.management.v1+json
745
+ X-Contentful-Version:
746
+ - '30'
747
+ Content-Length:
748
+ - '0'
749
+ Host:
750
+ - api.contentful.com
751
+ response:
752
+ status:
753
+ code: 200
754
+ message: OK
755
+ headers:
756
+ Server:
757
+ - nginx
758
+ Date:
759
+ - Wed, 30 Jul 2014 12:49:32 GMT
760
+ Content-Type:
761
+ - application/vnd.contentful.management.v1+json
762
+ Content-Length:
763
+ - '1449'
764
+ Connection:
765
+ - keep-alive
766
+ X-Powered-By:
767
+ - Express
768
+ Cf-Space-Id:
769
+ - yr5m0jky5hsh
770
+ Etag:
771
+ - '"6cbe0348b4d246662423a4d2a905ede2"'
772
+ Access-Control-Allow-Origin:
773
+ - "*"
774
+ Access-Control-Allow-Headers:
775
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization
776
+ Access-Control-Allow-Methods:
777
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
778
+ "^access-Control-Expose-Headers":
779
+ - Etag
780
+ Access-Control-Max-Age:
781
+ - '1728000'
782
+ body:
783
+ encoding: UTF-8
784
+ string: |
785
+ {
786
+ "sys": {
787
+ "id": "1YNepnMpXGiMWikaKC4GG0",
788
+ "type": "Entry",
789
+ "createdAt": "2014-12-18T12:02:39.207Z",
790
+ "createdBy": {
791
+ "sys": {
792
+ "type": "Link",
793
+ "linkType": "User",
794
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
795
+ }
796
+ },
797
+ "space": {
798
+ "sys": {
799
+ "type": "Link",
800
+ "linkType": "Space",
801
+ "id": "286arvy86ry9"
802
+ }
803
+ },
804
+ "contentType": {
805
+ "sys": {
806
+ "type": "Link",
807
+ "linkType": "ContentType",
808
+ "id": "2PqKsSmwKASkM6sWiqMuqi"
809
+ }
810
+ },
811
+ "firstPublishedAt": "2014-12-18T12:02:49.757Z",
812
+ "publishedCounter": 1,
813
+ "publishedAt": "2014-12-18T12:02:49.757Z",
814
+ "publishedBy": {
815
+ "sys": {
816
+ "type": "Link",
817
+ "linkType": "User",
818
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
819
+ }
820
+ },
821
+ "publishedVersion": 18,
822
+ "version": 19,
823
+ "updatedAt": "2014-12-18T12:02:49.806Z",
824
+ "updatedBy": {
825
+ "sys": {
826
+ "type": "Link",
827
+ "linkType": "User",
828
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
829
+ }
830
+ }
831
+ },
832
+ "fields": {
833
+ "name": {
834
+ "en-US": "Entry Test 3"
835
+ }
836
+ }
837
+ }
838
+ http_version:
839
+ recorded_at: Wed, 30 Jul 2014 12:49:32 GMT
840
+ recorded_with: VCR 2.9.2
@@ -2,6 +2,19 @@ require 'spec_helper'
2
2
  require 'contentful/management/space'
3
3
  require 'contentful/management/client'
4
4
 
5
+ class RetryLoggerMock < Logger
6
+ attr_reader :retry_attempts
7
+
8
+ def initialize(*)
9
+ super
10
+ @retry_attempts = 0
11
+ end
12
+
13
+ def info(message)
14
+ @retry_attempts += 1 if message.include?('Contentful Management API Rate Limit Hit! Retrying')
15
+ end
16
+ end
17
+
5
18
  module Contentful
6
19
  module Management
7
20
  describe Entry do
@@ -253,9 +266,9 @@ module Contentful
253
266
  it 'create with all attributes' do
254
267
  vcr('entry/create') do
255
268
  content_type = client.content_types.find('ene4qtp2sh7u', '5BHZB1vi4ooq4wKcmA8e2c')
256
- location = Location.new.tap do |location|
257
- location.lat = 22.44
258
- location.lon = 33.33
269
+ location = Location.new.tap do |loc|
270
+ loc.lat = 22.44
271
+ loc.lon = 33.33
259
272
  end
260
273
  file = client.assets.find('ene4qtp2sh7u', '2oNoT3vSAs82SOIQmKe0KG')
261
274
  entry_att = subject.find('ene4qtp2sh7u', '60zYC7nY9GcKGiCYwAs4wm')
@@ -411,6 +424,19 @@ module Contentful
411
424
  end
412
425
  end
413
426
 
427
+ it 'too many requests auto-retry' do
428
+ vcr('entry/too_many_requests_retry') do
429
+ logger = RetryLoggerMock.new(STDOUT)
430
+ space = Client.new(token, raise_errors: true, logger: logger).spaces.find('286arvy86ry9')
431
+ invalid_entry = space.entries.find('1YNepnMpXGiMWikaKC4GG0')
432
+ ct = space.content_types.find('5lIEiXrCIoKoIKaSW2C8aa')
433
+ entry = ct.entries.create(name: 'Create test', entry: invalid_entry)
434
+ entry.publish
435
+
436
+ expect(logger.retry_attempts).to eq 1
437
+ end
438
+ end
439
+
414
440
  it 'with just an id' do
415
441
  vcr('entry/create_with_just_id') do
416
442
  space = client.spaces.find('bbukbffokvih')
@@ -735,9 +761,9 @@ module Contentful
735
761
 
736
762
  it 'parses all kind of fields' do
737
763
 
738
- location = Location.new.tap do |location|
739
- location.lat = 22.44
740
- location.lon = 33.33
764
+ location = Location.new.tap do |loc|
765
+ loc.lat = 22.44
766
+ loc.lon = 33.33
741
767
  end
742
768
 
743
769
  attributes = {
data/spec/spec_helper.rb CHANGED
@@ -7,3 +7,8 @@ require 'pry'
7
7
  require 'rspec/its'
8
8
 
9
9
  Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
10
+
11
+ RSpec.configure do |config|
12
+ config.filter_run :focus => true
13
+ config.run_all_when_everything_filtered = true
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful-management
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Protas
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-08-17 00:00:00.000000000 Z
13
+ date: 2016-09-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http
@@ -444,6 +444,7 @@ files:
444
444
  - spec/fixtures/vcr_cassettes/entry/search_filter/reverse_order_sys_updatedAt.yml
445
445
  - spec/fixtures/vcr_cassettes/entry/service_unavailable.yml
446
446
  - spec/fixtures/vcr_cassettes/entry/too_many_requests.yml
447
+ - spec/fixtures/vcr_cassettes/entry/too_many_requests_retry.yml
447
448
  - spec/fixtures/vcr_cassettes/entry/unarchive.yml
448
449
  - spec/fixtures/vcr_cassettes/entry/unarchive_already_unarchived.yml
449
450
  - spec/fixtures/vcr_cassettes/entry/unpublish.yml
@@ -562,7 +563,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
562
563
  version: '0'
563
564
  requirements: []
564
565
  rubyforge_project:
565
- rubygems_version: 2.5.0
566
+ rubygems_version: 2.5.1
566
567
  signing_key:
567
568
  specification_version: 4
568
569
  summary: contentful management api
@@ -736,6 +737,7 @@ test_files:
736
737
  - spec/fixtures/vcr_cassettes/entry/search_filter/reverse_order_sys_updatedAt.yml
737
738
  - spec/fixtures/vcr_cassettes/entry/service_unavailable.yml
738
739
  - spec/fixtures/vcr_cassettes/entry/too_many_requests.yml
740
+ - spec/fixtures/vcr_cassettes/entry/too_many_requests_retry.yml
739
741
  - spec/fixtures/vcr_cassettes/entry/unarchive.yml
740
742
  - spec/fixtures/vcr_cassettes/entry/unarchive_already_unarchived.yml
741
743
  - spec/fixtures/vcr_cassettes/entry/unpublish.yml