contentful 2.12.0 → 2.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +69 -1
  3. data/README.md +24 -13
  4. data/lib/contentful/array.rb +14 -6
  5. data/lib/contentful/array_like.rb +11 -2
  6. data/lib/contentful/asset.rb +10 -4
  7. data/lib/contentful/base_resource.rb +29 -6
  8. data/lib/contentful/client.rb +4 -3
  9. data/lib/contentful/coercions.rb +1 -4
  10. data/lib/contentful/entry.rb +9 -5
  11. data/lib/contentful/fields_resource.rb +7 -11
  12. data/lib/contentful/includes.rb +74 -0
  13. data/lib/contentful/request.rb +6 -1
  14. data/lib/contentful/resource_builder.rb +15 -12
  15. data/lib/contentful/support.rb +0 -35
  16. data/lib/contentful/version.rb +1 -1
  17. metadata +15 -370
  18. data/.gitignore +0 -7
  19. data/.rspec +0 -1
  20. data/.rubocop.yml +0 -28
  21. data/.rubocop_todo.yml +0 -35
  22. data/.travis.yml +0 -13
  23. data/.yardopts +0 -4
  24. data/Gemfile +0 -9
  25. data/Gemfile.lock +0 -152
  26. data/Guardfile +0 -24
  27. data/RELEASE.md +0 -8
  28. data/Rakefile +0 -33
  29. data/contentful.gemspec +0 -44
  30. data/coverage/.last_run.json +0 -5
  31. data/coverage/.resultset.json +0 -2419
  32. data/coverage/.resultset.json.lock +0 -0
  33. data/coverage/assets/0.10.2/application.css +0 -799
  34. data/coverage/assets/0.10.2/application.js +0 -1707
  35. data/coverage/assets/0.10.2/colorbox/border.png +0 -0
  36. data/coverage/assets/0.10.2/colorbox/controls.png +0 -0
  37. data/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
  38. data/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
  39. data/coverage/assets/0.10.2/favicon_green.png +0 -0
  40. data/coverage/assets/0.10.2/favicon_red.png +0 -0
  41. data/coverage/assets/0.10.2/favicon_yellow.png +0 -0
  42. data/coverage/assets/0.10.2/loading.gif +0 -0
  43. data/coverage/assets/0.10.2/magnify.png +0 -0
  44. data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  45. data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  46. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  47. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  48. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  49. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  50. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  51. data/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  52. data/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
  53. data/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  54. data/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
  55. data/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
  56. data/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  57. data/coverage/index.html +0 -15071
  58. data/doc/Contentful/AccessDenied.html +0 -159
  59. data/doc/Contentful/Array.html +0 -765
  60. data/doc/Contentful/ArrayCoercion.html +0 -242
  61. data/doc/Contentful/ArrayLike.html +0 -625
  62. data/doc/Contentful/Asset.html +0 -487
  63. data/doc/Contentful/BadGateway.html +0 -159
  64. data/doc/Contentful/BadRequest.html +0 -159
  65. data/doc/Contentful/BaseCoercion.html +0 -445
  66. data/doc/Contentful/BaseResource.html +0 -599
  67. data/doc/Contentful/BooleanCoercion.html +0 -242
  68. data/doc/Contentful/Client.html +0 -1740
  69. data/doc/Contentful/ContentType.html +0 -618
  70. data/doc/Contentful/ContentTypeCache.html +0 -428
  71. data/doc/Contentful/DateCoercion.html +0 -244
  72. data/doc/Contentful/DeletedAsset.html +0 -157
  73. data/doc/Contentful/DeletedEntry.html +0 -157
  74. data/doc/Contentful/EmptyFieldError.html +0 -217
  75. data/doc/Contentful/Entry.html +0 -334
  76. data/doc/Contentful/Error.html +0 -410
  77. data/doc/Contentful/Field.html +0 -936
  78. data/doc/Contentful/FieldsResource.html +0 -583
  79. data/doc/Contentful/File.html +0 -218
  80. data/doc/Contentful/FloatCoercion.html +0 -238
  81. data/doc/Contentful/IntegerCoercion.html +0 -238
  82. data/doc/Contentful/Link.html +0 -249
  83. data/doc/Contentful/LinkCoercion.html +0 -158
  84. data/doc/Contentful/Locale.html +0 -537
  85. data/doc/Contentful/Location.html +0 -383
  86. data/doc/Contentful/LocationCoercion.html +0 -238
  87. data/doc/Contentful/NotFound.html +0 -159
  88. data/doc/Contentful/ObjectCoercion.html +0 -238
  89. data/doc/Contentful/RateLimitExceeded.html +0 -346
  90. data/doc/Contentful/Request.html +0 -887
  91. data/doc/Contentful/ResourceBuilder.html +0 -978
  92. data/doc/Contentful/ResourceReferences.html +0 -254
  93. data/doc/Contentful/Response.html +0 -710
  94. data/doc/Contentful/RichTextCoercion.html +0 -238
  95. data/doc/Contentful/ServerError.html +0 -159
  96. data/doc/Contentful/ServiceUnavailable.html +0 -159
  97. data/doc/Contentful/Space.html +0 -393
  98. data/doc/Contentful/StringCoercion.html +0 -242
  99. data/doc/Contentful/StructuredTextCoercion.html +0 -238
  100. data/doc/Contentful/Support.html +0 -788
  101. data/doc/Contentful/SymbolCoercion.html +0 -169
  102. data/doc/Contentful/Sync.html +0 -653
  103. data/doc/Contentful/SyncPage.html +0 -807
  104. data/doc/Contentful/TextCoercion.html +0 -169
  105. data/doc/Contentful/Unauthorized.html +0 -159
  106. data/doc/Contentful/UnparsableJson.html +0 -159
  107. data/doc/Contentful/UnparsableResource.html +0 -135
  108. data/doc/Contentful.html +0 -157
  109. data/doc/_index.html +0 -563
  110. data/doc/class_list.html +0 -51
  111. data/doc/css/common.css +0 -1
  112. data/doc/css/full_list.css +0 -58
  113. data/doc/css/style.css +0 -496
  114. data/doc/file.CHANGELOG.html +0 -729
  115. data/doc/file.LICENSE.html +0 -70
  116. data/doc/file.README.html +0 -925
  117. data/doc/file_list.html +0 -66
  118. data/doc/frames.html +0 -17
  119. data/doc/index.html +0 -925
  120. data/doc/js/app.js +0 -292
  121. data/doc/js/full_list.js +0 -216
  122. data/doc/js/jquery.js +0 -4
  123. data/doc/method_list.html +0 -1171
  124. data/doc/top-level-namespace.html +0 -110
  125. data/examples/custom_classes.rb +0 -39
  126. data/examples/example_queries.rb +0 -26
  127. data/examples/raise_errors.rb +0 -20
  128. data/examples/raw_mode.rb +0 -14
  129. data/spec/array_spec.rb +0 -122
  130. data/spec/asset_spec.rb +0 -192
  131. data/spec/auto_includes_spec.rb +0 -12
  132. data/spec/client_class_spec.rb +0 -86
  133. data/spec/client_configuration_spec.rb +0 -377
  134. data/spec/content_type_spec.rb +0 -49
  135. data/spec/deleted_asset_spec.rb +0 -38
  136. data/spec/deleted_entry_spec.rb +0 -38
  137. data/spec/entry_spec.rb +0 -688
  138. data/spec/error_class_spec.rb +0 -327
  139. data/spec/error_requests_spec.rb +0 -87
  140. data/spec/field_spec.rb +0 -95
  141. data/spec/file_spec.rb +0 -33
  142. data/spec/fixtures/json_responses/400_details_errors_object.json +0 -14
  143. data/spec/fixtures/json_responses/400_details_errors_string.json +0 -12
  144. data/spec/fixtures/json_responses/400_details_string.json +0 -8
  145. data/spec/fixtures/json_responses/403_reasons.json +0 -13
  146. data/spec/fixtures/json_responses/404_details_string.json +0 -8
  147. data/spec/fixtures/json_responses/404_id.json +0 -11
  148. data/spec/fixtures/json_responses/404_sys_type.json +0 -12
  149. data/spec/fixtures/json_responses/404_type.json +0 -10
  150. data/spec/fixtures/json_responses/content_type.json +0 -83
  151. data/spec/fixtures/json_responses/default_400.json +0 -7
  152. data/spec/fixtures/json_responses/default_401.json +0 -7
  153. data/spec/fixtures/json_responses/default_403.json +0 -7
  154. data/spec/fixtures/json_responses/default_404.json +0 -7
  155. data/spec/fixtures/json_responses/default_429.json +0 -7
  156. data/spec/fixtures/json_responses/default_500.json +0 -7
  157. data/spec/fixtures/json_responses/default_502.json +0 -7
  158. data/spec/fixtures/json_responses/default_503.json +0 -7
  159. data/spec/fixtures/json_responses/includes.json +0 -111
  160. data/spec/fixtures/json_responses/link_array.json +0 -43
  161. data/spec/fixtures/json_responses/not_found.json +0 -13
  162. data/spec/fixtures/json_responses/nyancat.json +0 -48
  163. data/spec/fixtures/json_responses/other_error.json +0 -9
  164. data/spec/fixtures/json_responses/other_error_no_details.json +0 -8
  165. data/spec/fixtures/json_responses/other_error_no_message.json +0 -8
  166. data/spec/fixtures/json_responses/other_error_no_request_id.json +0 -8
  167. data/spec/fixtures/json_responses/other_error_nothing.json +0 -6
  168. data/spec/fixtures/json_responses/self_link.json +0 -82
  169. data/spec/fixtures/json_responses/unparsable.json +0 -13
  170. data/spec/fixtures/vcr_cassettes/array/marshal_custom_classes.yml +0 -159
  171. data/spec/fixtures/vcr_cassettes/array/nested_resources.yml +0 -159
  172. data/spec/fixtures/vcr_cassettes/array.yml +0 -288
  173. data/spec/fixtures/vcr_cassettes/arrayField.yml +0 -87
  174. data/spec/fixtures/vcr_cassettes/array_page_1.yml +0 -106
  175. data/spec/fixtures/vcr_cassettes/array_page_2.yml +0 -73
  176. data/spec/fixtures/vcr_cassettes/asset/select_empty_array.yml +0 -104
  177. data/spec/fixtures/vcr_cassettes/asset/select_no_sys.yml +0 -119
  178. data/spec/fixtures/vcr_cassettes/asset/select_one_field.yml +0 -97
  179. data/spec/fixtures/vcr_cassettes/asset/select_only_sys.yml +0 -88
  180. data/spec/fixtures/vcr_cassettes/asset.yml +0 -96
  181. data/spec/fixtures/vcr_cassettes/assets/issues_129.yml +0 -90
  182. data/spec/fixtures/vcr_cassettes/assets/issues_jekyll_46.yml +0 -115
  183. data/spec/fixtures/vcr_cassettes/bad_request.yml +0 -76
  184. data/spec/fixtures/vcr_cassettes/content_type.yml +0 -147
  185. data/spec/fixtures/vcr_cassettes/entries/empty_fields.yml +0 -246
  186. data/spec/fixtures/vcr_cassettes/entries/issue_117.yml +0 -201
  187. data/spec/fixtures/vcr_cassettes/entries/issue_125.yml +0 -198
  188. data/spec/fixtures/vcr_cassettes/entries/rich_text.yml +0 -1707
  189. data/spec/fixtures/vcr_cassettes/entries/rich_text_hydration_issue.yml +0 -460
  190. data/spec/fixtures/vcr_cassettes/entries/rich_text_nested_fields.yml +0 -653
  191. data/spec/fixtures/vcr_cassettes/entries/rich_text_unresolved_relationships.yml +0 -983
  192. data/spec/fixtures/vcr_cassettes/entries/unresolvable_filter.yml +0 -159
  193. data/spec/fixtures/vcr_cassettes/entries/unresolvable_filter_deeply_nested.yml +0 -167
  194. data/spec/fixtures/vcr_cassettes/entries.yml +0 -561
  195. data/spec/fixtures/vcr_cassettes/entry/custom_resource.yml +0 -168
  196. data/spec/fixtures/vcr_cassettes/entry/include_resolution.yml +0 -101
  197. data/spec/fixtures/vcr_cassettes/entry/include_resolution_uniques.yml +0 -81
  198. data/spec/fixtures/vcr_cassettes/entry/json_objects.yml +0 -88
  199. data/spec/fixtures/vcr_cassettes/entry/json_objects_client.yml +0 -86
  200. data/spec/fixtures/vcr_cassettes/entry/marshal_138.yml +0 -159
  201. data/spec/fixtures/vcr_cassettes/entry/marshal_unpublished.yml +0 -303
  202. data/spec/fixtures/vcr_cassettes/entry/marshall.yml +0 -293
  203. data/spec/fixtures/vcr_cassettes/entry/raw.yml +0 -201
  204. data/spec/fixtures/vcr_cassettes/entry/search_link_to_asset.yml +0 -81
  205. data/spec/fixtures/vcr_cassettes/entry/search_link_to_entry.yml +0 -81
  206. data/spec/fixtures/vcr_cassettes/entry/search_link_to_entry_with_custom_query.yml +0 -115
  207. data/spec/fixtures/vcr_cassettes/entry/select_empty_array.yml +0 -111
  208. data/spec/fixtures/vcr_cassettes/entry/select_no_sys.yml +0 -102
  209. data/spec/fixtures/vcr_cassettes/entry/select_one_field.yml +0 -76
  210. data/spec/fixtures/vcr_cassettes/entry/select_one_field_proper.yml +0 -114
  211. data/spec/fixtures/vcr_cassettes/entry/select_only_sys.yml +0 -111
  212. data/spec/fixtures/vcr_cassettes/entry.yml +0 -102
  213. data/spec/fixtures/vcr_cassettes/entry_cache.yml +0 -288
  214. data/spec/fixtures/vcr_cassettes/entry_locales.yml +0 -104
  215. data/spec/fixtures/vcr_cassettes/field.yml +0 -147
  216. data/spec/fixtures/vcr_cassettes/human.yml +0 -118
  217. data/spec/fixtures/vcr_cassettes/linkField.yml +0 -83
  218. data/spec/fixtures/vcr_cassettes/locale.yml +0 -83
  219. data/spec/fixtures/vcr_cassettes/locale_from_environment.yml +0 -121
  220. data/spec/fixtures/vcr_cassettes/location.yml +0 -193
  221. data/spec/fixtures/vcr_cassettes/multi_locale_array_reference.yml +0 -196
  222. data/spec/fixtures/vcr_cassettes/multi_locale_reference.yml +0 -214
  223. data/spec/fixtures/vcr_cassettes/not_found.yml +0 -76
  224. data/spec/fixtures/vcr_cassettes/nyancat.yml +0 -102
  225. data/spec/fixtures/vcr_cassettes/ratelimit.yml +0 -64
  226. data/spec/fixtures/vcr_cassettes/ratelimit_retry.yml +0 -294
  227. data/spec/fixtures/vcr_cassettes/reloaded_entry.yml +0 -102
  228. data/spec/fixtures/vcr_cassettes/space.yml +0 -83
  229. data/spec/fixtures/vcr_cassettes/sync_deleted_asset.yml +0 -174
  230. data/spec/fixtures/vcr_cassettes/sync_deleted_entry.yml +0 -89
  231. data/spec/fixtures/vcr_cassettes/sync_deletion.yml +0 -191
  232. data/spec/fixtures/vcr_cassettes/sync_environment.yml +0 -81
  233. data/spec/fixtures/vcr_cassettes/sync_page.yml +0 -637
  234. data/spec/fixtures/vcr_cassettes/sync_page_2.yml +0 -71
  235. data/spec/fixtures/vcr_cassettes/sync_page_short.yml +0 -106
  236. data/spec/fixtures/vcr_cassettes/unauthorized.yml +0 -64
  237. data/spec/fixtures/vcr_cassettes/unavailable.yml +0 -76
  238. data/spec/link_spec.rb +0 -50
  239. data/spec/locale_spec.rb +0 -37
  240. data/spec/location_spec.rb +0 -25
  241. data/spec/request_spec.rb +0 -57
  242. data/spec/resource_building_spec.rb +0 -31
  243. data/spec/response_spec.rb +0 -62
  244. data/spec/space_spec.rb +0 -31
  245. data/spec/spec_helper.rb +0 -14
  246. data/spec/support/client.rb +0 -6
  247. data/spec/support/json_responses.rb +0 -18
  248. data/spec/support/vcr.rb +0 -16
  249. data/spec/sync_page_spec.rb +0 -103
  250. data/spec/sync_spec.rb +0 -180
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee3c004cc764ee56ec8a0f8a9cf739f5e5ab10e8fda5c327e1708829b8585145
4
- data.tar.gz: 57d48057485ff6260801e2090bd3dd37e71c1fb6afb53628f1f1e93bc5eabb3f
3
+ metadata.gz: 44bcfad09bdb03cc6460ebf0ac778f89e1b2820b9434f76bbbc297f63f84f7c7
4
+ data.tar.gz: a36e3d13ed3b67c501c34ceb7c777f60592188944905048839720d48490886d4
5
5
  SHA512:
