contentful 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/Guardfile +42 -0
- data/contentful.gemspec +2 -0
- data/lib/contentful/constants.rb +502 -0
- data/lib/contentful/resource.rb +11 -13
- data/lib/contentful/resource/fields.rb +20 -0
- data/lib/contentful/resource_builder.rb +1 -3
- data/lib/contentful/sync_page.rb +0 -4
- data/lib/contentful/version.rb +1 -1
- data/spec/entry_spec.rb +25 -3
- metadata +33 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b4c5fc8a4dc2ae13b7ee0fe9e0444e995b921bf
|
4
|
+
data.tar.gz: 9f38b091341e8b0137292070a7ae9b10ccdcab7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b09b93dab0ba708a502cb898dd3dd05f23693053b517594f2f18faf2b0955ddc468868ccb9828eb9fdff50ebf951d45310d5b29e4e373bda90969dbeec714fe3
|
7
|
+
data.tar.gz: 3d0aaeca5389a70b4d7e957e982996dbf16e9593a5fb6df3f529ce6ffc7474c07b669460d300c681406edc57dd86d6ec257b8b6e309a107608bad5234b1f1e4c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Change Log
|
2
2
|
## Unreleased
|
3
3
|
|
4
|
+
## 0.8.0
|
5
|
+
### Changed
|
6
|
+
* Unified Locale Handling [#73](https://github.com/contentful/contentful.rb/issues/73)
|
7
|
+
|
4
8
|
## 0.7.0
|
5
9
|
### Added
|
6
10
|
* Add support for querying a field's `linkType` [#75](https://github.com/contentful/contentful.rb/pull/75)
|
data/Guardfile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
28
|
+
require "guard/rspec/dsl"
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
end
|
data/contentful.gemspec
CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.add_development_dependency 'rake', '~> 10'
|
23
23
|
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
24
24
|
|
25
|
+
gem.add_development_dependency 'guard'
|
26
|
+
gem.add_development_dependency 'guard-rspec'
|
25
27
|
gem.add_development_dependency 'rspec', '~> 2'
|
26
28
|
gem.add_development_dependency 'rr'
|
27
29
|
gem.add_development_dependency 'vcr'
|
@@ -0,0 +1,502 @@
|
|
1
|
+
module Contentful
|
2
|
+
module Constants
|
3
|
+
KNOWN_LOCALES = [
|
4
|
+
"zh",
|
5
|
+
"en",
|
6
|
+
"es",
|
7
|
+
"hi",
|
8
|
+
"ru",
|
9
|
+
"ar",
|
10
|
+
"pt",
|
11
|
+
"bn",
|
12
|
+
"fr",
|
13
|
+
"ms",
|
14
|
+
"tr",
|
15
|
+
"de",
|
16
|
+
"ja",
|
17
|
+
"fa",
|
18
|
+
"ur",
|
19
|
+
"pa",
|
20
|
+
"vi",
|
21
|
+
"id",
|
22
|
+
"ko",
|
23
|
+
"te",
|
24
|
+
"mr",
|
25
|
+
"it",
|
26
|
+
"th",
|
27
|
+
"my",
|
28
|
+
"kn",
|
29
|
+
"gu",
|
30
|
+
"pl",
|
31
|
+
"af",
|
32
|
+
"af-NA",
|
33
|
+
"af-ZA",
|
34
|
+
"agq",
|
35
|
+
"agq-CM",
|
36
|
+
"ak",
|
37
|
+
"ak-GH",
|
38
|
+
"sq",
|
39
|
+
"sq-AL",
|
40
|
+
"am",
|
41
|
+
"am-ET",
|
42
|
+
"ar-DZ",
|
43
|
+
"ar-BH",
|
44
|
+
"ar-EG",
|
45
|
+
"ar-IQ",
|
46
|
+
"ar-JO",
|
47
|
+
"ar-KW",
|
48
|
+
"ar-LB",
|
49
|
+
"ar-LY",
|
50
|
+
"ar-MA",
|
51
|
+
"ar-OM",
|
52
|
+
"ar-QA",
|
53
|
+
"ar-SA",
|
54
|
+
"ar-SD",
|
55
|
+
"ar-SY",
|
56
|
+
"ar-TN",
|
57
|
+
"ar-AE",
|
58
|
+
"ar-YE",
|
59
|
+
"ar-001",
|
60
|
+
"hy",
|
61
|
+
"hy-AM",
|
62
|
+
"as",
|
63
|
+
"as-IN",
|
64
|
+
"asa",
|
65
|
+
"asa-TZ",
|
66
|
+
"az",
|
67
|
+
"az-Cyrl",
|
68
|
+
"az-Cyrl-AZ",
|
69
|
+
"az-Latn",
|
70
|
+
"az-Latn-AZ",
|
71
|
+
"ksf",
|
72
|
+
"ksf-CM",
|
73
|
+
"bm",
|
74
|
+
"bm-ML",
|
75
|
+
"bas",
|
76
|
+
"bas-CM",
|
77
|
+
"eu",
|
78
|
+
"eu-ES",
|
79
|
+
"be",
|
80
|
+
"be-BY",
|
81
|
+
"bem",
|
82
|
+
"bem-ZM",
|
83
|
+
"bez",
|
84
|
+
"bez-TZ",
|
85
|
+
"bn-BD",
|
86
|
+
"bn-IN",
|
87
|
+
"brx",
|
88
|
+
"brx-IN",
|
89
|
+
"bs",
|
90
|
+
"bs-BA",
|
91
|
+
"br",
|
92
|
+
"br-FR",
|
93
|
+
"bg",
|
94
|
+
"bg-BG",
|
95
|
+
"my-MM",
|
96
|
+
"ca",
|
97
|
+
"ca-ES",
|
98
|
+
"tzm",
|
99
|
+
"tzm-Latn",
|
100
|
+
"tzm-Latn-MA",
|
101
|
+
"chr",
|
102
|
+
"chr-US",
|
103
|
+
"cgg",
|
104
|
+
"cgg-UG",
|
105
|
+
"zh-CN",
|
106
|
+
"zh-Hans",
|
107
|
+
"zh-Hans-CN",
|
108
|
+
"zh-Hans-HK",
|
109
|
+
"zh-Hans-MO",
|
110
|
+
"zh-Hans-SG",
|
111
|
+
"zh-Hant",
|
112
|
+
"zh-Hant-HK",
|
113
|
+
"zh-Hant-MO",
|
114
|
+
"zh-Hant-TW",
|
115
|
+
"swc",
|
116
|
+
"swc-CD",
|
117
|
+
"kw",
|
118
|
+
"kw-GB",
|
119
|
+
"hr",
|
120
|
+
"hr-HR",
|
121
|
+
"cs",
|
122
|
+
"cs-CZ",
|
123
|
+
"da",
|
124
|
+
"da-DK",
|
125
|
+
"dua",
|
126
|
+
"dua-CM",
|
127
|
+
"nl",
|
128
|
+
"nl-AW",
|
129
|
+
"nl-BE",
|
130
|
+
"nl-CW",
|
131
|
+
"nl-NL",
|
132
|
+
"nl-SX",
|
133
|
+
"ebu",
|
134
|
+
"ebu-KE",
|
135
|
+
"en-AS",
|
136
|
+
"en-AU",
|
137
|
+
"en-BB",
|
138
|
+
"en-BE",
|
139
|
+
"en-BZ",
|
140
|
+
"en-BM",
|
141
|
+
"en-BW",
|
142
|
+
"en-CA",
|
143
|
+
"en-EU",
|
144
|
+
"en-GU",
|
145
|
+
"en-GY",
|
146
|
+
"en-HK",
|
147
|
+
"en-IN",
|
148
|
+
"en-IE",
|
149
|
+
"en-JM",
|
150
|
+
"en-MT",
|
151
|
+
"en-MH",
|
152
|
+
"en-MU",
|
153
|
+
"en-NA",
|
154
|
+
"en-NZ",
|
155
|
+
"en-MP",
|
156
|
+
"en-PK",
|
157
|
+
"en-PH",
|
158
|
+
"en-SG",
|
159
|
+
"en-ZA",
|
160
|
+
"en-TT",
|
161
|
+
"en-US-POSIX",
|
162
|
+
"en-UM",
|
163
|
+
"en-VI",
|
164
|
+
"en-GB",
|
165
|
+
"en-US",
|
166
|
+
"en-ZW",
|
167
|
+
"eo",
|
168
|
+
"et",
|
169
|
+
"et-EE",
|
170
|
+
"ee",
|
171
|
+
"ee-GH",
|
172
|
+
"ee-TG",
|
173
|
+
"ewo",
|
174
|
+
"ewo-CM",
|
175
|
+
"fo",
|
176
|
+
"fo-FO",
|
177
|
+
"fil",
|
178
|
+
"fil-PH",
|
179
|
+
"fi",
|
180
|
+
"fi-FI",
|
181
|
+
"fr-BE",
|
182
|
+
"fr-BJ",
|
183
|
+
"fr-BF",
|
184
|
+
"fr-BI",
|
185
|
+
"fr-CM",
|
186
|
+
"fr-CA",
|
187
|
+
"fr-CF",
|
188
|
+
"fr-TD",
|
189
|
+
"fr-KM",
|
190
|
+
"fr-CG",
|
191
|
+
"fr-CD",
|
192
|
+
"fr-CI",
|
193
|
+
"fr-DJ",
|
194
|
+
"fr-GQ",
|
195
|
+
"fr-FR",
|
196
|
+
"fr-GF",
|
197
|
+
"fr-GA",
|
198
|
+
"fr-GP",
|
199
|
+
"fr-GN",
|
200
|
+
"fr-LU",
|
201
|
+
"fr-MG",
|
202
|
+
"fr-ML",
|
203
|
+
"fr-MQ",
|
204
|
+
"fr-YT",
|
205
|
+
"fr-MC",
|
206
|
+
"fr-NE",
|
207
|
+
"fr-RW",
|
208
|
+
"fr-RE",
|
209
|
+
"fr-BL",
|
210
|
+
"fr-MF",
|
211
|
+
"fr-SN",
|
212
|
+
"fr-CH",
|
213
|
+
"fr-TG",
|
214
|
+
"ff",
|
215
|
+
"ff-SN",
|
216
|
+
"gl",
|
217
|
+
"gl-ES",
|
218
|
+
"lg",
|
219
|
+
"lg-UG",
|
220
|
+
"ka",
|
221
|
+
"ka-GE",
|
222
|
+
"de-AT",
|
223
|
+
"de-BE",
|
224
|
+
"de-DE",
|
225
|
+
"de-LI",
|
226
|
+
"de-LU",
|
227
|
+
"de-CH",
|
228
|
+
"el",
|
229
|
+
"el-CY",
|
230
|
+
"el-GR",
|
231
|
+
"gu-IN",
|
232
|
+
"guz",
|
233
|
+
"guz-KE",
|
234
|
+
"ha",
|
235
|
+
"ha-Latn",
|
236
|
+
"ha-Latn-GH",
|
237
|
+
"ha-Latn-NE",
|
238
|
+
"ha-Latn-NG",
|
239
|
+
"haw",
|
240
|
+
"haw-US",
|
241
|
+
"he",
|
242
|
+
"he-IL",
|
243
|
+
"hi-IN",
|
244
|
+
"hu",
|
245
|
+
"hu-HU",
|
246
|
+
"is",
|
247
|
+
"is-IS",
|
248
|
+
"ig",
|
249
|
+
"ig-NG",
|
250
|
+
"id-ID",
|
251
|
+
"ga",
|
252
|
+
"ga-IE",
|
253
|
+
"it-IT",
|
254
|
+
"it-CH",
|
255
|
+
"ja-JP",
|
256
|
+
"dyo",
|
257
|
+
"dyo-SN",
|
258
|
+
"kea",
|
259
|
+
"kea-CV",
|
260
|
+
"kab",
|
261
|
+
"kab-DZ",
|
262
|
+
"kl",
|
263
|
+
"kl-GL",
|
264
|
+
"kln",
|
265
|
+
"kln-KE",
|
266
|
+
"kam",
|
267
|
+
"kam-KE",
|
268
|
+
"kn-IN",
|
269
|
+
"kk",
|
270
|
+
"kk-Cyrl",
|
271
|
+
"kk-Cyrl-KZ",
|
272
|
+
"km",
|
273
|
+
"km-KH",
|
274
|
+
"ki",
|
275
|
+
"ki-KE",
|
276
|
+
"rw",
|
277
|
+
"rw-RW",
|
278
|
+
"kok",
|
279
|
+
"kok-IN",
|
280
|
+
"ko-KR",
|
281
|
+
"khq",
|
282
|
+
"khq-ML",
|
283
|
+
"ses",
|
284
|
+
"ses-ML",
|
285
|
+
"nmg",
|
286
|
+
"nmg-CM",
|
287
|
+
"lag",
|
288
|
+
"lag-TZ",
|
289
|
+
"lv",
|
290
|
+
"lv-LV",
|
291
|
+
"ln",
|
292
|
+
"ln-CG",
|
293
|
+
"ln-CD",
|
294
|
+
"lt",
|
295
|
+
"lt-LT",
|
296
|
+
"lu",
|
297
|
+
"lu-CD",
|
298
|
+
"luo",
|
299
|
+
"luo-KE",
|
300
|
+
"luy",
|
301
|
+
"luy-KE",
|
302
|
+
"mk",
|
303
|
+
"mk-MK",
|
304
|
+
"jmc",
|
305
|
+
"jmc-TZ",
|
306
|
+
"mgh",
|
307
|
+
"mgh-MZ",
|
308
|
+
"kde",
|
309
|
+
"kde-TZ",
|
310
|
+
"mg",
|
311
|
+
"mg-MG",
|
312
|
+
"ms-BN",
|
313
|
+
"ms-MY",
|
314
|
+
"ml",
|
315
|
+
"ml-IN",
|
316
|
+
"mt",
|
317
|
+
"mt-MT",
|
318
|
+
"gv",
|
319
|
+
"gv-GB",
|
320
|
+
"mr-IN",
|
321
|
+
"mas",
|
322
|
+
"mas-KE",
|
323
|
+
"mas-TZ",
|
324
|
+
"mer",
|
325
|
+
"mer-KE",
|
326
|
+
"mfe",
|
327
|
+
"mfe-MU",
|
328
|
+
"mua",
|
329
|
+
"mua-CM",
|
330
|
+
"naq",
|
331
|
+
"naq-NA",
|
332
|
+
"ne",
|
333
|
+
"ne-IN",
|
334
|
+
"ne-NP",
|
335
|
+
"nd",
|
336
|
+
"nd-ZW",
|
337
|
+
"nb",
|
338
|
+
"nb-NO",
|
339
|
+
"nn",
|
340
|
+
"nn-NO",
|
341
|
+
"nus",
|
342
|
+
"nus-SD",
|
343
|
+
"nyn",
|
344
|
+
"nyn-UG",
|
345
|
+
"or",
|
346
|
+
"or-IN",
|
347
|
+
"om",
|
348
|
+
"om-ET",
|
349
|
+
"om-KE",
|
350
|
+
"ps",
|
351
|
+
"ps-AF",
|
352
|
+
"fa-AF",
|
353
|
+
"fa-IR",
|
354
|
+
"pl-PL",
|
355
|
+
"pt-AO",
|
356
|
+
"pt-BR",
|
357
|
+
"pt-GW",
|
358
|
+
"pt-MZ",
|
359
|
+
"pt-PT",
|
360
|
+
"pt-ST",
|
361
|
+
"pa-Arab",
|
362
|
+
"pa-Arab-PK",
|
363
|
+
"pa-Guru",
|
364
|
+
"pa-Guru-IN",
|
365
|
+
"ro",
|
366
|
+
"ro-MD",
|
367
|
+
"ro-RO",
|
368
|
+
"rm",
|
369
|
+
"rm-CH",
|
370
|
+
"rof",
|
371
|
+
"rof-TZ",
|
372
|
+
"rn",
|
373
|
+
"rn-BI",
|
374
|
+
"ru-MD",
|
375
|
+
"ru-RU",
|
376
|
+
"ru-UA",
|
377
|
+
"rwk",
|
378
|
+
"rwk-TZ",
|
379
|
+
"saq",
|
380
|
+
"saq-KE",
|
381
|
+
"sg",
|
382
|
+
"sg-CF",
|
383
|
+
"sbp",
|
384
|
+
"sbp-TZ",
|
385
|
+
"seh",
|
386
|
+
"seh-MZ",
|
387
|
+
"sr",
|
388
|
+
"sr-Cyrl",
|
389
|
+
"sr-Cyrl-BA",
|
390
|
+
"sr-Cyrl-ME",
|
391
|
+
"sr-Cyrl-RS",
|
392
|
+
"sr-Latn",
|
393
|
+
"sr-Latn-BA",
|
394
|
+
"sr-Latn-ME",
|
395
|
+
"sr-Latn-RS",
|
396
|
+
"ksb",
|
397
|
+
"ksb-TZ",
|
398
|
+
"sn",
|
399
|
+
"sn-ZW",
|
400
|
+
"ii",
|
401
|
+
"ii-CN",
|
402
|
+
"si",
|
403
|
+
"si-LK",
|
404
|
+
"sk",
|
405
|
+
"sk-SK",
|
406
|
+
"sl",
|
407
|
+
"sl-SI",
|
408
|
+
"xog",
|
409
|
+
"xog-UG",
|
410
|
+
"so",
|
411
|
+
"so-DJ",
|
412
|
+
"so-ET",
|
413
|
+
"so-KE",
|
414
|
+
"so-SO",
|
415
|
+
"es-AR",
|
416
|
+
"es-BO",
|
417
|
+
"es-CL",
|
418
|
+
"es-CO",
|
419
|
+
"es-CR",
|
420
|
+
"es-DO",
|
421
|
+
"es-EC",
|
422
|
+
"es-SV",
|
423
|
+
"es-GQ",
|
424
|
+
"es-GT",
|
425
|
+
"es-HN",
|
426
|
+
"es-419",
|
427
|
+
"es-MX",
|
428
|
+
"es-NI",
|
429
|
+
"es-PA",
|
430
|
+
"es-PY",
|
431
|
+
"es-PE",
|
432
|
+
"es-PR",
|
433
|
+
"es-ES",
|
434
|
+
"es-US",
|
435
|
+
"es-UY",
|
436
|
+
"es-VE",
|
437
|
+
"sw",
|
438
|
+
"sw-KE",
|
439
|
+
"sw-TZ",
|
440
|
+
"sv",
|
441
|
+
"sv-FI",
|
442
|
+
"sv-SE",
|
443
|
+
"gsw",
|
444
|
+
"gsw-CH",
|
445
|
+
"shi",
|
446
|
+
"shi-Latn",
|
447
|
+
"shi-Latn-MA",
|
448
|
+
"shi-Tfng",
|
449
|
+
"shi-Tfng-MA",
|
450
|
+
"dav",
|
451
|
+
"dav-KE",
|
452
|
+
"ta",
|
453
|
+
"ta-IN",
|
454
|
+
"ta-LK",
|
455
|
+
"twq",
|
456
|
+
"twq-NE",
|
457
|
+
"te-IN",
|
458
|
+
"teo",
|
459
|
+
"teo-KE",
|
460
|
+
"teo-UG",
|
461
|
+
"th-TH",
|
462
|
+
"bo",
|
463
|
+
"bo-CN",
|
464
|
+
"bo-IN",
|
465
|
+
"ti",
|
466
|
+
"ti-ER",
|
467
|
+
"ti-ET",
|
468
|
+
"to",
|
469
|
+
"to-TO",
|
470
|
+
"tr-TR",
|
471
|
+
"uk",
|
472
|
+
"uk-UA",
|
473
|
+
"ur-IN",
|
474
|
+
"ur-PK",
|
475
|
+
"uz",
|
476
|
+
"uz-Arab",
|
477
|
+
"uz-Arab-AF",
|
478
|
+
"uz-Cyrl",
|
479
|
+
"uz-Cyrl-UZ",
|
480
|
+
"uz-Latn",
|
481
|
+
"uz-Latn-UZ",
|
482
|
+
"vai",
|
483
|
+
"vai-Latn",
|
484
|
+
"vai-Latn-LR",
|
485
|
+
"vai-Vaii",
|
486
|
+
"vai-Vaii-LR",
|
487
|
+
"vi-VN",
|
488
|
+
"vun",
|
489
|
+
"vun-TZ",
|
490
|
+
"cy",
|
491
|
+
"cy-GB",
|
492
|
+
"yav",
|
493
|
+
"yav-CM",
|
494
|
+
"yo",
|
495
|
+
"yo-NG",
|
496
|
+
"dje",
|
497
|
+
"dje-NE",
|
498
|
+
"zu",
|
499
|
+
"zu-ZA"
|
500
|
+
]
|
501
|
+
end
|
502
|
+
end
|
data/lib/contentful/resource.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'resource/system_properties'
|
2
|
+
require 'contentful/constants'
|
2
3
|
require 'date'
|
3
4
|
|
4
5
|
module Contentful
|
@@ -21,15 +22,15 @@ module Contentful
|
|
21
22
|
|
22
23
|
attr_reader :properties, :request, :client, :default_locale
|
23
24
|
|
24
|
-
def initialize(object = nil, request = nil, client = nil,
|
25
|
+
def initialize(object = nil, request = nil, client = nil, default_locale = Contentful::Client::DEFAULT_CONFIGURATION[:default_locale])
|
25
26
|
self.class.update_coercions!
|
26
|
-
@nested_locale_fields = nested_locale_fields
|
27
27
|
@default_locale = default_locale
|
28
28
|
|
29
29
|
@properties = extract_from_object(object, :property,
|
30
30
|
self.class.property_coercions.keys)
|
31
31
|
@request = request
|
32
32
|
@client = client
|
33
|
+
@api_object = object
|
33
34
|
end
|
34
35
|
|
35
36
|
def inspect(info = nil)
|
@@ -42,9 +43,9 @@ module Contentful
|
|
42
43
|
false
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
def localized?(value)
|
47
|
+
return false unless value.is_a? ::Hash
|
48
|
+
value.keys.any? { |possible_locale| Contentful::Constants::KNOWN_LOCALES.include?(possible_locale) }
|
48
49
|
end
|
49
50
|
|
50
51
|
# Resources that don't include SystemProperties return nil for #sys
|
@@ -72,17 +73,18 @@ module Contentful
|
|
72
73
|
def initialize_fields_for_localized_resource(object)
|
73
74
|
@fields = {}
|
74
75
|
|
75
|
-
|
76
|
-
|
76
|
+
object['fields'].each do |field_name, nested_child_object|
|
77
|
+
if localized?(nested_child_object)
|
77
78
|
nested_child_object.each do |object_locale, real_child_object|
|
78
79
|
@fields[object_locale] ||= {}
|
79
80
|
@fields[object_locale].merge! extract_from_object(
|
80
81
|
{ field_name => real_child_object }, :fields
|
81
82
|
)
|
82
83
|
end
|
84
|
+
else
|
85
|
+
@fields[locale] ||= {}
|
86
|
+
@fields[locale].merge! extract_from_object({ field_name => nested_child_object }, :fields)
|
83
87
|
end
|
84
|
-
else
|
85
|
-
@fields[locale] = extract_from_object object['fields'], :fields
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
@@ -150,10 +152,6 @@ module Contentful
|
|
150
152
|
# Register the resources properties on class level by using the #property method
|
151
153
|
module ClassMethods
|
152
154
|
# By default, fields come flattened in the current locale. This is different for sync
|
153
|
-
def nested_locale_fields?
|
154
|
-
false
|
155
|
-
end
|
156
|
-
|
157
155
|
def property_coercions
|
158
156
|
@property_coercions ||= {}
|
159
157
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'contentful/constants'
|
2
|
+
|
1
3
|
module Contentful
|
2
4
|
module Resource
|
3
5
|
# Include this module into your Resource class to enable it
|
@@ -7,9 +9,23 @@ module Contentful
|
|
7
9
|
module Fields
|
8
10
|
# Returns all fields of the asset
|
9
11
|
def fields(wanted_locale = default_locale)
|
12
|
+
wanted_locale = wanted_locale.to_s
|
10
13
|
@fields.has_key?(wanted_locale) ? @fields[wanted_locale] : @fields[locale]
|
11
14
|
end
|
12
15
|
|
16
|
+
# Returns all fields of the asset with locales nested by field
|
17
|
+
def fields_with_locales
|
18
|
+
remapped_fields = {}
|
19
|
+
locales.each do |locale|
|
20
|
+
fields(locale).each do |name, value|
|
21
|
+
remapped_fields[name] ||= {}
|
22
|
+
remapped_fields[name][locale.to_sym] = value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
remapped_fields
|
27
|
+
end
|
28
|
+
|
13
29
|
def initialize(object = nil, *)
|
14
30
|
super
|
15
31
|
extract_fields_from_object! object if object
|
@@ -25,6 +41,10 @@ module Contentful
|
|
25
41
|
|
26
42
|
private
|
27
43
|
|
44
|
+
def locales
|
45
|
+
@fields.keys
|
46
|
+
end
|
47
|
+
|
28
48
|
def extract_fields_from_object!(object)
|
29
49
|
initialize_fields_for_localized_resource(object)
|
30
50
|
end
|
@@ -33,7 +33,6 @@ module Contentful
|
|
33
33
|
@client = client
|
34
34
|
@included_resources = {}
|
35
35
|
@known_resources = Hash.new { |h, k| h[k] = {} }
|
36
|
-
@nested_locales = false
|
37
36
|
@default_locale = default_locale
|
38
37
|
@resource_mapping = default_resource_mapping.merge(resource_mapping)
|
39
38
|
@entry_mapping = default_entry_mapping.merge(entry_mapping)
|
@@ -73,8 +72,7 @@ module Contentful
|
|
73
72
|
# Creates a single resource from the response object
|
74
73
|
def create_resource(object)
|
75
74
|
res_class = detect_resource_class(object)
|
76
|
-
|
77
|
-
res = res_class.new(object, response.request, client, @nested_locales, @default_locale)
|
75
|
+
res = res_class.new(object, response.request, client, @default_locale)
|
78
76
|
|
79
77
|
add_to_known_resources res
|
80
78
|
replace_children res, object
|
data/lib/contentful/sync_page.rb
CHANGED
data/lib/contentful/version.rb
CHANGED
data/spec/entry_spec.rb
CHANGED
@@ -54,10 +54,32 @@ describe Contentful::Entry do
|
|
54
54
|
it 'can handle multiple locales' do
|
55
55
|
vcr('entry_locales') {
|
56
56
|
cat = create_client.entries(locale: "*").items.first
|
57
|
-
expect(cat.fields
|
58
|
-
expect(cat.fields[:name]
|
57
|
+
expect(cat.fields('en-US')[:name]).to eq "Nyan Cat"
|
58
|
+
expect(cat.fields('es')[:name]).to eq "Gato Nyan"
|
59
|
+
|
60
|
+
|
61
|
+
expect(cat.fields(:'en-US')[:name]).to eq "Nyan Cat"
|
62
|
+
expect(cat.fields(:es)[:name]).to eq "Gato Nyan"
|
59
63
|
}
|
60
64
|
end
|
61
|
-
end
|
62
65
|
|
66
|
+
describe '#fields_with_locales' do
|
67
|
+
it 'can handle entries with just 1 locale' do
|
68
|
+
vcr('entry') {
|
69
|
+
nyancat = create_client.entry('nyancat')
|
70
|
+
expect(nyancat.fields_with_locales[:name].size).to eq(1)
|
71
|
+
expect(nyancat.fields_with_locales[:name][:'en-US']).to eq("Nyan Cat")
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'can handle entries with multiple locales' do
|
76
|
+
vcr('entry_locales') {
|
77
|
+
nyancat = create_client.entries(locale: "*").items.first
|
78
|
+
expect(nyancat.fields_with_locales[:name].size).to eq(2)
|
79
|
+
expect(nyancat.fields_with_locales[:name][:'en-US']).to eq("Nyan Cat")
|
80
|
+
expect(nyancat.fields_with_locales[:name][:es]).to eq("Gato Nyan")
|
81
|
+
}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
63
85
|
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: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH (Jan Lelis)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-12-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: http
|
@@ -81,6 +81,34 @@ dependencies:
|
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0.2'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: guard
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: guard-rspec
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
84
112
|
- !ruby/object:Gem::Dependency
|
85
113
|
name: rspec
|
86
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,6 +183,7 @@ files:
|
|
155
183
|
- CHANGELOG.md
|
156
184
|
- Gemfile
|
157
185
|
- Gemfile.lock
|
186
|
+
- Guardfile
|
158
187
|
- LICENSE.txt
|
159
188
|
- README.md
|
160
189
|
- RELEASE.md
|
@@ -170,6 +199,7 @@ files:
|
|
170
199
|
- lib/contentful/array.rb
|
171
200
|
- lib/contentful/asset.rb
|
172
201
|
- lib/contentful/client.rb
|
202
|
+
- lib/contentful/constants.rb
|
173
203
|
- lib/contentful/content_type.rb
|
174
204
|
- lib/contentful/deleted_asset.rb
|
175
205
|
- lib/contentful/deleted_entry.rb
|
@@ -279,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
279
309
|
version: '0'
|
280
310
|
requirements: []
|
281
311
|
rubyforge_project:
|
282
|
-
rubygems_version: 2.
|
312
|
+
rubygems_version: 2.4.5.1
|
283
313
|
signing_key:
|
284
314
|
specification_version: 4
|
285
315
|
summary: contentful
|