contentful-management 1.7.0 → 1.8.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: c880b5d6e4f5f9b5cf11599a5177de92c8cfb673
4
- data.tar.gz: 57ed6666b81a6767b4c7d5b1b315d2bf64f3e7e2
3
+ metadata.gz: 40d1451f0e37654a37d2f0fe02bc0c8931440c1f
4
+ data.tar.gz: 8abbaf22f08e54e9167507705523fa15bd1c071e
5
5
  SHA512:
6
- metadata.gz: e590866845d60f709bfd6b525f2a7a4ef779373e78e57881e375237f52ea54e3b66a52d221052cab7a572c3a609127cfbb8aa41a0cd3cddaca9a01e447dce278
7
- data.tar.gz: f115b17339749173bdbd4c883b8d3cc0d99ceaa398f3b30639959a31ebcfc5751d01a9b61198deae79f5fd019d2c91b883836a2f06f95f8895ec1c4bc2c437af
6
+ metadata.gz: 5cf284b9bdd5b41613caf2c8e891ec65fcaf46eebd108a243f240bd008477cb31096b68ab9e6d70ae22139886f2a04c9a56f8838854118578f5d83cf35176536
7
+ data.tar.gz: d337afda7c3e38a6a139f7a3d270664037528186b808b03760324ee604f25d135fd942a9f3428b3c2befaf74b8305ed1da85e9ffe736edcfc0d835c837871334
data/.rubocop.yml CHANGED
@@ -20,7 +20,7 @@ Metrics/LineLength:
20
20
  Max: 135
21
21
 
22
22
  Metrics/ClassLength:
23
- Max: 250
23
+ Max: 300
24
24
 
25
25
  Style/SignalException:
26
26
  EnforcedStyle: 'semantic'
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 1.8.0
6
+ ### Added
7
+ * Added `X-Contentful-User-Agent` header for more information.
8
+
5
9
  ## 1.7.0
6
10
 
7
11
  ### Added
@@ -21,6 +21,7 @@ require_relative 'request'
21
21
  require 'http'
22
22
  require 'json'
23
23
  require 'logger'
24
+ require 'rbconfig'
24
25
 
25
26
  module Contentful
26
27
  module Management
@@ -49,7 +50,11 @@ module Contentful
49
50
  proxy_username: nil,
50
51
  proxy_password: nil,
51
52
  max_rate_limit_retries: 1,
52
- max_rate_limit_wait: 60
53
+ max_rate_limit_wait: 60,
54
+ application_name: nil,
55
+ application_version: nil,
56
+ integration_name: nil,
57
+ integration_version: nil
53
58
  }.freeze
54
59
 
55
60
  # Rate Limit Reset Header Key
@@ -69,6 +74,10 @@ module Contentful
69
74
  # @option configuration [Fixnum] :proxy_port
70
75
  # @option configuration [String] :proxy_username
71
76
  # @option configuration [String] :proxy_username
77
+ # @option configuration [String] :application_name
78
+ # @option configuration [String] :application_version
79
+ # @option configuration [String] :integration_name
80
+ # @option configuration [String] :integration_version
72
81
  def initialize(access_token = nil, configuration = {})
73
82
  @configuration = default_configuration.merge(configuration)
74
83
  setup_logger
@@ -344,9 +353,72 @@ module Contentful
344
353
  Hash['Content-Type', "application/vnd.contentful.management.v#{api_version}+json"]
345
354
  end
346
355
 