6
- metadata.gz: 88eb373835acf4f0cf9d90a48c407fa082efb9e73052c33b0c89c4ed1f685cf37d6ea6f90306a683e2b4f49c972e4aa0f3c5784fe4c2e44a4da0124373d5ec85
7
- data.tar.gz: 5d7f33c79174fb1867a6509af1c59a76afec8b04d5a3cc557117d0e90cbd394bdd3243522404bba18e210d50aa941c773614a2815f868e1358f28dae0e665898
6
+ metadata.gz: 171a6d3f675e9596a9353c40d43ab5ee81fabf755407e13933fdf04a7934d1db058d33480b25a305609b52a27e00d46f6790a1186608495815b93cc29c0648d9
7
+ data.tar.gz: 763fc3a03017b6c10a5fdee30d6bd71eca0f0015aacbf4e3f250186985d347a20363d817265c4e6aa777b06b73df0817c865d4d9ddba8b3e0cace9b177eb62fb
data/CHANGELOG.md CHANGED
@@ -1,6 +1,74 @@
1
1
  # Change Log
2
2
 
3
- ## Unreleased
3
+ ## 2.17.0
4
+
5
+ ### Updated
6
+ * Updated `http` gem version
7
+
8
+ ### Changed
9
+ * CI/CD vendor from travis to circleci
10
+ * Refactored `includes` to be a model (`Contentful::Includes`) with a lookup table instead of a plain Ruby array, for improved performance when `include_level` is set. Two related methods from `Support` have been moved to this new class. Any code that uses the undocumented `includes_for_single` option to any method will need to be updated. [#235](https://github.com/contentful/contentful.rb/pull/235)
11
+
12
+ ## 2.16.3
13
+ ### Fixed
14
+ * Fixed an issue where `raw['metadata']` was unexpectedly overwritten by `BaseResource#hydrate_metadata` method.
15
+
16
+ ## 2.16.2
17
+ ### Fixed
18
+ * Fixed an issue where entry's `raw['fields']` was unexpectedly overwritten by `FieldsResource#raw_with_links` method.
19
+
20
+ ## 2.16.1
21
+ * Removed unncessary files from gem release package.
22
+
23
+ ## 2.16.0
24
+
25
+ ### Added
26
+ * Added `Contentful::ArrayLike#to_ary`. [#200](https://github.com/contentful/contentful.rb/issues/200)
27
+ * Added `_metadata[:tags]` to read metadata tags on `entry` and `asset`.
28
+
29
+ ## 2.15.4
30
+
31
+ ### Fixed
32
+ * Fixed an issue where the `log_level` of `Logger` was changed unintentionally [#222](https://github.com/contentful/contentful.rb/pull/222)
33
+ * Fixed an issue cause by a `Logger` not being correctly thrown away, causing an exception. [#220](https://github.com/contentful/contentful.rb/pull/220)
34
+ * Added `title` field to assets to prevent Error raising when the field is empty. [#218](https://github.com/contentful/contentful.rb/pull/218)
35
+ * Fixed an issue with `ArrayLike` not taking multiple arguments leading to Errors when using it with pagination libraries. [#215](https://github.com/contentful/contentful.rb/pull/215)
36
+
37
+ ## 2.15.3
38
+ ### Fixed
39
+ * Fixed a deprecation warning in Ruby 2.7.0 for `URI::escape` and replaced it with a backwards compatible mechanism. [#217](https://github.com/contentful/contentful.rb/issues/217)
40
+
41
+ ## 2.15.2
42
+ ### Fixed
43
+ * Fixed unresolvable single linked entries and assets returning a JSON Link rather than being `nil`, the same way they are filtered from Link arrays.
44
+
45
+ ## 2.15.1
46
+ ### Fixed
47
+ * Fixed how `entry_mapping` is cached in order to avoid errors when deserializing resources that have been serialized with previously deleted mapping classes. [#212](https://github.com/contentful/contentful.rb/issues/212)
48
+
49
+ ## 2.15.0
50
+ ### Added
51
+ * Added the capability for `Array#next_page` to support carry-over of query parameters.
52
+
53
+ ## 2.14.0
54
+ ### Added
55
+ * Allow user defined methods to override properties created by the SDK, if you want to access overriden fields or sys properties use `#fields[]` or `#sys[]` as accessors. [#210](https://github.com/contentful/contentful.rb/pull/210)
56
+
57
+ ## 2.13.3
58
+ ### Fixed
59
+ * Fixed unfiltered unresolvable entries and assets from re-marshalled entries. [#207](https://github.com/contentful/contentful.rb/pull/207)
60
+
61
+ ## 2.13.2
62
+ ### Fixed
63
+ * Removed unnecessary object dups and moved some static arrays that were regenerated each time to constants.
64
+
65
+ ## 2.13.1
66
+ ### Fixed
67
+ * Fixed detection of empty fields when `:use_camel_case` is `true`. [#203](https://github.com/contentful/contentful.rb/issues/203)
68
+
69
+ ## 2.13.0
70
+ ### Changed
71
+ * Updated HTTP gem version limits. [#202](https://github.com/contentful/contentful.rb/pull/202)
4
72
 
5
73
  ## 2.12.0
6
74
  ### Added
data/README.md CHANGED
@@ -10,10 +10,10 @@
10
10
  </a>
11
11
  </p>
12
12
 
13
- # contentful.rb - Contentful Ruby Delivery SDK
13
+ # contentful.rb - Contentful Ruby Delivery Library
14
14
  [![Gem Version](https://badge.fury.io/rb/contentful.png)](http://badge.fury.io/rb/contentful)
15
15
 
16
- > Ruby SDK for the Contentful [Content Delivery API](https://www.contentful.com/developers/docs/references/content-delivery-api/) and [Content Preview API](https://www.contentful.com/developers/docs/references/content-preview-api/). It helps you to easily access your Content stored in Contentful with your Ruby applications.
16
+ > Ruby library for the Contentful [Content Delivery API](https://www.contentful.com/developers/docs/references/content-delivery-api/) and [Content Preview API](https://www.contentful.com/developers/docs/references/content-preview-api/). It helps you to easily access your Content stored in Contentful with your Ruby applications.
17
17
 
18
18
  <p align="center">
19
19
  <img src="https://img.shields.io/badge/Status-Maintained-green.svg" alt="This repository is actively maintained" /> &nbsp;
@@ -21,8 +21,8 @@
21
21
  <img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License" />
22
22
  </a>
23
23
  &nbsp;
24
- <a href="https://travis-ci.org/contentful/contentful.rb">
25
- <img src="https://travis-ci.org/contentful/contentful.rb.svg?branch=master" alt="Build Status">
24
+ <a href="https://app.circleci.com/pipelines/github/contentful/contentful.rb?branch=master">
25
+ <img src="https://circleci.com/gh/contentful/contentful.rb/tree/master.svg?style=svg" alt="CircleCI">
26
26
  </a>
27
27
  </p>
28
28
 
@@ -45,12 +45,12 @@
45
45
 
46
46
  <!-- TOC -->
47
47
 
48
- - [contentful.rb - Contentful Ruby Delivery SDK](#contentfulrb---contentful-ruby-delivery-sdk)
48
+ - [contentful.rb - Contentful Ruby Delivery library](#contentfulrb---contentful-ruby-delivery-library)
49
49
  - [Core Features](#core-features)
50
50
  - [Getting started](#getting-started)
51
51
  - [Installation](#installation)
52
52
  - [Your first request](#your-first-request)
53
- - [Using this SDK with the Preview API](#using-this-sdk-with-the-preview-api)
53
+ - [Using this library with the Preview API](#using-this-library-with-the-preview-api)
54
54
  - [Authentication](#authentication)
55
55
  - [Documentation & References](#documentation--references)
56
56
  - [Configuration](#configuration)
@@ -94,11 +94,11 @@
94
94
 
95
95
  ## Getting started
96
96
 
97
- In order to get started with the Contentful Ruby SDK you'll need not only to install it, but also to get credentials which will allow you to have access to your content in Contentful.
97
+ In order to get started with the Contentful Ruby library you'll need not only to install it, but also to get credentials which will allow you to have access to your content in Contentful.
98
98
 
99
99
  - [Installation](#installation)
100
100
  - [Your first request](#your-first-request)
101
- - [Using this SDK with the Preview API](#using-this-sdk-with-the-preview-api)
101
+ - [Using this library with the Preview API](#using-this-library-with-the-preview-api)
102
102
  - [Authentication](#authentication)
103
103
  - [Documentation & References](#documentation--references)
104
104
 
@@ -118,7 +118,7 @@ gem i contentful
118
118
 
119
119
  ### Your first request
120
120
 
121
- The following code snippet is the most basic one you can use to get some content from Contentful with this SDK:
121
+ The following code snippet is the most basic one you can use to get some content from Contentful with this library:
122
122
 
123
123
  ```ruby
124
124
  require 'contentful'
@@ -132,9 +132,9 @@ client = Contentful::Client.new(
132
132
  entry = client.entry('nyancat')
133
133
  ```
134
134
 
135
- ### Using this SDK with the Preview API
135
+ ### Using this library with the Preview API
136
136
 
137
- This SDK can also be used with the Preview API. In order to do so, you need to use the Preview API Access token, available on the same page where you get the Delivery API token, and specify the host of the preview API, such as:
137
+ This library can also be used with the Preview API. In order to do so, you need to use the Preview API Access token, available on the same page where you get the Delivery API token, and specify the host of the preview API, such as:
138
138
 
139
139
  ```ruby
140
140
  require 'contentful'
@@ -168,7 +168,7 @@ For more information, check the [Contentful REST API reference on Authentication
168
168
  - [Migrating to 2.x](#migrating-to-2x)
169
169
 
170
170
 
171
- To help you get the most out of this SDK, we've prepared all available client configuration options, reference documentation, tutorials and other examples that will help you learn and understand how to use this library.
171
+ To help you get the most out of this library, we've prepared all available client configuration options, reference documentation, tutorials and other examples that will help you learn and understand how to use this library.
172
172
 
173
173
  ### Configuration
174
174
 
@@ -287,7 +287,7 @@ client = Contentful::Client.new(
287
287
  <td><code>max_include_resolution_depth</code></td>
288
288
  <td><code>20</code></td>
289
289
  <td>
290
- Maximum amount of levels to resolve includes for SDK entities
290
+ Maximum amount of levels to resolve includes for library entities
291
291
  (this is independent of API-level includes - it represents the maximum depth the include resolution
292
292
  tree is allowed to resolved before falling back to <code>Link</code> objects).
293
293
  This include resolution strategy is in place in order to avoid having infinite circular recursion on resources with circular dependencies.
@@ -363,6 +363,8 @@ client = Contentful::Client.new(
363
363
  <td>
364
364
  The default severity is set to INFO and logs only the request attributes (headers, parameters and url).
365
365
  Setting it to DEBUG will also log the raw JSON response.
366
+ WARNING: Setting this will override the level on the logger instance. Leave out this key to preserve
367
+ the original log_level on the logger, for example when using Rails.logger.
366
368
  </td>
367
369
  </tr>
368
370
  </tbody>
@@ -422,6 +424,15 @@ entry.color # 'rainbow'
422
424
  entry.birthday # #<DateTime: 2011-04-04T22:00:00+00:00 ((2455656j,79200s,0n),+0s,2299161j)>
423
425
  ```
424
426
 
427
+ #### Accessing tags
428
+
429
+ Tags can be accessed via the `#_metadata` method.
430
+
431
+ ```ruby
432
+ entry = client.entry 'nyancat'
433
+ entry._metadata[:tags] # => [<Contentful::Link id='tagID'>]
434
+ ```
435
+
425
436
  #### Dynamic entries
426
437
 
427
438
  However, you can (and should) set `:dynamic_entries` to `:auto` in your client configuration.
@@ -1,5 +1,6 @@
1
1
  require_relative 'base_resource'
2
2
  require_relative 'array_like'
3
+ require_relative 'includes'
3
4
 
4
5
  module Contentful
5
6
  # Resource Class for Arrays (e.g. search results)
@@ -11,13 +12,15 @@ module Contentful
11
12
 
12
13
  include Contentful::ArrayLike
13
14
 
14
- attr_reader :total, :limit, :skip, :items, :endpoint
15
+ attr_reader :total, :limit, :skip, :items, :endpoint, :query
15
16
 
16
17
  def initialize(item = nil,
17
18
  configuration = {
18
19
  default_locale: Contentful::Client::DEFAULT_CONFIGURATION[:default_locale]
19
20
  },
20
- endpoint = '', *)
21
+ endpoint = '',
22
+ query = {},
23
+ *)
21
24
  super(item, configuration)
22
25
 
23
26
  @endpoint = endpoint
@@ -25,11 +28,12 @@ module Contentful
25
28
  @limit = item.fetch('limit', nil)
26
29
  @skip = item.fetch('skip', nil)
27
30
  @items = item.fetch('items', [])
31
+ @query = query
28
32
  end
29
33
 
30
34
  # @private
31
35
  def marshal_dump
32
- super.merge(endpoint: endpoint)
36
+ super.merge(endpoint: endpoint, query: query)
33
37
  end
34
38
 
35
39
  # @private
@@ -39,12 +43,15 @@ module Contentful
39
43
  @total = raw.fetch('total', nil)
40
44
  @limit = raw.fetch('limit', nil)
41
45
  @skip = raw.fetch('skip', nil)
46
+ @query = raw_object[:query]
42
47
  @items = raw.fetch('items', []).map do |item|
43
48
  require_relative 'resource_builder'
44
49
  ResourceBuilder.new(
45
50
  item.raw,
46
- raw_object[:configuration].merge(includes_for_single: Support.includes_from_response(raw, false)),
47
- item.respond_to?(:localized) ? item.localized : false
51
+ raw_object[:configuration].merge(includes_for_single: Includes.from_response(raw, false)),
52
+ item.respond_to?(:localized) ? item.localized : false,
53
+ 0,
54
+ raw_object[:configuration][:errors] || []
48
55
  ).run
49
56
  end
50
57
  end
@@ -70,7 +77,8 @@ module Contentful
70
77
  'Asset' => 'assets',
71
78
  'Locale' => 'locales'
72
79
  }
73
- client.public_send(plurals[items.first.type], limit: limit, skip: new_skip)
80
+
81
+ client.public_send(plurals[items.first.type], query.merge(limit: limit, skip: new_skip))
74
82
  end
75
83
  end
76
84
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Contentful
2
4
  # Useful methods for array-like resources that can be included if an
3
5
  # :items property exists
@@ -37,8 +39,8 @@ module Contentful
37
39
  # Delegates to items#[]
38
40
  #
39
41
  # @return [Contentful::Entry, Contentful::Asset]
40
- def [](index)
41
- items[index]
42
+ def [](*args)
43
+ items[*args]
42
44
  end
43
45
 
44
46
  # Delegates to items#last
@@ -47,5 +49,12 @@ module Contentful
47
49
  def last
48
50
  items.last
49
51
  end
52
+
53
+ # Delegates to items#to_ary
54
+ #
55
+ # @return [Contentful::Entry, Contentful::Asset]
56
+ def to_ary
57
+ items
58
+ end
50
59
  end
51
60
  end
@@ -10,10 +10,7 @@ module Contentful
10
10
 
11
11
  # @private
12
12
  def marshal_dump
13
- {
14
- configuration: @configuration,
15
- raw: raw
16
- }
13
+ super.merge(raw: raw)
17
14
  end
18
15
 
19
16
  # @private
@@ -23,6 +20,11 @@ module Contentful
23
20
  define_asset_methods!
24
21
  end
25
22
 
23
+ # @private
24
+ def known_link?(*)
25
+ false
26
+ end
27
+
26
28
  # @private
27
29
  def inspect
28
30
  "<#{repr_name} id='#{sys[:id]}' url='#{url}'>"
@@ -91,6 +93,10 @@ module Contentful
91
93
  end
92
94
 
93
95
  def define_asset_methods!
96
+ define_singleton_method :title do
97
+ fields.fetch(:title, nil)
98
+ end
99
+
94
100
  define_singleton_method :description do
95
101
  fields.fetch(:description, nil)
96
102
  end
@@ -5,16 +5,17 @@ require_relative 'support'
5
5
  module Contentful
6
6
  # Base definition of a Contentful Resource containing Sys properties
7
7
  class BaseResource
8
- attr_reader :raw, :default_locale, :sys
8
+ attr_reader :raw, :default_locale, :sys, :_metadata
9
9
 
10
10
  # rubocop:disable Metrics/ParameterLists
11
- def initialize(item, configuration = {}, _localized = false, _includes = [], entries = {}, depth = 0, _errors = [])
11
+ def initialize(item, configuration = {}, _localized = false, _includes = Includes.new, entries = {}, depth = 0, _errors = [])
12
12
  entries["#{item['sys']['type']}:#{item['sys']['id']}"] = self if entries && item.key?('sys')
13
13
  @raw = item
14
14
  @default_locale = configuration[:default_locale]
15
15
  @depth = depth
16
16
  @configuration = configuration
17
17
  @sys = hydrate_sys
18
+ @_metadata = hydrate_metadata
18
19
 
19
20
  define_sys_methods!
20
21
  end
@@ -31,18 +32,33 @@ module Contentful
31
32
 
32
33
  # @private
33
34
  def marshal_dump
35
+ entry_mapping = @configuration[:entry_mapping].each_with_object({}) do |(k, v), res|
36
+ res[k] = v.to_s
37
+ end
38
+
34
39
  {
35
- configuration: @configuration,
40
+ # loggers usually have a file handle that can't be marshalled, so let's not return that
41
+ configuration: @configuration.merge(entry_mapping: entry_mapping, logger: nil),
36
42
  raw: raw
37
43
  }
38
44
  end
39
45
 
40
46
  # @private
41
47
  def marshal_load(raw_object)
48
+ raw_object[:configuration][:entry_mapping] = raw_object[:configuration].fetch(:entry_mapping, {}).each_with_object({}) do |(k, v), res|
49
+ begin
50
+ v = v.to_s unless v.is_a?(::String)
51
+ res[k] = v.split('::').inject(Object) { |o, c| o.const_get c }
52
+ rescue
53
+ next
54
+ end
55
+ end
56
+
42
57
  @raw = raw_object[:raw]
43
58
  @configuration = raw_object[:configuration]
44
59
  @default_locale = @configuration[:default_locale]
45
60
  @sys = hydrate_sys
61
+ @_metadata = hydrate_metadata
46
62
  @depth = 0
47
63
  define_sys_methods!
48
64
  end
@@ -59,9 +75,7 @@ module Contentful
59
75
 
60
76
  def define_sys_methods!
61
77
  @sys.each do |k, v|
62
- define_singleton_method k do
63
- v
64
- end
78
+ define_singleton_method(k) { v } unless self.class.method_defined?(k)
65
79
  end
66
80
  end
67
81
 
@@ -81,6 +95,15 @@ module Contentful
81
95
  result
82
96
  end
83
97
 
98
+ def hydrate_metadata
99
+ result = {}
100
+ raw.fetch('metadata', {}).each do |k, v|
101
+ v = v.map { |tag| build_link(tag) } if k == 'tags'
102
+ result[Support.snakify(k, @configuration[:use_camel_case]).to_sym] = v
103
+ end
104
+ result
105
+ end
106
+
84
107
  protected
85
108
 
86
109
  def repr_name
@@ -30,7 +30,6 @@ module Contentful
30
30
  raw_mode: false,
31
31
  gzip_encoded: true,
32
32
  logger: false,
33
- log_level: Logger::INFO,
34
33
  proxy_host: nil,
35
34
  proxy_username: nil,
36
35
  proxy_password: nil,
@@ -105,7 +104,7 @@ module Contentful
105
104
  # @private
106
105
  def setup_logger
107
106
  @logger = configuration[:logger]
108
- logger.level = configuration[:log_level] if logger
107
+ logger.level = configuration[:log_level] if logger && configuration.key?(:log_level)
109
108
  end
110
109
 
111
110
  # @private
@@ -386,7 +385,9 @@ module Contentful
386
385
  response.object,
387
386
  configuration.merge(endpoint: response.request.endpoint),
388
387
  (response.request.query || {}).fetch(:locale, nil) == '*',
389
- 0
388
+ 0,
389
+ [],
390
+ response.request.query || {}
390
391
  ).run
391
392
  end
392
393
 
@@ -155,10 +155,7 @@ module Contentful
155
155
 
156
156
  return nil if Support.unresolvable?(node['data']['target'], configuration[:errors])
157
157
 
158
- resource = Support.resource_for_link(
159
- node['data']['target'],
160
- configuration[:includes_for_single]
161
- )
158
+ resource = configuration[:includes_for_single].find_link(node['data']['target'])
162
159
 
163
160
  # Resource is valid but unreachable
164
161
  return Link.new(node['data']['target'], configuration) if resource.nil?
@@ -2,6 +2,7 @@ require_relative 'error'
2
2
  require_relative 'fields_resource'
3
3
  require_relative 'content_type_cache'
4
4
  require_relative 'resource_references'
5
+ require_relative 'includes'
5
6
 
6
7
  module Contentful
7
8
  # Resource class for Entry.
@@ -17,7 +18,8 @@ module Contentful
17
18
  private
18
19
 
19
20
  def coerce(field_id, value, includes, errors, entries = {})
20
- if Support.link?(value) && !Support.unresolvable?(value, errors)
21
+ if Support.link?(value)
22
+ return nil if Support.unresolvable?(value, errors)
21
23
  return build_nested_resource(value, includes, entries, errors)
22
24
  end
23
25
  return coerce_link_array(value, includes, errors, entries) if Support.link_array?(value)
@@ -29,7 +31,7 @@ module Contentful
29
31
  content_type_field = content_type.field_for(field_id)
30
32
  coercion_configuration = @configuration.merge(
31
33
  includes_for_single:
32
- @configuration.fetch(:includes_for_single, []) + includes,
34
+ @configuration.fetch(:includes_for_single, Includes.new) + includes,
33
35
  _entries_cache: entries,
34
36
  localized: localized,
35
37
  depth: @depth,
@@ -57,7 +59,7 @@ module Contentful
57
59
  # Any included object after the maximum include resolution depth will be just a Link
58
60
  def build_nested_resource(value, includes, entries, errors)
59
61
  if @depth < @configuration.fetch(:max_include_resolution_depth, 20)
60
- resource = Support.resource_for_link(value, includes)
62
+ resource = includes.find_link(value)
61
63
  return resolve_include(resource, includes, entries, errors) unless resource.nil?
62
64
  end
63
65
 
@@ -71,7 +73,7 @@ module Contentful
71
73
  resource,
72
74
  @configuration.merge(
73
75
  includes_for_single:
74
- @configuration.fetch(:includes_for_single, []) + includes,
76
+ @configuration.fetch(:includes_for_single, Includes.new) + includes,
75
77
  _entries_cache: entries
76
78
  ),
77
79
  localized,
@@ -103,9 +105,11 @@ module Contentful
103
105
  protected
104
106
 
105
107
  def content_type_field?(name)
108
+ content_type_key = Support.snakify('contentType', @configuration[:use_camel_case])
109
+
106
110
  content_type = ContentTypeCache.cache_get(
107
111
  sys[:space].id,
108
- sys[:content_type].id
112
+ sys[content_type_key.to_sym].id
109
113
  )
110
114
 
111
115
  return false if content_type.nil?
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'support'
4
4
  require_relative 'base_resource'
5
+ require_relative 'includes'
5
6
 
6
7
  module Contentful
7
8
  # Base definition of a Contentful Resource containing Field properties
@@ -9,7 +10,7 @@ module Contentful
9
10
  attr_reader :localized
10
11
 
11
12
  # rubocop:disable Metrics/ParameterLists
12
- def initialize(item, _configuration, localized = false, includes = [], entries = {}, depth = 0, errors = [])
13
+ def initialize(item, _configuration, localized = false, includes = Includes.new, entries = {}, depth = 0, errors = [])
13
14
  super
14
15
 
15
16
  @configuration[:errors] = errors
@@ -48,11 +49,7 @@ module Contentful
48
49
 
49
50
  # @private
50
51
  def marshal_dump
51
- {
52
- configuration: @configuration,
53
- raw: raw_with_links,
54
- localized: localized
55
- }
52
+ super.merge(raw: raw_with_links, localized: localized)
56
53
  end
57
54
 
58
55
  # @private
@@ -60,7 +57,7 @@ module Contentful
60
57
  super(raw_object)
61
58
  @localized = raw_object[:localized]
62
59
  @fields = hydrate_fields(
63
- raw_object[:configuration].fetch(:includes_for_single, []),
60
+ raw_object[:configuration].fetch(:includes_for_single, Includes.new),
64
61
  {},
65
62
  raw_object[:configuration].fetch(:errors, [])
66
63
  )
@@ -71,6 +68,7 @@ module Contentful
71
68
  def raw_with_links
72
69
  links = fields.keys.select { |property| known_link?(property) }
73
70
  processed_raw = raw.clone
71
+ processed_raw['fields'] = raw['fields'].clone
74
72
  raw['fields'].each do |k, v|
75
73
  links_key = Support.snakify(k, @configuration[:use_camel_case])
76
74
  processed_raw['fields'][k] = links.include?(links_key.to_sym) ? send(links_key) : v
@@ -83,9 +81,7 @@ module Contentful
83
81
 
84
82
  def define_fields_methods!
85
83
  fields.each do |k, v|
86
- define_singleton_method k do
87
- v
88
- end
84
+ define_singleton_method(k) { v } unless self.class.method_defined?(k)
89
85
  end
90
86
  end
91
87
 
@@ -110,8 +106,8 @@ module Contentful
110
106
  end
111
107
 
112
108
  def hydrate_nonlocalized_fields(includes, errors, entries)
113
- result = { locale => {} }
114
109
  locale = internal_resource_locale
110
+ result = { locale => {} }
115
111
  raw['fields'].each do |name, value|
116
112
  name = Support.snakify(name, @configuration[:use_camel_case])
117
113
  result[locale][name.to_sym] = coerce(
@@ -0,0 +1,74 @@
1
+ require_relative 'array_like'
2
+
3
+ module Contentful
4
+ # The includes hashes returned when include_level is specified
5
+ class Includes
6
+ include ArrayLike
7
+
8
+ attr_accessor :items, :lookup
9
+
10
+ def initialize(items = [], lookup = nil)
11
+ self.items = items
12
+ self.lookup = lookup || build_lookup
13
+ end
14
+
15
+ def self.from_response(json, raw = true)
16
+ includes = if raw
17
+ json['items'].dup
18
+ else
19
+ json['items'].map(&:raw)
20
+ end
21
+
22
+ %w[Entry Asset].each do |type|
23
+ includes.concat(json['includes'].fetch(type, [])) if json.fetch('includes', {}).key?(type)
24
+ end
25
+
26
+ new includes || []
27
+ end
28
+
29
+ def find_link(link)
30
+ key = "#{link['sys']['linkType']}:#{link['sys']['id']}"
31
+ lookup[key]
32
+ end
33
+
34
+ # Override some of the features of Array to take into account the lookup
35
+ # field in a performant way.
36
+
37
+ # If the lookups are the same then these two objects are effectively the same
38
+ def ==(other)
39
+ object_id == other.object_id || lookup == other.lookup
40
+ end
41
+
42
+ def +(other)
43
+ # If we're being asked to add to itself, just return without duplicating
44
+ return self if self == other
45
+
46
+ dup.tap do |copy|
47
+ copy.items += other.items
48
+ copy.lookup.merge!(other.lookup)
49
+ end
50
+ end
51
+
52
+ def dup
53
+ self.class.new(items.dup, lookup.dup)
54
+ end
55
+
56
+ def marshal_dump
57
+ items
58
+ end
59
+
60
+ def marshal_load(array)
61
+ self.items = array
62
+ self.lookup = build_lookup
63
+ end
64
+
65
+ private
66
+
67
+ def build_lookup
68
+ items.each_with_object({}) do |i, h|
69
+ key = "#{i['sys']['type']}:#{i['sys']['id']}"
70
+ h[key] = i
71
+ end
72
+ end
73
+ end
74
+ end
@@ -13,7 +13,12 @@ module Contentful
13
13
 
14
14
  if id
15
15
  @type = :single
16
- @id = URI.escape(id)
16
+ # Given the deprecation of `URI::escape` and `URI::encode`
17
+ # it is needed to replace it with `URI::encode_www_form_component`.
18
+ # This method, does replace spaces with `+` instead of `%20`.
19
+ # Therefore, to keep backwards compatibility, we're replacing the resulting `+`
20
+ # back with `%20`.
21
+ @id = URI.encode_www_form_component(id).gsub('+', '%20')
17
22
  else
18
23
  @type = :multi
19
24
  @id = nil