contentful 1.0.0 → 1.0.1

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: 0113f1da37746a15f2e342b3d7248ea3edffce5e
4
- data.tar.gz: a3c9f048f5f9a8fd6dc2ecf978af27c2dc986952
3
+ metadata.gz: e018b3e026198922d69a821134ba088e962b750f
4
+ data.tar.gz: f0237cee08b92e9e17864831e20f91d74afb8733
5
5
  SHA512:
6
- metadata.gz: 79d39379d1187ab7037fb11000ca0233ff0c101c855a6ef01e651244ec0516e49822a5afd1e5d9b94fa9c20d487fa13bbd51c9abeff7467e6b84ca0930a96a2a
7
- data.tar.gz: 84443697de10d3b27db87d08f7fd5b5385de83bfd32e44bdc3c58e8374f127772becb209e1e155e85957cf61aaa6fe20c7c4921d9d781df02a8c9b1a0f4ec0bf
6
+ metadata.gz: 4c11bc9897c16a237b5afac122f95d0fc4f1bdee794e68cdbc06f8526f4b0417f9bae230ef944c49609666adc923fbd6dfd0e5ec91db524ef0fbeb572f521d26
7
+ data.tar.gz: c7aeb7db69f75723d92964142ca0a2355509049bc2df34842430fb5c9b2f33fae43e71bb763ca00ccf045d3c07377bb7b00d3a730c7b9f3f538b5bfe13959a8f
data/.travis.yml CHANGED
@@ -6,7 +6,6 @@ rvm:
6
6
  - 2.1.1
7
7
  - 2.1
8
8
  - 2.0.0
9
- - 1.9.3
10
9
  notifications:
11
10
  slack:
12
11
  secure: Zr3mKCiTb0vaTD4MPtTG8BbyYyErFuoxioM25QyrqePKVkDFeZC1MtGmg5klQQrJiWTKZPa/zB8NAHYkoUxg9I+z15JK0hYfz9KRubEpCrXCaqTC9Vzq88kJ3LN8YsTyBF66izaBH2KLsOfaJRxwplFzZqgpg4GG2DUBPtrGtes=
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.0.1
6
+ ### Fixed
7
+ * Fix Link resolution on localized content
8
+
9
+ ### Changed
10
+ * Removed dependency lock specific for Ruby < 2.0 support
11
+
5
12
  ## 1.0.0
6
13
 
7
14
  **ATTENTION**: Breaking changes on how JSON Fields are parsed. All keys are now symbolized, including
data/README.md CHANGED
@@ -372,11 +372,6 @@ first_entry = client.sync(initial: true, type: 'Entry').first_page.items.first
372
372
  first_entry.fields('de-DE') # Returns German localizations
