contentful 1.2.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/LICENSE.txt +1 -0
  4. data/README.md +8 -0
  5. data/contentful.gemspec +2 -1
  6. data/examples/custom_classes.rb +23 -26
  7. data/examples/raise_errors.rb +2 -2
  8. data/lib/contentful.rb +0 -1
  9. data/lib/contentful/array.rb +27 -19
  10. data/lib/contentful/array_like.rb +51 -0
  11. data/lib/contentful/asset.rb +43 -11
  12. data/lib/contentful/base_resource.rb +87 -0
  13. data/lib/contentful/client.rb +43 -34
  14. data/lib/contentful/coercions.rb +116 -0
  15. data/lib/contentful/content_type.rb +23 -8
  16. data/lib/contentful/content_type_cache.rb +26 -0
  17. data/lib/contentful/deleted_asset.rb +2 -5
  18. data/lib/contentful/deleted_entry.rb +2 -5
  19. data/lib/contentful/entry.rb +55 -33
  20. data/lib/contentful/error.rb +1 -1
  21. data/lib/contentful/field.rb +37 -9
  22. data/lib/contentful/fields_resource.rb +115 -0
  23. data/lib/contentful/file.rb +7 -8
  24. data/lib/contentful/link.rb +3 -6
  25. data/lib/contentful/locale.rb +6 -6
  26. data/lib/contentful/location.rb +7 -5
  27. data/lib/contentful/resource_builder.rb +72 -226
  28. data/lib/contentful/space.rb +16 -6
  29. data/lib/contentful/support.rb +41 -3
  30. data/lib/contentful/sync_page.rb +17 -10
  31. data/lib/contentful/version.rb +1 -1
  32. data/spec/array_spec.rb +4 -8
  33. data/spec/client_class_spec.rb +12 -23
  34. data/spec/client_configuration_spec.rb +13 -23
  35. data/spec/content_type_spec.rb +0 -5
  36. data/spec/entry_spec.rb +130 -125
  37. data/spec/error_requests_spec.rb +1 -1
  38. data/spec/field_spec.rb +0 -5
  39. data/spec/file_spec.rb +0 -5
  40. data/spec/fixtures/vcr_cassettes/entry.yml +54 -64
  41. data/spec/fixtures/vcr_cassettes/entry/include_resolution.yml +101 -0
  42. data/spec/fixtures/vcr_cassettes/entry/marshall.yml +227 -251
  43. data/spec/fixtures/vcr_cassettes/entry/raw.yml +88 -124
  44. data/spec/fixtures/vcr_cassettes/entry_locales.yml +56 -74
  45. data/spec/fixtures/vcr_cassettes/human.yml +63 -40
  46. data/spec/fixtures/vcr_cassettes/location.yml +99 -211
  47. data/spec/fixtures/vcr_cassettes/multi_locale_array_reference.yml +12 -16
  48. data/spec/fixtures/vcr_cassettes/not_found.yml +26 -21
  49. data/spec/fixtures/vcr_cassettes/nyancat.yml +53 -63
  50. data/spec/fixtures/vcr_cassettes/ratelimit.yml +1 -1
  51. data/spec/fixtures/vcr_cassettes/reloaded_entry.yml +54 -64
  52. data/spec/fixtures/vcr_cassettes/unauthorized.yml +1 -1
  53. data/spec/fixtures/vcr_cassettes/unavailable.yml +27 -15
  54. data/spec/link_spec.rb +3 -2
  55. data/spec/locale_spec.rb +0 -5
  56. data/spec/location_spec.rb +1 -6
  57. data/spec/request_spec.rb +3 -2
  58. data/spec/resource_building_spec.rb +10 -7
  59. data/spec/response_spec.rb +1 -1
  60. data/spec/space_spec.rb +0 -5
  61. data/spec/spec_helper.rb +3 -0
  62. data/spec/support/json_responses.rb +3 -3
  63. data/spec/sync_page_spec.rb +1 -6
  64. data/spec/sync_spec.rb +11 -7
  65. metadata +69 -20
  66. data/examples/dynamic_entries.rb +0 -124
  67. data/examples/resource_mapping.rb +0 -32
  68. data/lib/contentful/constants.rb +0 -504
  69. data/lib/contentful/dynamic_entry.rb +0 -57
  70. data/lib/contentful/resource.rb +0 -239
  71. data/lib/contentful/resource/array_like.rb +0 -39
  72. data/lib/contentful/resource/asset_fields.rb +0 -58
  73. data/lib/contentful/resource/custom_resource.rb +0 -29
  74. data/lib/contentful/resource/fields.rb +0 -73
  75. data/lib/contentful/resource/system_properties.rb +0 -55
  76. data/spec/coercions_spec.rb +0 -23
  77. data/spec/dynamic_entry_spec.rb +0 -75
  78. data/spec/resource_spec.rb +0 -79