356
+ # Returns the formatted part of the X-Contentful-User-Agent header
357
+ # @private
358
+ def format_user_agent_header(key, values)
359
+ header = "#{key} #{values[:name]}"
360
+ header = "#{header}/#{values[:version]}" if values[:version]
361
+ "#{header};"
362
+ end
363
+
364
+ # Returns the X-Contentful-User-Agent sdk data
365
+ # @private
366
+ def sdk_info
367
+ { name: 'contentful-management.rb', version: ::Contentful::Management::VERSION }
368
+ end
369
+
370
+ # Returns the X-Contentful-User-Agent app data
371
+ # @private
372
+ def app_info
373
+ { name: configuration[:application_name], version: configuration[:application_version] }
374
+ end
375
+
376
+ # Returns the X-Contentful-User-Agent integration data
377
+ # @private
378
+ def integration_info
379
+ { name: configuration[:integration_name], version: configuration[:integration_version] }
380
+ end
381
+
382
+ # Returns the X-Contentful-User-Agent platform data
383
+ # @private
384
+ def platform_info
385
+ { name: 'ruby', version: RUBY_VERSION }
386
+ end
387
+
388
+ # Returns the X-Contentful-User-Agent os data
389
+ # @private
390
+ def os_info
391
+ os_name = case ::RbConfig::CONFIG['host_os']
392
+ when /(cygwin|mingw|mswin|windows)/i then 'Windows'
393
+ when /(darwin|macruby|mac os)/i then 'macOS'
394
+ when /(linux|bsd|aix|solarix)/i then 'Linux'
395
+ end
396
+ { name: os_name, version: Gem::Platform.local.version }
397
+ end
398
+
399
+ # Returns the X-Contentful-User-Agent
400
+ # @private
401
+ def contentful_user_agent
402
+ header = {
403
+ 'sdk' => sdk_info,
404
+ 'app' => app_info,
405
+ 'integration' => integration_info,
406
+ 'platform' => platform_info,
407
+ 'os' => os_info
408
+ }
409
+
410
+ result = []
411
+ header.each do |key, values|
412
+ next unless values[:name]
413
+ result << format_user_agent_header(key, values)
414
+ end
415
+
416
+ result.join(' ')
417
+ end
418
+
347
419
  # @private
348
420
  def user_agent
349
- Hash['User-Agent', "RubyContentfulManagementGem/#{Contentful::Management::VERSION}"]
421
+ Hash['X-Contentful-User-Agent', contentful_user_agent]
350
422
  end
351
423
 
352
424
  # @private
@@ -14,6 +14,8 @@ module Contentful
14
14
  property :range, :hash
15
15
  property :linkMimetypeGroup, :string
16
16
  property :linkField, :boolean
17
+ property :unique, :boolean
18
+ property :assetFileSize, :hash
17
19
 
18
20
  # @private
19
21
  def properties_to_hash
@@ -3,6 +3,6 @@ module Contentful
3
3
  # Management Namespace
4
4
  module Management
5
5
  # Gem Version
6
- VERSION = '1.7.0'.freeze
6
+ VERSION = '1.8.0'.freeze
7
7
  end
8
8
  end
