contentful 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/README.md +18 -21
- data/lib/contentful/client.rb +73 -2
- data/lib/contentful/version.rb +1 -1
- data/spec/client_configuration_spec.rb +145 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64ddb906124dfd977570b56271e874dd105bad5d
|
4
|
+
data.tar.gz: dc3c20c1dadf513ef9429ade5c0e7f796c4a5d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba13149d7dc6794482c5950f2bb563511041731899f0b757d3efc8aeb7557e0e1670b273755b5c0b422efa7c3d7ed03f2343e014c6608541f6311a9d14e09900
|
7
|
+
data.tar.gz: 899dbabd938a143fba8190e3f1bacdf7c6d46482059a9b1370b393f86688a18535e81d33508b13da7e90d7e4c18c34f2f4daeb403832d2f8d7b0b592750e201f
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -58,12 +58,6 @@ content_type = client.content_type 'cat'
|
|
58
58
|
content_type.description # "Meow."
|
59
59
|
```
|
60
60
|
|
61
|
-
Alternatively, the data can be accessed as Ruby `Hash` with symbolized keys (and in camelCase):
|
62
|
-
|
63
|
-
```ruby
|
64
|
-
content_type.properties # { name: '...', description: '...' }
|
65
|
-
```
|
66
|
-
|
67
61
|
System Properties behave the same and can be accessed via the `#sys` method.
|
68
62
|
|
69
63
|
```ruby
|
@@ -315,19 +309,6 @@ client = Contentful::Client.new(
|
|
315
309
|
client.entry('nyancat') # is instance of Cat
|
316
310
|
```
|
317
311
|
|
318
|
-
If you want to use the `property :field_name` syntax, you can do it the following way:
|
319
|
-
|
320
|
-
```ruby
|
321
|
-
class Cat < Contentful::Entry
|
322
|
-
include Contentful::Resource::CustomResource
|
323
|
-
|
324
|
-
property :name
|
325
|
-
property :lives
|
326
|
-
property :bestFriend
|
327
|
-
# ...
|
328
|
-
end
|
329
|
-
```
|
330
|
-
|
331
312
|
## Synchronization
|
332
313
|
|
333
314
|
The client also includes a wrapper for the synchronization endpoint. You can initialize it with the options described in the [Delivery API Documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization) or an URL you received from a previous sync:
|
@@ -382,9 +363,25 @@ first_entry.fields('de-DE') # Returns German localizations
|
|
382
363
|
|
383
364
|
- When an entry has related entries that are unpublished, they still end up in the resource as unresolved links. We consider this correct, because it is in line with the API responses and our other SDKs. However, you can use the workaround from [issue #60](/../../issues/60) if you happen to want this working differently.
|
384
365
|
|
385
|
-
|
366
|
+
## Migrating to 2.x
|
386
367
|
|
368
|
+
If you're a `0.x` or a `1.x` user of this gem, and are planning to migrate to the current `2.x` branch.
|
369
|
+
There are a few breaking changes you have to take into account:
|
370
|
+
|
371
|
+
* `Contentful::Link#resolve` and `Contentful::Array#next_page` now require a `Contentful::Client` instance as a parameter.
|
372
|
+
* `Contentful::CustomResource` does no longer exist, custom entry classes can now inherit from `Contentful::Entry` and have proper marshalling working.
|
373
|
+
* `Contentful::Resource` does no longer exist, all resource classes now inherit from `Contentful::BaseResource`. `Contentful::Entry` and `Contentful::Asset` inherit from `Contentful::FieldsResource` which is a subclass of `Contentful::BaseResource`.
|
374
|
+
* `Contentful::DynamicEntry` does no longer exist, if code checked against that base class, it should now check against `Contentful::Entry` instead.
|
375
|
+
* `Contentful::Client#dynamic_entry_cache` _(private)_ has been extracted to it's own class, and can be now manually cleared by using `Contentful::ContentTypeCache::clear`.
|
376
|
+
* `Contentful::BaseResource#sys` and `Contentful::FieldsResource#fields` internal representation for keys are now snake cased to match the instance accessors. E.g. `entry.fields[:myField]` previously had the accessor `entry.my_field`, now it is `entry.fields[:my_field]`. The value in both cases would correspond to the same field, only change is to unify the style. If code accessed the values through the `#sys` or `#fields` methods, keys now need to be snake cased.
|
377
|
+
* Circular references are handled as individual objects to simplify marshalling and reduce stack errors, this introduces a performance hit on extremely interconnected content. Therefore, to limit the impact of circular references, an additional configuration flag `max_include_resolution_depth` has been added. It is set to 20 by default (which corresponds to the maximum include level value * 2). This allows for non-circular but highly connected content to resolve properly. In very interconnected content, it also allows to reduce this number to improve performance. For a more in depth look into this you can read [this issue](https://github.com/contentful/contentful.rb/issues/124#issuecomment-287002469).
|
378
|
+
* `#inspect` now offers a clearer and better output for all resources. If your code had assertions based on the string representation of the resources, update to the new format `<Contentful::#{RESOURCE_CLASS}#{additional_info} id="#{RESOURCE_ID}">`.
|
379
|
+
|
380
|
+
For more information on the internal changes present in the 2.x release, please read the [CHANGELOG](CHANGELOG.md)
|
387
381
|
|
388
382
|
## License
|
389
383
|
|
390
|
-
Copyright (c) 2014 Contentful GmbH - Jan Lelis.
|
384
|
+
Copyright (c) 2014 Contentful GmbH - Jan Lelis.
|
385
|
+
Copyright (c) 2016 Contentfuk GmbH - David Litvak.
|
386
|
+
|
387
|
+
See LICENSE.txt for further details.
|
data/lib/contentful/client.rb
CHANGED
@@ -6,6 +6,7 @@ require_relative 'content_type_cache'
|
|
6
6
|
|
7
7
|
require 'http'
|
8
8
|
require 'logger'
|
9
|
+
require 'rbconfig'
|
9
10
|
|
10
11
|
module Contentful
|
11
12
|
# The client object is initialized with a space and a key and then used
|
@@ -34,7 +35,11 @@ module Contentful
|
|
34
35
|
proxy_port: nil,
|
35
36
|
max_rate_limit_retries: 1,
|
36
37
|
max_rate_limit_wait: 60,
|
37
|
-
max_include_resolution_depth: 20
|
38
|
+
max_include_resolution_depth: 20,
|
39
|
+
application_name: nil,
|
40
|
+
application_version: nil,
|
41
|
+
integration_name: nil,
|
42
|
+
integration_version: nil
|
38
43
|
}
|
39
44
|
# Rate Limit Reset Header Key
|
40
45
|
RATE_LIMIT_RESET_HEADER_KEY = 'x-contentful-ratelimit-reset'
|
@@ -73,6 +78,10 @@ module Contentful
|
|
73
78
|
# @option given_configuration [::Array<String>] :dynamic_entries
|
74
79
|
# @option given_configuration [::Hash<String, Contentful::Resource>] :resource_mapping
|
75
80
|
# @option given_configuration [::Hash<String, Contentful::Resource>] :entry_mapping
|
81
|
+
# @option given_configuration [String] :application_name
|
82
|
+
# @option given_configuration [String] :application_version
|
83
|
+
# @option given_configuration [String] :integration_name
|
84
|
+
# @option given_configuration [String] :integration_version
|
76
85
|
def initialize(given_configuration = {})
|
77
86
|
@configuration = default_configuration.merge(given_configuration)
|
78
87
|
normalize_configuration!
|
@@ -184,10 +193,72 @@ module Contentful
|
|
184
193
|
"http#{configuration[:secure] ? 's' : ''}://#{configuration[:api_url]}/spaces/#{configuration[:space]}"
|
185
194
|
end
|
186
195
|
|
196
|
+
# Returns the formatted part of the X-Contentful-User-Agent header
|
197
|
+
# @private
|
198
|
+
def format_user_agent_header(key, values)
|
199
|
+
header = "#{key} #{values[:name]}"
|
200
|
+
header = "#{header}/#{values[:version]}" if values[:version]
|
201
|
+
"#{header};"
|
202
|
+
end
|
203
|
+
|
204
|
+
# Returns the X-Contentful-User-Agent sdk data
|
205
|
+
# @private
|
206
|
+
def sdk_info
|
207
|
+
{ name: 'contentful.rb', version: ::Contentful::VERSION }
|
208
|
+
end
|
209
|
+
|
210
|
+
# Returns the X-Contentful-User-Agent app data
|
211
|
+
# @private
|
212
|
+
def app_info
|
213
|
+
{ name: configuration[:application_name], version: configuration[:application_version] }
|
214
|
+
end
|
215
|
+
|
216
|
+
# Returns the X-Contentful-User-Agent integration data
|
217
|
+
# @private
|
218
|
+
def integration_info
|
219
|
+
{ name: configuration[:integration_name], version: configuration[:integration_version] }
|
220
|
+
end
|
221
|
+
|
222
|
+
# Returns the X-Contentful-User-Agent platform data
|
223
|
+
# @private
|
224
|
+
def platform_info
|
225
|
+
{ name: 'ruby', version: RUBY_VERSION }
|
226
|
+
end
|
227
|
+
|
228
|
+
# Returns the X-Contentful-User-Agent os data
|
229
|
+
# @private
|
230
|
+
def os_info
|
231
|
+
os_name = case ::RbConfig::CONFIG['host_os']
|
232
|
+
when /(cygwin|mingw|mswin|windows)/i then 'Windows'
|
233
|
+
when /(darwin|macruby|mac os)/i then 'macOS'
|
234
|
+
when /(linux|bsd|aix|solarix)/i then 'Linux'
|
235
|
+
end
|
236
|
+
{ name: os_name, version: Gem::Platform.local.version }
|
237
|
+
end
|
238
|
+
|
239
|
+
# Returns the X-Contentful-User-Agent
|
240
|
+
# @private
|
241
|
+
def contentful_user_agent
|
242
|
+
header = {
|
243
|
+
'sdk' => sdk_info,
|
244
|
+
'app' => app_info,
|
245
|
+
'integration' => integration_info,
|
246
|
+
'platform' => platform_info,
|
247
|
+
'os' => os_info
|
248
|
+
}
|
249
|
+
|
250
|
+
result = []
|
251
|
+
header.each do |key, values|
|
252
|
+
next unless values[:name]
|
253
|
+
result << format_user_agent_header(key, values)
|
254
|
+
end
|
255
|
+
result.join(' ')
|
256
|
+
end
|
257
|
+
|
187
258
|
# Returns the headers used for the HTTP requests
|
188
259
|
# @private
|
189
260
|
def request_headers
|
190
|
-
headers = { 'User-Agent' =>
|
261
|
+
headers = { 'X-Contentful-User-Agent' => contentful_user_agent }
|
191
262
|
headers['Authorization'] = "Bearer #{configuration[:access_token]}" if configuration[:authentication_mechanism] == :header
|
192
263
|
headers['Content-Type'] = "application/vnd.contentful.delivery.v#{configuration[:api_version].to_i}+json" if configuration[:api_version]
|
193
264
|
headers['Accept-Encoding'] = 'gzip' if configuration[:gzip_encoded]
|
data/lib/contentful/version.rb
CHANGED
@@ -202,4 +202,149 @@ describe 'Client Configuration Options' do
|
|
202
202
|
expect(finn).to be_a Contentful::Entry
|
203
203
|
end
|
204
204
|
end
|
205
|
+
|
206
|
+
describe 'X-Contentful-User-Agent headers' do
|
207
|
+
it 'default values' do
|
208
|
+
expected = [
|
209
|
+
"sdk contentful.rb/#{Contentful::VERSION};",
|
210
|
+
"platform ruby/#{RUBY_VERSION};",
|
211
|
+
]
|
212
|
+
|
213
|
+
client = create_client
|
214
|
+
expected.each do |h|
|
215
|
+
expect(client.contentful_user_agent).to include(h)
|
216
|
+
end
|
217
|
+
|
218
|
+
expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
|
219
|
+
|
220
|
+
['integration', 'app'].each do |h|
|
221
|
+
expect(client.contentful_user_agent).not_to include(h)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'with integration name only' do
|
226
|
+
expected = [
|
227
|
+
"sdk contentful.rb/#{Contentful::VERSION};",
|
228
|
+
"platform ruby/#{RUBY_VERSION};",
|
229
|
+
"integration foobar;"
|
230
|
+
]
|
231
|
+
|
232
|
+
client = create_client(integration_name: 'foobar')
|
233
|
+
expected.each do |h|
|
234
|
+
expect(client.contentful_user_agent).to include(h)
|
235
|
+
end
|
236
|
+
|
237
|
+
expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
|
238
|
+
|
239
|
+
['app'].each do |h|
|
240
|
+
expect(client.contentful_user_agent).not_to include(h)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'with integration' do
|
245
|
+
expected = [
|
246
|
+
"sdk contentful.rb/#{Contentful::VERSION};",
|
247
|
+
"platform ruby/#{RUBY_VERSION};",
|
248
|
+
"integration foobar/0.1.0;"
|
249
|
+
]
|
250
|
+
|
251
|
+
client = create_client(integration_name: 'foobar', integration_version: '0.1.0')
|
252
|
+
expected.each do |h|
|
253
|
+
expect(client.contentful_user_agent).to include(h)
|
254
|
+
end
|
255
|
+
|
256
|
+
expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
|
257
|
+
|
258
|
+
['app'].each do |h|
|
259
|
+
expect(client.contentful_user_agent).not_to include(h)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'with application name only' do
|
264
|
+
expected = [
|
265
|
+
"sdk contentful.rb/#{Contentful::VERSION};",
|
266
|
+
"platform ruby/#{RUBY_VERSION};",
|
267
|
+
"app fooapp;"
|
268
|
+
]
|
269
|
+
|
270
|
+
client = create_client(application_name: 'fooapp')
|
271
|
+
expected.each do |h|
|
272
|
+
expect(client.contentful_user_agent).to include(h)
|
273
|
+
end
|
274
|
+
|
275
|
+
expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
|
276
|
+
|
277
|
+
['integration'].each do |h|
|
278
|
+
expect(client.contentful_user_agent).not_to include(h)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'with application' do
|
283
|
+
expected = [
|
284
|
+
"sdk contentful.rb/#{Contentful::VERSION};",
|
285
|
+
"platform ruby/#{RUBY_VERSION};",
|
286
|
+
"app fooapp/1.0.0;"
|
287
|
+
]
|
288
|
+
|
289
|
+
client = create_client(application_name: 'fooapp', application_version: '1.0.0')
|
290
|
+
expected.each do |h|
|
291
|
+
expect(client.contentful_user_agent).to include(h)
|
292
|
+
end
|
293
|
+
|
294
|
+
expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
|
295
|
+
|
296
|
+
['integration'].each do |h|
|
297
|
+
expect(client.contentful_user_agent).not_to include(h)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'with all' do
|
302
|
+
expected = [
|
303
|
+
"sdk contentful.rb/#{Contentful::VERSION};",
|
304
|
+
"platform ruby/#{RUBY_VERSION};",
|
305
|
+
"integration foobar/0.1.0;",
|
306
|
+
"app fooapp/1.0.0;"
|
307
|
+
]
|
308
|
+
|
309
|
+
client = create_client(
|
310
|
+
integration_name: 'foobar',
|
311
|
+
integration_version: '0.1.0',
|
312
|
+
application_name: 'fooapp',
|
313
|
+
application_version: '1.0.0'
|
314
|
+
)
|
315
|
+
|
316
|
+
expected.each do |h|
|
317
|
+
expect(client.contentful_user_agent).to include(h)
|
318
|
+
end
|
319
|
+
|
320
|
+
expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
|
321
|
+
end
|
322
|
+
|
323
|
+
it 'when only version numbers, skips header' do
|
324
|
+
expected = [
|
325
|
+
"sdk contentful.rb/#{Contentful::VERSION};",
|
326
|
+
"platform ruby/#{RUBY_VERSION};"
|
327
|
+
]
|
328
|
+
|
329
|
+
client = create_client(
|
330
|
+
integration_version: '0.1.0',
|
331
|
+
application_version: '1.0.0'
|
332
|
+
)
|
333
|
+
|
334
|
+
expected.each do |h|
|
335
|
+
expect(client.contentful_user_agent).to include(h)
|
336
|
+
end
|
337
|
+
|
338
|
+
expect(client.contentful_user_agent).to match(/os (Windows|macOS|Linux)(\/.*)?;/i)
|
339
|
+
|
340
|
+
['integration', 'app'].each do |h|
|
341
|
+
expect(client.contentful_user_agent).not_to include(h)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'headers include X-Contentful-User-Agent' do
|
346
|
+
client = create_client
|
347
|
+
expect(client.request_headers['X-Contentful-User-Agent']).to eq client.contentful_user_agent
|
348
|
+
end
|
349
|
+
end
|
205
350
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH (Jan Lelis)
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: http
|