@@ -1,124 +0,0 @@
1
- require 'contentful'
2
-
3
- # A DynamicEntry is a resource classes, specifically for one ContentType
4
- # This is the manual way of creating a dynamic class. This should not be
5
- # neceassary in :auto mode
6
-
7
- client = Contentful::Client.new(
8
- space: 'cfexampleapi',
9
- access_token: 'b4c0n73n7fu1',
10
- dynamic_entries: :manual,
11
- )
12
-
13
- cat = client.content_type('cat')
14
- CatEntry = Contentful::DynamicEntry.create(cat)
15
- client.register_dynamic_entry 'cat', CatEntry
16
-
17
- # The CatEntry behaves just like a normal entry, but it has knowlegde about the entry fields.
18
- # It will create getter methods and convert field contents to the proper type:
19
-
20
- nyancat = client.entry('nyancat')
21
- p nyancat.is_a? CatEntry # => true
22
- p nyancat.fields[:name] # => "Nyan Cat" # This would also be possible with a non-dynamic entry
23
- p nyancat.name # => "Nyan Cat"
24
-
25
- # You don't need to initialize a ContentType resource to create a DynamicEntry
26
- # You could also pass the content type's JSON representation:
27
-
28
- SuperCatEntry = Contentful::DynamicEntry.create <<JSON
29
- {
30
- "fields": [
31
- {
32
- "id": "name",
33
- "name": "Name",
34
- "type": "Text",
35
- "required": true,
36
- "localized": true
37
- },
38
- {
39
- "id": "likes",
40
- "name": "Likes",
41
- "type": "Array",
42
- "required": false,
43
- "localized": false,
44
- "items": {
45
- "type": "Symbol"
46
- }
47
- },
48
- {
49
- "id": "color",
50
- "name": "Color",
51
- "type": "Symbol",
52
- "required": false,
53
- "localized": false
54
- },
55
- {
56
- "id": "bestFriend",
57
- "name": "Best Friend",
58
- "type": "Link",
59
- "required": false,
60
- "localized": false,
61
- "linkType": "Entry"
62
- },
63
- {
64
- "id": "birthday",
65
- "name": "Birthday",
66
- "type": "Date",
67
- "required": false,
68
- "localized": false
69
- },
70
- {
71
- "id": "lifes",
72
- "name": "Lifes left",
73
- "type": "Integer",
74
- "required": false,
75
- "localized": false,
76
- "disabled": true
77
- },
78
- {
79
- "id": "lives",
80
- "name": "Lives left",
81
- "type": "Integer",
82
- "required": false,
83
- "localized": false
84
- },
85
- {
86
- "id": "image",
87
- "name": "Image",
88
- "required": false,
89
- "localized": false,
90
- "type": "Link",
91
- "linkType": "Asset"
92
- }
93
- ],
94
- "name": "Cat",
95
- "displayField": "name",
96
- "description": "Meow.",
97
- "sys": {
98
- "space": {
99
- "sys": {
100
- "type": "Link",
101
- "linkType": "Space",
102
- "id": "cfexampleapi"
103
- }
104
- },
105
- "type": "ContentType",
106
- "id": "cat",
107
- "revision": 2,
108
- "createdAt": "2013-06-27T22:46:12.852Z",
109
- "updatedAt": "2013-09-02T13:14:47.863Z"
110
- }
111
- }
112
- JSON
113
-
114
- # AUTO MODE - All entries will be converted to dynamic entries
115
-
116
- client = Contentful::Client.new(
117
- space: 'cfexampleapi',
118
- access_token: 'b4c0n73n7fu1',
119
- dynamic_entries: :auto,
120
- )
121
-
122
- p happycat = client.entry('happycat') # #<Contentful::DynamicEntry[cat]:10078260 @fields={:name=>"Happy Cat" ...
123
- p happycat.is_a? Contentful::DynamicEntry # true
124
- p happycat.color # gray
@@ -1,32 +0,0 @@
1
- # Using the :resource_mapping configuration, you can register your own classes to be used
2
- # for the results from contentful.
3
- #
4
- # The key of the resource_mapping hash defines the resource type (object["sys"]["type"]) and the value is:
5
- # - the Class to use
6
- # - a Proc, that returns the Class to use
7
- # - a Symbol for a method of the ResourceBuilder object
8
-
9
- require 'contentful'
10
-
11
- class MyBetterArray < Contentful::Array
12
- # e.g. define more methods that you need
13
- def last
14
- items.last
15
- end
16
- end
17
-
18
- client = Contentful::Client.new(
19
- space: 'cfexampleapi',
20
- access_token: 'b4c0n73n7fu1',
21
- resource_mapping: {
22
- 'Array' => MyBetterArray,
23
- 'Asset' => ->(_json_object)do
24
- # might return different class if some criteria is matched
25
- Contentful::Asset
26
- end,
27
- }
28
- )
29
-
30
- assets = client.assets
31
- p assets.class # => MyBetterArray
32
- p assets.last # => #<Contentful::Asset ...
@@ -1,504 +0,0 @@
1
- module Contentful
2
- # Module containing useful Constants
3
- module Constants
4
- # List of Locales known by Contentful
5
- KNOWN_LOCALES = [
6
- 'zh',
7
- 'en',
8
- 'es',
9
- 'hi',
10
- 'ru',
11
- 'ar',
12
- 'pt',
13
- 'bn',
14
- 'fr',
15
- 'ms',
16
- 'tr',
17
- 'de',
18
- 'ja',
19
- 'fa',
20
- 'ur',
21
- 'pa',
22
- 'vi',
23
- 'id',
24
- 'ko',
25
- 'te',
26
- 'mr',
27
- 'it',
28
- 'th',
29
- 'my',
30
- 'kn',
31
- 'gu',
32
- 'pl',
33
- 'af',
34
- 'af-NA',
35
- 'af-ZA',
36
- 'agq',
37
- 'agq-CM',
38
- 'ak',
39
- 'ak-GH',
40
- 'sq',
41
- 'sq-AL',
42
- 'am',
43
- 'am-ET',
44
- 'ar-DZ',
45
- 'ar-BH',
46
- 'ar-EG',
47
- 'ar-IQ',
48
- 'ar-JO',
49
- 'ar-KW',
50
- 'ar-LB',
51
- 'ar-LY',
52
- 'ar-MA',
53
- 'ar-OM',
54
- 'ar-QA',
55
- 'ar-SA',
56
- 'ar-SD',
57
- 'ar-SY',
58
- 'ar-TN',
59
- 'ar-AE',
60
- 'ar-YE',
61
- 'ar-001',
62
- 'hy',
63
- 'hy-AM',
64
- 'as',
65
- 'as-IN',
66
- 'asa',
67
- 'asa-TZ',
68
- 'az',
69
- 'az-Cyrl',
70
- 'az-Cyrl-AZ',
71
- 'az-Latn',
72
- 'az-Latn-AZ',
73
- 'ksf',
74
- 'ksf-CM',
75
- 'bm',
76
- 'bm-ML',
77
- 'bas',
78
- 'bas-CM',
79
- 'eu',
80
- 'eu-ES',
81
- 'be',
82
- 'be-BY',
83
- 'bem',
84
- 'bem-ZM',
85
- 'bez',
86
- 'bez-TZ',
87
- 'bn-BD',
88
- 'bn-IN',
89
- 'brx',
90
- 'brx-IN',
91
- 'bs',
92
- 'bs-BA',
93
- 'br',
94
- 'br-FR',
95
- 'bg',
96
- 'bg-BG',
97
- 'my-MM',
98
- 'ca',
99
- 'ca-ES',
100
- 'tzm',
101
- 'tzm-Latn',
102
- 'tzm-Latn-MA',
103
- 'chr',
104
- 'chr-US',
105
- 'cgg',
106
- 'cgg-UG',
107
- 'zh-CN',
108
- 'zh-Hans',
109
- 'zh-Hans-CN',
110
- 'zh-Hans-HK',
111
- 'zh-Hans-MO',
112
- 'zh-Hans-SG',
113
- 'zh-Hant',
114
- 'zh-Hant-HK',
115
- 'zh-Hant-MO',
116
- 'zh-Hant-TW',
117
- 'swc',
118
- 'swc-CD',
119
- 'kw',
120
- 'kw-GB',
121
- 'hr',
122
- 'hr-HR',
123
- 'cs',
124
- 'cs-CZ',
125
- 'da',
126
- 'da-DK',
127
- 'dua',
128
- 'dua-CM',
129
- 'nl',
130
- 'nl-AW',
131
- 'nl-BE',
132
- 'nl-CW',
133
- 'nl-NL',
134
- 'nl-SX',
135
- 'ebu',
136
- 'ebu-KE',
137
- 'en-AS',
138
- 'en-AU',
139
- 'en-BB',
140
- 'en-BE',
141
- 'en-BZ',
142
- 'en-BM',
143
- 'en-BW',
144
- 'en-CA',
145
- 'en-EU',
146
- 'en-GU',
147
- 'en-GY',
148
- 'en-HK',
149
- 'en-IN',
150
- 'en-IE',
151
- 'en-JM',
152
- 'en-MT',
153
- 'en-MH',
154
- 'en-MU',
155
- 'en-NA',
156
- 'en-NZ',
157
- 'en-MP',
158
- 'en-PK',
159
- 'en-PH',
160
- 'en-SG',
161
- 'en-ZA',
162
- 'en-TT',
163
- 'en-US-POSIX',
164
- 'en-UM',
165
- 'en-VI',
166
- 'en-GB',
167
- 'en-US',
168
- 'en-ZW',
169
- 'eo',
170
- 'et',
171
- 'et-EE',
172
- 'ee',
173
- 'ee-GH',
174
- 'ee-TG',
175
- 'ewo',
176
- 'ewo-CM',
177
- 'fo',
178
- 'fo-FO',
179
- 'fil',
180
- 'fil-PH',
181
- 'fi',
182
- 'fi-FI',
183
- 'fr-BE',
184
- 'fr-BJ',
185
- 'fr-BF',
186
- 'fr-BI',
187
- 'fr-CM',
188
- 'fr-CA',
189
- 'fr-CF',
190
- 'fr-TD',
191
- 'fr-KM',
192
- 'fr-CG',
193
- 'fr-CD',
194
- 'fr-CI',
195
- 'fr-DJ',
196
- 'fr-GQ',
197
- 'fr-FR',
198
- 'fr-GF',
199
- 'fr-GA',
200
- 'fr-GP',
201
- 'fr-GN',
202
- 'fr-LU',
203
- 'fr-MG',
204
- 'fr-ML',
205
- 'fr-MQ',
206
- 'fr-YT',
207
- 'fr-MC',
208
- 'fr-NE',
209
- 'fr-RW',
210
- 'fr-RE',
211
- 'fr-BL',
212
- 'fr-MF',
213
- 'fr-SN',
214
- 'fr-CH',
215
- 'fr-TG',
216
- 'ff',
217
- 'ff-SN',
218
- 'gl',
219
- 'gl-ES',
220
- 'lg',
221
- 'lg-UG',
222
- 'ka',
223
- 'ka-GE',
224
- 'de-AT',
225
- 'de-BE',
226
- 'de-DE',
227
- 'de-LI',
228
- 'de-LU',
229
- 'de-CH',
230
- 'el',
231
- 'el-CY',
232
- 'el-GR',
233
- 'gu-IN',
234
- 'guz',
235
- 'guz-KE',
236
- 'ha',
237
- 'ha-Latn',
238
- 'ha-Latn-GH',
239
- 'ha-Latn-NE',
240
- 'ha-Latn-NG',
241
- 'haw',
242
- 'haw-US',
243
- 'he',
244
- 'he-IL',
245
- 'hi-IN',
246
- 'hu',
247
- 'hu-HU',
248
- 'is',
249
- 'is-IS',
250
- 'ig',
251
- 'ig-NG',
252
- 'id-ID',
253
- 'ga',
254
- 'ga-IE',
255
- 'it-IT',
256
- 'it-CH',
257
- 'ja-JP',
258
- 'dyo',
259
- 'dyo-SN',
260
- 'kea',
261
- 'kea-CV',
262
- 'kab',
263
- 'kab-DZ',
264
- 'kl',
265
- 'kl-GL',
266
- 'kln',
267
- 'kln-KE',
268
- 'kam',
269
- 'kam-KE',
270
- 'kn-IN',
271
- 'kk',
272
- 'kk-Cyrl',
273
- 'kk-Cyrl-KZ',
274
- 'km',
275
- 'km-KH',
276
- 'ki',
277
- 'ki-KE',
278
- 'rw',
279
- 'rw-RW',
280
- 'kok',
281
- 'kok-IN',
282
- 'ko-KR',
283
- 'khq',
284
- 'khq-ML',
285
- 'ses',
286
- 'ses-ML',
287
- 'nmg',
288
- 'nmg-CM',
289
- 'lag',
290
- 'lag-TZ',
291
- 'lv',
292
- 'lv-LV',
293
- 'ln',
294
- 'ln-CG',
295
- 'ln-CD',
296
- 'lt',
297
- 'lt-LT',
298
- 'lu',
299
- 'lu-CD',
300
- 'luo',
301
- 'luo-KE',
302
- 'luy',
303
- 'luy-KE',
304
- 'mk',
305
- 'mk-MK',
306
- 'jmc',
307
- 'jmc-TZ',
308
- 'mgh',
309
- 'mgh-MZ',
310
- 'kde',
311
- 'kde-TZ',
312
- 'mg',
313
- 'mg-MG',
314
- 'ms-BN',
315
- 'ms-MY',
316
- 'ml',
317
- 'ml-IN',
318
- 'mt',
319
- 'mt-MT',
320
- 'gv',
321
- 'gv-GB',
322
- 'mr-IN',
323
- 'mas',
324
- 'mas-KE',
325
- 'mas-TZ',
326
- 'mer',
327
- 'mer-KE',
328
- 'mfe',
329
- 'mfe-MU',
330
- 'mua',
331
- 'mua-CM',
332
- 'naq',
333
- 'naq-NA',
334
- 'ne',
335
- 'ne-IN',
336
- 'ne-NP',
337
- 'nd',
338
- 'nd-ZW',
339
- 'nb',
340
- 'nb-NO',
341
- 'nn',
342
- 'nn-NO',
343
- 'nus',
344
- 'nus-SD',
345
- 'nyn',
346
- 'nyn-UG',
347
- 'or',
348
- 'or-IN',
349
- 'om',
350
- 'om-ET',
351
- 'om-KE',
352
- 'ps',
353
- 'ps-AF',
354
- 'fa-AF',
355
- 'fa-IR',
356
- 'pl-PL',
357
- 'pt-AO',
358
- 'pt-BR',
359
- 'pt-GW',
360
- 'pt-MZ',
361
- 'pt-PT',
362
- 'pt-ST',
363
- 'pa-Arab',
364
- 'pa-Arab-PK',
365
- 'pa-Guru',
366
- 'pa-Guru-IN',
367
- 'ro',
368
- 'ro-MD',
369
- 'ro-RO',
370
- 'rm',
371
- 'rm-CH',
372
- 'rof',
373
- 'rof-TZ',
374
- 'rn',
375
- 'rn-BI',
376
- 'ru-MD',
377
- 'ru-RU',
378
- 'ru-UA',
379
- 'rwk',
380
- 'rwk-TZ',
381
- 'saq',
382
- 'saq-KE',
383
- 'sg',
384
- 'sg-CF',
385
- 'sbp',
386
- 'sbp-TZ',
387
- 'seh',
388
- 'seh-MZ',
389
- 'sr',
390
- 'sr-Cyrl',
391
- 'sr-Cyrl-BA',
392
- 'sr-Cyrl-ME',
393
- 'sr-Cyrl-RS',
394
- 'sr-Latn',
395
- 'sr-Latn-BA',
396
- 'sr-Latn-ME',
397
- 'sr-Latn-RS',
398
- 'ksb',
399
- 'ksb-TZ',
400
- 'sn',
401
- 'sn-ZW',
402
- 'ii',
403
- 'ii-CN',
404
- 'si',
405
- 'si-LK',
406
- 'sk',
407
- 'sk-SK',
408
- 'sl',
409
- 'sl-SI',
410
- 'xog',
411
- 'xog-UG',
412
- 'so',
413
- 'so-DJ',
414
- 'so-ET',
415
- 'so-KE',
416
- 'so-SO',
417
- 'es-AR',
418
- 'es-BO',
419
- 'es-CL',
420
- 'es-CO',
421
- 'es-CR',
422
- 'es-DO',
423
- 'es-EC',
424
- 'es-SV',
425
- 'es-GQ',
426
- 'es-GT',
427
- 'es-HN',
428
- 'es-419',
429
- 'es-MX',
430
- 'es-NI',
431
- 'es-PA',
432
- 'es-PY',
433
- 'es-PE',
434
- 'es-PR',
435
- 'es-ES',
436
- 'es-US',
437
- 'es-UY',
438
- 'es-VE',
439
- 'sw',
440
- 'sw-KE',
441
- 'sw-TZ',
442
- 'sv',
443
- 'sv-FI',
444
- 'sv-SE',
445
- 'gsw',
446
- 'gsw-CH',
447
- 'shi',
448
- 'shi-Latn',
449
- 'shi-Latn-MA',
450
- 'shi-Tfng',
451
- 'shi-Tfng-MA',
452
- 'dav',
453
- 'dav-KE',
454
- 'ta',
455
- 'ta-IN',
456
- 'ta-LK',
457
- 'twq',
458
- 'twq-NE',
459
- 'te-IN',
460
- 'teo',
461
- 'teo-KE',
462
- 'teo-UG',
463
- 'th-TH',
464
- 'bo',
465
- 'bo-CN',
466
- 'bo-IN',
467
- 'ti',
468
- 'ti-ER',
469
- 'ti-ET',
470
- 'to',
471
- 'to-TO',
472
- 'tr-TR',
473
- 'uk',
474
- 'uk-UA',
475
- 'ur-IN',
476
- 'ur-PK',
477
- 'uz',
478
- 'uz-Arab',
479
- 'uz-Arab-AF',
480
- 'uz-Cyrl',
481
- 'uz-Cyrl-UZ',
482
- 'uz-Latn',
483
- 'uz-Latn-UZ',
484
- 'vai',
485
- 'vai-Latn',
486
- 'vai-Latn-LR',
487
- 'vai-Vaii',
488
- 'vai-Vaii-LR',
489
- 'vi-VN',
490
- 'vun',
491
- 'vun-TZ',
492
- 'cy',
493
- 'cy-GB',
494
- 'yav',
495
- 'yav-CM',
496
- 'yo',
497
- 'yo-NG',
498
- 'dje',
499
- 'dje-NE',
500
- 'zu',
501
- 'zu-ZA'
502
- ]
503
- end
504
- end