@@ -0,0 +1,526 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/iig6ari2cj2t
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContentfulManagementGem/1.7.0
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Content-Length:
17
+ - '0'
18
+ Connection:
19
+ - close
20
+ Host:
21
+ - api.contentful.com
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Accept-Ranges:
28
+ - bytes
29
+ Access-Control-Allow-Headers:
30
+ - 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,X-Contentful-User-Agent
31
+ Access-Control-Allow-Methods:
32
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Expose-Headers:
36
+ - Etag
37
+ Access-Control-Max-Age:
38
+ - '1728000'
39
+ Cache-Control:
40
+ - max-age=0
41
+ Cf-Organization-Id:
42
+ - 0IKEmvvGDzoiQ94Zq50lBc
43
+ Cf-Space-Id:
44
+ - iig6ari2cj2t
45
+ Content-Type:
46
+ - application/vnd.contentful.management.v1+json
47
+ Date:
48
+ - Thu, 11 May 2017 02:42:11 GMT
49
+ Etag:
50
+ - W/"f92eb6dd9c7262fbdccf0d61a89cd016"
51
+ Server:
52
+ - Contentful
53
+ Strict-Transport-Security:
54
+ - max-age=15768000
55
+ X-Content-Type-Options:
56
+ - nosniff
57
+ X-Contentful-Ratelimit-Hour-Limit:
58
+ - '36000'
59
+ X-Contentful-Ratelimit-Hour-Remaining:
60
+ - '35860'
61
+ X-Contentful-Ratelimit-Reset:
62
+ - '0'
63
+ X-Contentful-Ratelimit-Second-Limit:
64
+ - '10'
65
+ X-Contentful-Ratelimit-Second-Remaining:
66
+ - '9'
67
+ X-Contentful-Request-Id:
68
+ - c78585c1c120de426178432d345fbb01
69
+ X-Frame-Options:
70
+ - ALLOWALL
71
+ X-Xss-Protection:
72
+ - 1; mode=block
73
+ Content-Length:
74
+ - '453'
75
+ Connection:
76
+ - Close
77
+ X-Iinfo:
78
+ - 7-8367135-8367137 NNNN CT(224 452 0) RT(1494470530343 12) q(0 0 7 -1) r(10
79
+ 10) U5
80
+ X-Cdn:
81
+ - Incapsula
82
+ body:
83
+ encoding: ASCII-8BIT
84
+ string: |+
85
+ {
86
+ "name":"stefan-dev",
87
+ "sys":{
88
+ "type":"Space",
89
+ "id":"iig6ari2cj2t",
90
+ "version":1,
91
+ "createdBy":{
92
+ "sys":{
93
+ "type":"Link",
94
+ "linkType":"User",
95
+ "id":"0tqeNNbBRbgi5aGEc4R4ai"
96
+ }
97
+ },
98
+ "createdAt":"2017-05-10T07:59:56Z",
99
+ "updatedBy":{
100
+ "sys":{
101
+ "type":"Link",
102
+ "linkType":"User",
103
+ "id":"0tqeNNbBRbgi5aGEc4R4ai"
104
+ }
105
+ },
106
+ "updatedAt":"2017-05-10T07:59:56Z"
107
+ }
108
+ }
109
+
110
+ http_version:
111
+ recorded_at: Thu, 11 May 2017 02:42:11 GMT
112
+ - request:
113
+ method: get
114
+ uri: https://api.contentful.com/spaces/iig6ari2cj2t/content_types
115
+ body:
116
+ encoding: US-ASCII
117
+ string: ''
118
+ headers:
119
+ User-Agent:
120
+ - RubyContentfulManagementGem/1.7.0
121
+ Authorization:
122
+ - Bearer <ACCESS_TOKEN>
123
+ Content-Type:
124
+ - application/vnd.contentful.management.v1+json
125
+ Content-Length:
126
+ - '0'
127
+ Connection:
128
+ - close
129
+ Host:
130
+ - api.contentful.com
131
+ response:
132
+ status:
133
+ code: 200
134
+ message: OK
135
+ headers:
136
+ Access-Control-Allow-Headers:
137
+ - 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,X-Contentful-User-Agent
138
+ Access-Control-Allow-Methods:
139
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
140
+ Access-Control-Allow-Origin:
141
+ - "*"
142
+ Access-Control-Expose-Headers:
143
+ - Etag
144
+ Access-Control-Max-Age:
145
+ - '1728000'
146
+ Cf-Space-Id:
147
+ - iig6ari2cj2t
148
+ Content-Type:
149
+ - application/vnd.contentful.management.v1+json
150
+ Date:
151
+ - Thu, 11 May 2017 02:42:12 GMT
152
+ Etag:
153
+ - '"c9b789c4ad9917d3b4687cfcfe518960"'
154
+ Server:
155
+ - Contentful
156
+ Strict-Transport-Security:
157
+ - max-age=15768000
158
+ X-Content-Type-Options:
159
+ - nosniff
160
+ X-Contentful-Ratelimit-Hour-Limit:
161
+ - '36000'
162
+ X-Contentful-Ratelimit-Hour-Remaining:
163
+ - '35859'
164
+ X-Contentful-Ratelimit-Reset:
165
+ - '0'
166
+ X-Contentful-Ratelimit-Second-Limit:
167
+ - '10'
168
+ X-Contentful-Ratelimit-Second-Remaining:
169
+ - '9'
170
+ X-Contentful-Request-Id:
171
+ - fa5c0ba379f0f1e62034fe67de21655c
172
+ Content-Length:
173
+ - '3685'
174
+ Connection:
175
+ - Close
176
+ X-Iinfo:
177
+ - 10-22082754-22082756 NNNN CT(223 228 0) RT(1494470531334 13) q(0 0 4 -1) r(8
178
+ 8) U5
179
+ X-Cdn:
180
+ - Incapsula
181
+ body:
182
+ encoding: ASCII-8BIT
183
+ string: |
184
+ {
185
+ "sys": {
186
+ "type": "Array"
187
+ },
188
+ "total": 2,
189
+ "skip": 0,
190
+ "limit": 100,
191
+ "items": [
192
+ {
193
+ "sys": {
194
+ "space": {
195
+ "sys": {
196
+ "type": "Link",
197
+ "linkType": "Space",
198
+ "id": "iig6ari2cj2t"
199
+ }
200
+ },
201
+ "id": "1JrDv4JJsYuY4KGEEgAsQU",
202
+ "type": "ContentType",
203
+ "createdAt": "2017-05-11T02:26:15.925Z",
204
+ "updatedAt": "2017-05-11T02:26:16.706Z",
205
+ "createdBy": {
206
+ "sys": {
207
+ "type": "Link",
208
+ "linkType": "User",
209
+ "id": "0tqeNNbBRbgi5aGEc4R4ai"
210
+ }
211
+ },
212
+ "updatedBy": {
213
+ "sys": {
214
+ "type": "Link",
215
+ "linkType": "User",
216
+ "id": "0tqeNNbBRbgi5aGEc4R4ai"
217
+ }
218
+ },
219
+ "publishedCounter": 1,
220
+ "version": 2,
221
+ "publishedBy": {
222
+ "sys": {
223
+ "type": "Link",
224
+ "linkType": "User",
225
+ "id": "0tqeNNbBRbgi5aGEc4R4ai"
226
+ }
227
+ },
228
+ "publishedVersion": 1,
229
+ "firstPublishedAt": "2017-05-11T02:26:16.693Z",
230
+ "publishedAt": "2017-05-11T02:26:16.693Z"
231
+ },
232
+ "displayField": "t",
233
+ "name": "test",
234
+ "description": "abcd",
235
+ "fields": [
236
+ {
237
+ "id": "t",
238
+ "name": "t",
239
+ "type": "Symbol",
240
+ "localized": false,
241
+ "required": false,
242
+ "validations": [],
243
+ "disabled": false,
244
+ "omitted": false
245
+ }
246
+ ]
247
+ }
248
+ ]
249
+ }
250
+ http_version:
251
+ recorded_at: Thu, 11 May 2017 02:42:12 GMT
252
+ - request:
253
+ method: get
254
+ uri: https://api.contentful.com/spaces/iig6ari2cj2t/content_types/1JrDv4JJsYuY4KGEEgAsQU
255
+ body:
256
+ encoding: US-ASCII
257
+ string: ''
258
+ headers:
259
+ User-Agent:
260
+ - RubyContentfulManagementGem/1.7.0
261
+ Authorization:
262
+ - Bearer <ACCESS_TOKEN>
263
+ Content-Type:
264
+ - application/vnd.contentful.management.v1+json
265
+ Content-Length:
266
+ - '0'
267
+ Connection:
268
+ - close
269
+ Host:
270
+ - api.contentful.com
271
+ response:
272
+ status:
273
+ code: 200
274
+ message: OK
275
+ headers:
276
+ Access-Control-Allow-Headers:
277
+ - 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,X-Contentful-User-Agent
278
+ Access-Control-Allow-Methods:
279
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
280
+ Access-Control-Allow-Origin:
281
+ - "*"
282
+ Access-Control-Expose-Headers:
283
+ - Etag
284
+ Access-Control-Max-Age:
285
+ - '1728000'
286
+ Cf-Space-Id:
287
+ - iig6ari2cj2t
288
+ Content-Type:
289
+ - application/vnd.contentful.management.v1+json
290
+ Date:
291
+ - Thu, 11 May 2017 02:42:13 GMT
292
+ Etag:
293
+ - '"7af0e379f007cf7a7e58f4e8289b0e13"'
294
+ Server:
295
+ - Contentful
296
+ Strict-Transport-Security:
297
+ - max-age=15768000
298
+ X-Content-Type-Options:
299
+ - nosniff
300
+ X-Contentful-Ratelimit-Hour-Limit:
301
+ - '36000'
302
+ X-Contentful-Ratelimit-Hour-Remaining:
303
+ - '35858'
304
+ X-Contentful-Ratelimit-Reset:
305
+ - '0'
306
+ X-Contentful-Ratelimit-Second-Limit:
307
+ - '10'
308
+ X-Contentful-Ratelimit-Second-Remaining:
309
+ - '9'
310
+ X-Contentful-Request-Id:
311
+ - 77a495f932828b381223642ae1f8fbec
312
+ Content-Length:
313
+ - '1172'
314
+ Connection:
315
+ - Close
316
+ X-Iinfo:
317
+ - 6-5223669-5223671 NNNN CT(220 220 0) RT(1494470532122 11) q(0 0 4 -1) r(7
318
+ 7) U5
319
+ X-Cdn:
320
+ - Incapsula
321
+ body:
322
+ encoding: ASCII-8BIT
323
+ string: |
324
+ {
325
+ "name": "test",
326
+ "fields": [
327
+ {
328
+ "name": "t",
329
+ "id": "t",
330
+ "type": "Symbol",
331
+ "validations": [],
332
+ "localized": false,
333
+ "required": false,
334
+ "disabled": false,
335
+ "omitted": false
336
+ }
337
+ ],
338
+ "displayField": "t",
339
+ "description": "abcd",
340
+ "sys": {
341
+ "id": "1JrDv4JJsYuY4KGEEgAsQU",
342
+ "type": "ContentType",
343
+ "createdAt": "2017-05-11T02:26:15.925Z",
344
+ "createdBy": {
345
+ "sys": {
346
+ "type": "Link",
347
+ "linkType": "User",
348
+ "id": "0tqeNNbBRbgi5aGEc4R4ai"
349
+ }
350
+ },
351
+ "space": {
352
+ "sys": {
353
+ "type": "Link",
354
+ "linkType": "Space",
355
+ "id": "iig6ari2cj2t"
356
+ }
357
+ },
358
+ "firstPublishedAt": "2017-05-11T02:26:16.693Z",
359
+ "publishedCounter": 1,
360
+ "publishedAt": "2017-05-11T02:26:16.693Z",
361
+ "publishedBy": {
362
+ "sys": {
363
+ "type": "Link",
364
+ "linkType": "User",
365
+ "id": "0tqeNNbBRbgi5aGEc4R4ai"
366
+ }
367
+ },
368
+ "publishedVersion": 1,
369
+ "version": 2,
370
+ "updatedAt": "2017-05-11T02:26:16.706Z",
371
+ "updatedBy": {
372
+ "sys": {
373
+ "type": "Link",
374
+ "linkType": "User",
375
+ "id": "0tqeNNbBRbgi5aGEc4R4ai"
376
+ }
377
+ }
378
+ }
379
+ }
380
+ http_version:
381
+ recorded_at: Thu, 11 May 2017 02:42:13 GMT
382
+ - request:
383
+ method: put
384
+ uri: https://api.contentful.com/spaces/iig6ari2cj2t/content_types/1JrDv4JJsYuY4KGEEgAsQU
385
+ body:
386
+ encoding: UTF-8
387
+ string: '{"displayField":"t","name":"test","description":"abcd","fields":[{"id":"t","name":"t","type":"Symbol","linkType":null,"items":null,"required":null,"localized":null,"validations":[],"disabled":null,"omitted":null},{"id":"symbol","name":"Slug","type":"Symbol","validations":[{"unique":true}]}]}'
388
+ headers:
389
+ User-Agent:
390
+ - RubyContentfulManagementGem/1.7.0
391
+ Authorization:
392
+ - Bearer <ACCESS_TOKEN>
393
+ Content-Type:
394
+ - application/vnd.contentful.management.v1+json
395
+ X-Contentful-Version:
396
+ - '2'
397
+ Version:
398
+ - '2'
399
+ Connection:
400
+ - close
401
+ Host:
402
+ - api.contentful.com
403
+ response:
404
+ status:
405
+ code: 200
406
+ message: OK
407
+ headers:
408
+ Access-Control-Allow-Headers:
409
+ - 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,X-Contentful-User-Agent
410
+ Access-Control-Allow-Methods:
411
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
412
+ Access-Control-Allow-Origin:
413
+ - "*"
414
+ Access-Control-Expose-Headers:
415
+ - Etag
416
+ Access-Control-Max-Age:
417
+ - '1728000'
418
+ Cf-Space-Id:
419
+ - iig6ari2cj2t
420
+ Content-Type:
421
+ - application/vnd.contentful.management.v1+json
422
+ Date:
423
+ - Thu, 11 May 2017 02:42:14 GMT
424
+ Etag:
425
+ - '"82562582a32e3b9e1e3e76f75434c87d"'
426
+ Server:
427
+ - Contentful
428
+ Strict-Transport-Security:
429
+ - max-age=15768000
430
+ X-Content-Type-Options:
431
+ - nosniff
432
+ X-Contentful-Ratelimit-Hour-Limit:
433
+ - '36000'
434
+ X-Contentful-Ratelimit-Hour-Remaining:
435
+ - '35857'
436
+ X-Contentful-Ratelimit-Reset:
437
+ - '0'
438
+ X-Contentful-Ratelimit-Second-Limit:
439
+ - '10'
440
+ X-Contentful-Ratelimit-Second-Remaining:
441
+ - '9'
442
+ X-Contentful-Request-Id:
443
+ - c39d48769d0dc0259bcea60fea0777cb
444
+ Content-Length:
445
+ - '1370'
446
+ Connection:
447
+ - Close
448
+ X-Iinfo:
449
+ - 5-27034072-27034077 NNNN CT(221 225 0) RT(1494470532943 12) q(0 0 5 -1) r(8
450
+ 8) U5
451
+ X-Cdn:
452
+ - Incapsula
453
+ body:
454
+ encoding: ASCII-8BIT
455
+ string: |
456
+ {
457
+ "displayField": "t",
458
+ "name": "test",
459
+ "description": "abcd",
460
+ "fields": [
461
+ {
462
+ "id": "t",
463
+ "name": "t",
464
+ "type": "Symbol",
465
+ "linkType": null,
466
+ "items": null,
467
+ "required": null,
468
+ "localized": null,
469
+ "validations": [],
470
+ "disabled": null,
471
+ "omitted": null
472
+ },
473
+ {
474
+ "id": "symbol",
475
+ "name": "Slug",
476
+ "type": "Symbol",
477
+ "validations": [
478
+ {
479
+ "unique": true
480
+ }
481
+ ]
482
+ }
483
+ ],
484
+ "sys": {
485
+ "id": "1JrDv4JJsYuY4KGEEgAsQU",
486
+ "type": "ContentType",
487
+ "createdAt": "2017-05-11T02:26:15.925Z",
488
+ "createdBy": {
489
+ "sys": {
490
+ "type": "Link",
491
+ "linkType": "User",
492
+ "id": "0tqeNNbBRbgi5aGEc4R4ai"
493
+ }
494
+ },
495
+ "space": {
496
+ "sys": {
497
+ "type": "Link",
498
+ "linkType": "Space",
499
+ "id": "iig6ari2cj2t"
500
+ }
501
+ },
502
+ "firstPublishedAt": "2017-05-11T02:26:16.693Z",
503
+ "publishedCounter": 1,
504
+ "publishedAt": "2017-05-11T02:26:16.693Z",
505
+ "publishedBy": {
506
+ "sys": {
507
+ "type": "Link",
508
+ "linkType": "User",
509
+ "id": "0tqeNNbBRbgi5aGEc4R4ai"
510
+ }
511
+ },
512
+ "publishedVersion": 1,
513
+ "version": 3,
514
+ "updatedAt": "2017-05-11T02:42:14.195Z",
515
+ "updatedBy": {
516
+ "sys": {
517
+ "type": "Link",
518
+ "linkType": "User",
519
+ "id": "0tqeNNbBRbgi5aGEc4R4ai"
520
+ }
521
+ }
522
+ }
523
+ }
524
+ http_version:
525
+ recorded_at: Thu, 11 May 2017 02:42:14 GMT
526
+ recorded_with: VCR 3.0.3
@@ -31,7 +31,168 @@ module Contentful
31
31
 