373
373
  ```
374
374
 
375
- ## Rate-limit
376
- The library does not make assumptions on the rate limit but reacts to `HTTP 429` by raising or returning an error (see [Client Configuration Options](#client-configuration-options)).
377
- You should handle this within your code and either do the delay calculation naive (fixed amount of seconds) or more elaborated (exponential increase) depending by the structure of your code.
378
-
379
-
380
375
  ## Workarounds
381
376
 
382
377
  - 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.
data/contentful.gemspec CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'http', '~> 1.0'
19
19
  gem.add_dependency 'multi_json', '~> 1'
20
- gem.add_dependency 'json', '~> 1.8'
21
20
 
22
21
  gem.add_development_dependency 'bundler', '~> 1.5'
23
22
  gem.add_development_dependency 'rake', '~> 10'
@@ -61,14 +61,6 @@ module Contentful
61
61
  false
62
62
  end
63
63
 
64
- # Returns true if resource is localized
65
- #
66
- # @return [Boolean]
67
- def localized?(value)
68
- return false unless value.is_a? ::Hash
69
- value.keys.any? { |possible_locale| Contentful::Constants::KNOWN_LOCALES.include?(possible_locale) }
70
- end
71
-
72
64
  # Resources that don't include SystemProperties return nil for #sys
73
65
  def sys
74
66
  nil
@@ -146,7 +138,7 @@ module Contentful
146
138
  @fields = {}
147
139
 
148
140
  object['fields'].each do |field_name, nested_child_object|
149
- if localized?(nested_child_object)
141
+ if Support.localized?(nested_child_object)
150
142
  nested_child_object.each do |object_locale, real_child_object|
151
143
  @fields[object_locale] ||= {}
152
144
  @fields[object_locale].merge! extract_from_object(
@@ -58,12 +58,12 @@ module Contentful
58
58
  end
59
59
  end
60
60
 
61
- private
62
-
63
61
  def locales
64
62
  @fields.keys
65
63
  end
66
64
 
65
+ private
66
+
67
67
  def extract_fields_from_object!(object)
68
68
  initialize_fields_for_localized_resource(object)
69
69
  end
@@ -182,8 +182,17 @@ module Contentful
182
182
  @known_resources[res.type][res.id] = res if res.sys && res.id && res.type != 'Link'
183
183
  end
184
184
 
185
+ def localized_entry?(object, property_name, potential_objects)
186
+ object['sys']['type'] == 'Entry' &&
187
+ property_name == 'fields' &&
188
+ potential_objects.is_a?(::Hash) &&
189
+ potential_objects.any? { |_, p| Support.localized?(p) }
190
+ end
191
+
185
192
  def replace_children(res, object)
186
193
  object.each do |name, potential_objects|
194
+ replace_localized_children(res, object, name, potential_objects)
195
+
187
196
  detect_child_objects(potential_objects).each do |child_name, child_object|
188
197
  res.public_send(name)[child_name.to_sym] = create_resource(child_object)
189
198
  end
@@ -194,6 +203,17 @@ module Contentful
194
203
  end
195
204
  end
196
205
 
206
+ def replace_localized_children(result, object, property_name, potential_objects)
207
+ if localized_entry?(object, property_name, potential_objects)
208
+ localized_objects = potential_objects.select { |_, p| Support.localized?(p) }
209
+ localized_objects.each do |field_name, localized_object|
210
+ detect_child_objects(localized_object).each do |locale, child_object|
211
+ result.public_send(property_name, locale)[field_name.to_sym] = create_resource(child_object)
212
+ end
213
+ end
214
+ end
215
+ end
216
+
197
217
  def replace_child_array(child_array)
198
218
  child_array.map! { |resource_object| create_resource(resource_object) }
199
219
  end
@@ -214,9 +234,19 @@ module Contentful
214
234
  def replace_links_with_known_resources(res, seen_resource_ids = [])
215
235
  seen_resource_ids << res.id
216
236
 
217
- property_containers = [:properties, :sys, :fields].map do |property_container_name|
237
+ property_containers = [:properties, :sys].map do |property_container_name|
218
238
  res.public_send(property_container_name)
219
- end.compact
239
+ end
240
+
241
+ if res.is_a?(Entry)
242
+ res.locales.each do |locale|
243
+ property_containers << res.fields(locale)
244
+ end
245
+ else
246
+ property_containers << res.fields
247
+ end
248
+
249
+ property_containers.compact!
220
250
 
221
251
  property_containers.each do |property_container|
222
252
  replace_links_in_properties(property_container, seen_resource_ids)
@@ -11,6 +11,14 @@ module Contentful
11
11
  snake = String(object).gsub(/(?<!^)[A-Z]/) { "_#{$&}" }
12
12
  snake.downcase
13
13
  end
14
+
15
+ # Returns true if resource is localized
16
+ #
17
+ # @return [Boolean]
18
+ def localized?(value)
19
+ return false unless value.is_a? ::Hash
20
+ value.keys.any? { |possible_locale| Contentful::Constants::KNOWN_LOCALES.include?(possible_locale) }
21
+ end
14
22
  end
15
23
  end
16
24
  end
@@ -1,5 +1,5 @@
1
1
  # Contentful Namespace
2
2
  module Contentful
3
3
  # Gem Version
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
data/spec/entry_spec.rb CHANGED
@@ -80,6 +80,24 @@ describe Contentful::Entry do
80
80
  expect(nyancat.fields_with_locales[:name][:es]).to eq("Gato Nyan")
81
81
  }
82
82
  end
83
+
84
+ it 'can have references in multiple locales and they are properly solved' do
85
+ vcr('multi_locale_reference') {
86
+ client = create_client(
87
+ space: '1sjfpsn7l90g',
88
+ access_token: 'e451a3cdfced9000220be41ed9c899866e8d52aa430eaf7c35b09df8fc6326f9',
89
+ dynamic_entries: :auto
90
+ )
91
+
92
+ entry = client.entries(locale: '*').first
93
+
94
+ expect(entry.image).to be_a ::Contentful::Asset
95
+ expect(entry.fields('zh')[:image]).to be_a ::Contentful::Asset
96
+ expect(entry.fields('es')[:image]).to be_a ::Contentful::Asset
97
+
98
+ expect(entry.image.id).not_to eq entry.fields('zh')[:image].id
99
+ }
100
+ end
83
101
  end
84
102
  end
85
103
 
@@ -0,0 +1,214 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cdn.contentful.com/spaces/1sjfpsn7l90g/content_types?limit=1000
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContentfulGem/1.0.0
12
+ Authorization:
13
+ - Bearer e451a3cdfced9000220be41ed9c899866e8d52aa430eaf7c35b09df8fc6326f9
14
+ Content-Type:
15
+ - application/vnd.contentful.delivery.v1+json
16
+ Accept-Encoding:
17
+ - gzip
18
+ Connection:
19
+ - close
20
+ Host:
21
+ - cdn.contentful.com
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
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,X-Contentful-User-Agent
29
+ Access-Control-Allow-Methods:
30
+ - GET,HEAD,OPTIONS
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Expose-Headers:
34
+ - Etag
35
+ Access-Control-Max-Age:
36
+ - '86400'
37
+ Cache-Control:
38
+ - max-age=0
39
+ Content-Type:
40
+ - application/vnd.contentful.delivery.v1+json
41
+ Etag:
42
+ - '"a684f9ee6d6e80804ecfc6ad741f3b28"'
43
+ Server:
44
+ - Contentful
45
+ X-Content-Type-Options:
46
+ - nosniff
47
+ - nosniff
48
+ X-Contentful-Request-Id:
49
+ - eaef9f65adddf842356893d4ff94a061
50
+ Content-Length:
51
+ - '809'
52
+ Accept-Ranges:
53
+ - bytes
54
+ Date:
55
+ - Thu, 29 Sep 2016 22:12:09 GMT
56
+ Via:
57
+ - 1.1 varnish
58
+ Age:
59
+ - '3732'
60
+ Connection:
61
+ - close
62
+ X-Served-By:
63
+ - cache-gru7125-GRU
64
+ X-Cache:
65
+ - HIT
66
+ X-Cache-Hits:
67
+ - '1'
68
+ X-Timer:
69
+ - S1475187129.479343,VS0,VE0
70
+ Vary:
71
+ - Accept-Encoding
72
+ body:
73
+ encoding: ASCII-8BIT
74
+ string: |
75
+ {
76
+ "sys": {
77
+ "type": "Array"
78
+ },
79
+ "total": 1,
80
+ "skip": 0,
81
+ "limit": 1000,
82
+ "items": [
83
+ {
84
+ "sys": {
85
+ "space": {
86
+ "sys": {
87
+ "type": "Link",
88
+ "linkType": "Space",
89
+ "id": "1sjfpsn7l90g"
90
+ }
91
+ },
92
+ "id": "test",
93
+ "type": "ContentType",
94
+ "createdAt": "2016-09-29T14:46:41.071Z",
95
+ "updatedAt": "2016-09-29T14:46:41.071Z",
96
+ "revision": 1
97
+ },
98
+ "displayField": null,
99
+ "name": "Test",
100
+ "description": "",
101
+ "fields": [
102
+ {
103
+ "id": "image",
104
+ "name": "Image",
105
+ "type": "Link",
106
+ "localized": true,
107
+ "required": false,
108
+ "disabled": false,
109
+ "omitted": false,
110
+ "linkType": "Asset"
111
+ }
112
+ ]
113
+ }
114
+ ]
115
+ }
116
+ http_version:
117
+ recorded_at: Thu, 29 Sep 2016 22:12:09 GMT
118
+ - request:
119
+ method: get
120
+ uri: https://cdn.contentful.com/spaces/1sjfpsn7l90g/entries?locale=*
121
+ body:
122
+ encoding: US-ASCII
123
+ string: ''
124
+ headers:
125
+ User-Agent:
126
+ - RubyContentfulGem/1.0.0
127
+ Authorization:
128
+ - Bearer e451a3cdfced9000220be41ed9c899866e8d52aa430eaf7c35b09df8fc6326f9
129
+ Content-Type:
130
+ - application/vnd.contentful.delivery.v1+json
131
+ Accept-Encoding:
132
+ - gzip
133
+ Connection:
134
+ - close
135
+ Host:
136
+ - cdn.contentful.com
137
+ response:
138
+ status:
139
+ code: 200
140
+ message: OK
141
+ headers:
142
+ Access-Control-Allow-Headers:
143
+ - 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
144
+ Access-Control-Allow-Methods:
145
+ - GET,HEAD,OPTIONS
146
+ Access-Control-Allow-Origin:
147
+ - "*"
148
+ Access-Control-Expose-Headers:
149
+ - Etag
150
+ Access-Control-Max-Age:
151
+ - '86400'
152
+ Cache-Control:
153
+ - max-age=0
154
+ Content-Encoding:
155
+ - gzip
156
+ Content-Type:
157
+ - application/vnd.contentful.delivery.v1+json
158
+ Etag:
159
+ - W/"d74db949e37697354c70ebc8d3ac5301"
160
+ Server:
161
+ - Contentful
162
+ X-Content-Type-Options:
163
+ - nosniff
164
+ - nosniff
165
+ X-Contentful-Request-Id:
166
+ - 5a58a9b54ff533c49bab5b96f4654c08
167
+ Content-Length:
168
+ - '880'
169
+ Accept-Ranges:
170
+ - bytes
171
+ Date:
172
+ - Thu, 29 Sep 2016 22:12:14 GMT
173
+ Via:
174
+ - 1.1 varnish
175
+ Age:
176
+ - '3737'
177
+ Connection:
178
+ - close
179
+ X-Served-By:
180
+ - cache-gru7120-GRU
181
+ X-Cache:
182
+ - HIT
183
+ X-Cache-Hits:
184
+ - '20'
185
+ X-Timer:
186
+ - S1475187134.558426,VS0,VE0
187
+ Vary:
188
+ - Accept-Encoding
189
+ body:
190
+ encoding: ASCII-8BIT
191
+ string: !binary |-
192
+ H4sIAAAAAAAAA+2WXW/aMBSG7/srUK4HsR0nwb1DVYWqbu06itA2VVVCHDAk
193
+ ISOhDCr++2yHgCEhoxtrVWm5gPjj2Ofj9eM8n9VqWrJItPPaM3/ljXQRU97S
194
+ WtOps9B43+qDmJNOUifg/VC2kjGLeQPIRsBCloohkLVZSkOx4He5YLbs3i5y
195
+ pyR2+mKrfEbWqfgiOmRn7tNHFo01sef24btH4/u1zx254t4E5olwYDLy4ySy
196
+ AwIGIqr8WW3eZZzZo2U2GI0vR8ubEQmv+gzRRfv2qsPulPU3jl1G6XShDvSn
197
+ 1Emp1xJ50RCAVh2QOiL3EJ+bxrmJGwayv6kGs9h7mcGUPrGETaK8JmvP+5Mo
198
+ pVG6zsjpUnuhrFua4JQm6YHErvO6SbDmMxp4W80J1zUWOoOCGmhU73b2JFIi
199
+ pXXsFTKRMt0KpZUkNN0TivBBSsX6EkxG5NPVz9v5AMzR+MeF0+sgNTZ+KFQJ
200
+ qfnQ6G5cMjb1gK0lJrpP5C/qtT/H8QIHTqvXG3RZrw1Qp3Wsv8vhq+d3OR6G
201
+ 0wu2vJ7dddugG369prhX4e/2iOZKkv+iBg+SQCzqBzNPybyWFThn0JZCpcUo
202
+ JVHpTFnN48tWxqONzA4RqUpcmUAPFHxHhhuMF5SuVbMJWQ1sQZVN3ONqOpWa
203
+ qHzaFlBhbAkERHJZGuxjgHfnINBcpz8eTCezyKtLYtSJZTcRqBEL1GwEdgi0
204
+ kxCfVa2rglIWeTYVt52m63KXpLHmqj8L+Guoq8XTy+uhG8SEyIYQEAqJQ7Hp
205
+ Iui6AGMXYdegff1ALI88lkceS2MUD4qM8mjqsKAIGel1wpYiecjEBjF2MS3H
206
+ yyArBuTgnHmpgAHfumjKx4eUDYbiQuMTFPxl1ioQRY9ym66XFwW4cUL5cfFH
207
+ ke9ebVks+iimO/f53ukpoiMPbVvxEjy/NyIcuLJORgQTk5cSoWjyj4iQYeCJ
208
+ 0XkdQoMgYL4pDMpLoWMLuzYGDml6HAkEmCY2fdv2TMt3DBe5GWfqahin4AA0
209
+ kFk8zMdxgGOoaKpywMJ/y4Fi7aqD/o8ACdMduOZfreVfVSdDALatlyKgaPJa
210
+ CMBvi4DSUuhO0ycAmMQ1Xd+zELAJbELso75BPd9xcBEBuPo0HPMpAA3YtN4V
211
+ An4T9GkQIL8LHvjv6mx19gvB1oxYBREAAA==
212
+ http_version:
213
+ recorded_at: Thu, 29 Sep 2016 22:12:14 GMT
214
+ recorded_with: VCR 3.0.3
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: 1.0.0
4
+ version: 1.0.1
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: 2016-08-24 00:00:00.000000000 Z
13
+ date: 2016-10-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http
@@ -40,20 +40,6 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '1'
43
- - !ruby/object:Gem::Dependency
44
- name: json
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '1.8'
50
- type: :runtime
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '1.8'
57
43
  - !ruby/object:Gem::Dependency
58
44
  name: bundler
59
45
  requirement: !ruby/object:Gem::Requirement
@@ -400,6 +386,7 @@ files:
400
386
  - spec/fixtures/vcr_cassettes/linkField.yml
401
387
  - spec/fixtures/vcr_cassettes/locale.yml
402
388
  - spec/fixtures/vcr_cassettes/location.yml
389
+ - spec/fixtures/vcr_cassettes/multi_locale_reference.yml
403
390
  - spec/fixtures/vcr_cassettes/not_found.yml
404
391
  - spec/fixtures/vcr_cassettes/nyancat.yml
405
392
  - spec/fixtures/vcr_cassettes/ratelimit.yml
@@ -496,6 +483,7 @@ test_files:
496
483
  - spec/fixtures/vcr_cassettes/linkField.yml
497
484
  - spec/fixtures/vcr_cassettes/locale.yml
498
485
  - spec/fixtures/vcr_cassettes/location.yml
486
+ - spec/fixtures/vcr_cassettes/multi_locale_reference.yml
499
487
  - spec/fixtures/vcr_cassettes/not_found.yml
500
488
  - spec/fixtures/vcr_cassettes/nyancat.yml
501
489
  - spec/fixtures/vcr_cassettes/ratelimit.yml