32
32
  describe '#user_agent' do
33
33
  its(:user_agent) { should be_kind_of Hash }
34
- its(:user_agent) { should eq 'User-Agent' => "RubyContentfulManagementGem/#{ Contentful::Management::VERSION }" }
34
+ its(:user_agent) { should eq 'X-Contentful-User-Agent' => client.contentful_user_agent }
35
+ end
36
+
37
+ describe 'X-Contentful-User-Agent header' do
38
+ it 'default values' do
39
+ expected = [
40
+ "sdk contentful-management.rb/#{Contentful::Management::VERSION};",
41
+ "platform ruby/#{RUBY_VERSION};"
42
+ ]
43
+
44
+ client = Client.new(token)
45
+ expected.each do |h|
46
+ expect(client.contentful_user_agent).to include(h)
47
+ end
48
+
49
+ expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
50
+
51
+ ['integration', 'app'].each do |h|
52
+ expect(client.contentful_user_agent).not_to include(h)
53
+ end
54
+ end
55
+
56
+ it 'with integration name only' do
57
+ expected = [
58
+ "sdk contentful-management.rb/#{Contentful::Management::VERSION};",
59
+ "platform ruby/#{RUBY_VERSION};",
60
+ "integration foobar;"
61
+ ]
62
+
63
+ client = Client.new(
64
+ token,
65
+ integration_name: 'foobar'
66
+ )
67
+ expected.each do |h|
68
+ expect(client.contentful_user_agent).to include(h)
69
+ end
70
+
71
+ expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
72
+
73
+ ['app'].each do |h|
74
+ expect(client.contentful_user_agent).not_to include(h)
75
+ end
76
+ end
77
+
78
+ it 'with integration' do
79
+ expected = [
80
+ "sdk contentful-management.rb/#{Contentful::Management::VERSION};",
81
+ "platform ruby/#{RUBY_VERSION};",
82
+ "integration foobar/0.1.0;"
83
+ ]
84
+
85
+ client = Client.new(
86
+ token,
87
+ integration_name: 'foobar',
88
+ integration_version: '0.1.0'
89
+ )
90
+ expected.each do |h|
91
+ expect(client.contentful_user_agent).to include(h)
92
+ end
93
+
94
+ expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
95
+
96
+ ['app'].each do |h|
97
+ expect(client.contentful_user_agent).not_to include(h)
98
+ end
99
+ end
100
+
101
+ it 'with application name only' do
102
+ expected = [
103
+ "sdk contentful-management.rb/#{Contentful::Management::VERSION};",
104
+ "platform ruby/#{RUBY_VERSION};",
105
+ "app fooapp;"
106
+ ]
107
+
108
+ client = Client.new(
109
+ token,
110
+ application_name: 'fooapp'
111
+ )
112
+ expected.each do |h|
113
+ expect(client.contentful_user_agent).to include(h)
114
+ end
115
+
116
+ expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
117
+
118
+ ['integration'].each do |h|
119
+ expect(client.contentful_user_agent).not_to include(h)
120
+ end
121
+ end
122
+
123
+ it 'with application' do
124
+ expected = [
125
+ "sdk contentful-management.rb/#{Contentful::Management::VERSION};",
126
+ "platform ruby/#{RUBY_VERSION};",
127
+ "app fooapp/1.0.0;"
128
+ ]
129
+
130
+ client = Client.new(
131
+ token,
132
+ application_name: 'fooapp',
133
+ application_version: '1.0.0'
134
+ )
135
+ expected.each do |h|
136
+ expect(client.contentful_user_agent).to include(h)
137
+ end
138
+
139
+ expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
140
+
141
+ ['integration'].each do |h|
142
+ expect(client.contentful_user_agent).not_to include(h)
143
+ end
144
+ end
145
+
146
+ it 'with all' do
147
+ expected = [
148
+ "sdk contentful-management.rb/#{Contentful::Management::VERSION};",
149
+ "platform ruby/#{RUBY_VERSION};",
150
+ "integration foobar/0.1.0;",
151
+ "app fooapp/1.0.0;"
152
+ ]
153
+
154
+ client = Client.new(
155
+ token,
156
+ integration_name: 'foobar',
157
+ integration_version: '0.1.0',
158
+ application_name: 'fooapp',
159
+ application_version: '1.0.0'
160
+ )
161
+
162
+ expected.each do |h|
163
+ expect(client.contentful_user_agent).to include(h)
164
+ end
165
+
166
+ expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
167
+ end
168
+
169
+ it 'when only version numbers, skips header' do
170
+ expected = [
171
+ "sdk contentful-management.rb/#{Contentful::Management::VERSION};",
172
+ "platform ruby/#{RUBY_VERSION};"
173
+ ]
174
+
175
+ client = Client.new(
176
+ token,
177
+ integration_version: '0.1.0',
178
+ application_version: '1.0.0'
179
+ )
180
+
181
+ expected.each do |h|
182
+ expect(client.contentful_user_agent).to include(h)
183
+ end
184
+
185
+ expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
186
+
187
+ ['integration', 'app'].each do |h|
188
+ expect(client.contentful_user_agent).not_to include(h)
189
+ end
190
+ end
191
+
192
+ it 'headers include X-Contentful-User-Agent' do
193
+ client = Client.new(token)
194
+ expect(client.request_headers['X-Contentful-User-Agent']).to eq client.contentful_user_agent
195
+ end
35
196
  end
36
197
 
37
198
  describe '#organization_header' do
@@ -729,6 +729,19 @@ module Contentful
729
729
  end
730
730
  end
731
731
  end
732
+ context 'unique' do
733
+ let(:space) { client.spaces.find('iig6ari2cj2t') }
734
+ it 'adds `unique` validation to field' do
735
+ vcr('content_type/validation/unique') do
736
+ content_type = space.content_types.find('1JrDv4JJsYuY4KGEEgAsQU')
737
+ validation_unique = Contentful::Management::Validation.new
738
+ validation_unique.unique = true
739
+ content_type.fields.create(id: 'symbol', name: 'Slug', type: 'Symbol', validations: [validation_unique])
740
+ expect(content_type.fields.last.validations.first.properties[:unique]).to be_truthy
741
+ expect(content_type.fields.last.validations.first.type).to be :unique
742
+ end
743
+ end
744
+ end
732
745
 
733
746
  context 'add multiple validations' do
734
747
  it 'create field with multiple validations' do
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.7.0
4
+ version: 1.8.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: 2017-05-02 00:00:00.000000000 Z
13
+ date: 2017-05-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http
@@ -463,6 +463,7 @@ files:
463
463
  - spec/fixtures/vcr_cassettes/content_type/validation/range_update.yml
464
464
  - spec/fixtures/vcr_cassettes/content_type/validation/regexp.yml
465
465
  - spec/fixtures/vcr_cassettes/content_type/validation/size.yml
466
+ - spec/fixtures/vcr_cassettes/content_type/validation/unique.yml
466
467
  - spec/fixtures/vcr_cassettes/delete_request.yml
467
468
  - spec/fixtures/vcr_cassettes/editor_interfaces/default_for_space.yml
468
469
  - spec/fixtures/vcr_cassettes/editor_interfaces/update.yml
@@ -772,6 +773,7 @@ test_files:
772
773
  - spec/fixtures/vcr_cassettes/content_type/validation/range_update.yml
773
774
  - spec/fixtures/vcr_cassettes/content_type/validation/regexp.yml
774
775
  - spec/fixtures/vcr_cassettes/content_type/validation/size.yml
776
+ - spec/fixtures/vcr_cassettes/content_type/validation/unique.yml
775
777
  - spec/fixtures/vcr_cassettes/delete_request.yml
776
778
  - spec/fixtures/vcr_cassettes/editor_interfaces/default_for_space.yml
777
779
  - spec/fixtures/vcr_cassettes/editor_interfaces/update.yml