contentful 2.12.0 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,327 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Contentful::Error do
4
- let(:r) { Contentful::Response.new raw_fixture('not_found', 404) }
5
-
6
- describe '#response' do
7
- it 'returns the response the error has been initialized with' do
8
- expect(Contentful::Error.new(r).response).to be r
9
- end
10
- end
11
-
12
- describe '#message' do
13
- it 'returns the message found in the response json' do
14
- message = "HTTP status code: 404\n"\
15
- "Message: The resource could not be found.\n"\
16
- "Details: {\"type\"=>\"Entry\", \"space\"=>\"cfexampleapi\", \"id\"=>\"not found\"}\n"\
17
- "Request ID: 85f-351076632"
18
- expect(Contentful::Error.new(r).message).not_to be_nil
19
- expect(Contentful::Error.new(r).message).to eq message
20
- end
21
-
22
- describe 'message types' do
23
- describe 'default messages' do
24
- it '400' do
25
- response = Contentful::Response.new raw_fixture('default_400', 400)
26
- error = Contentful::Error[response.raw.status].new(response)
27
-
28
- message = "HTTP status code: 400\n"\
29
- "Message: The request was malformed or missing a required parameter.\n"\
30
- "Request ID: 85f-351076632"
31
- expect(error.message).to eq message
32
- end
33
-
34
- it '401' do
35
- response = Contentful::Response.new raw_fixture('default_401', 401)
36
- error = Contentful::Error[response.raw.status].new(response)
37
-
38
- message = "HTTP status code: 401\n"\
39
- "Message: The authorization token was invalid.\n"\
40
- "Request ID: 85f-351076632"
41
- expect(error.message).to eq message
42
- end
43
-
44
- it '403' do
45
- response = Contentful::Response.new raw_fixture('default_403', 403)
46
- error = Contentful::Error[response.raw.status].new(response)
47
-
48
- message = "HTTP status code: 403\n"\
49
- "Message: The specified token does not have access to the requested resource.\n"\
50
- "Request ID: 85f-351076632"
51
- expect(error.message).to eq message
52
- end
53
-
54
- it '404' do
55
- response = Contentful::Response.new raw_fixture('default_404', 404)
56
- error = Contentful::Error[response.raw.status].new(response)
57
-
58
- message = "HTTP status code: 404\n"\
59
- "Message: The requested resource or endpoint could not be found.\n"\
60
- "Request ID: 85f-351076632"
61
- expect(error.message).to eq message
62
- end
63
-
64
- it '429' do
65
- response = Contentful::Response.new raw_fixture('default_429', 429)
66
- error = Contentful::Error[response.raw.status].new(response)
67
-
68
- message = "HTTP status code: 429\n"\
69
- "Message: Rate limit exceeded. Too many requests.\n"\
70
- "Request ID: 85f-351076632"
71
- expect(error.message).to eq message
72
- end
73
-
74
- it '500' do
75
- response = Contentful::Response.new raw_fixture('default_500', 500)
76
- error = Contentful::Error[response.raw.status].new(response)
77
-
78
- message = "HTTP status code: 500\n"\
79
- "Message: Internal server error.\n"\
80
- "Request ID: 85f-351076632"
81
- expect(error.message).to eq message
82
- end
83
-
84
- it '502' do
85
- response = Contentful::Response.new raw_fixture('default_502', 502)
86
- error = Contentful::Error[response.raw.status].new(response)
87
-
88
- message = "HTTP status code: 502\n"\
89
- "Message: The requested space is hibernated.\n"\
90
- "Request ID: 85f-351076632"
91
- expect(error.message).to eq message
92
- end
93
-
94
- it '503' do
95
- response = Contentful::Response.new raw_fixture('default_503', 503)
96
- error = Contentful::Error[response.raw.status].new(response)
97
-
98
- message = "HTTP status code: 503\n"\
99
- "Message: The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.\n"\
100
- "Request ID: 85f-351076632"
101
- expect(error.message).to eq message
102
- end
103
- end
104
-
105
- describe 'special cases' do
106
- describe '400' do
107
- it 'details is a string' do
108
- response = Contentful::Response.new raw_fixture('400_details_string', 400)
109
- error = Contentful::Error[response.raw.status].new(response)
110
-
111
- message = "HTTP status code: 400\n"\
112
- "Message: The request was malformed or missing a required parameter.\n"\
113
- "Details: some error\n"\
114
- "Request ID: 85f-351076632"
115
- expect(error.message).to eq message
116
- end
117
-
118
- it 'details is an object, internal errors are strings' do
119
- response = Contentful::Response.new raw_fixture('400_details_errors_string', 400)
120
- error = Contentful::Error[response.raw.status].new(response)
121
-
122
- message = "HTTP status code: 400\n"\
123
- "Message: The request was malformed or missing a required parameter.\n"\
124
- "Details: some error\n"\
125
- "Request ID: 85f-351076632"
126
- expect(error.message).to eq message
127
- end
128
-
129
- it 'details is an object, internal errors are objects which have details' do
130
- response = Contentful::Response.new raw_fixture('400_details_errors_object', 400)
131
- error = Contentful::Error[response.raw.status].new(response)
132
-
133
- message = "HTTP status code: 400\n"\
134
- "Message: The request was malformed or missing a required parameter.\n"\
135
- "Details: some error\n"\
136
- "Request ID: 85f-351076632"
137
- expect(error.message).to eq message
138
- end
139
- end
140
-
141
- describe '403' do
142
- it 'has an array of reasons' do
143
- response = Contentful::Response.new raw_fixture('403_reasons', 403)
144
- error = Contentful::Error[response.raw.status].new(response)
145
-
146
- message = "HTTP status code: 403\n"\
147
- "Message: The specified token does not have access to the requested resource.\n"\
148
- "Details: \n\tReasons:\n"\
149
- "\t\tfoo\n"\
150
- "\t\tbar\n"\
151
- "Request ID: 85f-351076632"
152
- expect(error.message).to eq message
153
- end
154
- end
155
-
156
- describe '404' do
157
- it 'details is a string' do
158
- response = Contentful::Response.new raw_fixture('404_details_string', 404)
159
- error = Contentful::Error[response.raw.status].new(response)
160
-
161
- message = "HTTP status code: 404\n"\
162
- "Message: The requested resource or endpoint could not be found.\n"\
163
- "Details: The resource could not be found\n"\
164
- "Request ID: 85f-351076632"
165
- expect(error.message).to eq message
166
- end
167
-
168
- describe 'has a type' do
169
- it 'type is on the top level' do
170
- response = Contentful::Response.new raw_fixture('404_type', 404)
171
- error = Contentful::Error[response.raw.status].new(response)
172
-
173
- message = "HTTP status code: 404\n"\
174
- "Message: The requested resource or endpoint could not be found.\n"\
175
- "Details: The requested Asset could not be found.\n"\
176
- "Request ID: 85f-351076632"
177
- expect(error.message).to eq message
178
- end
179
-
180
- it 'type is not on the top level' do
181
- response = Contentful::Response.new raw_fixture('404_sys_type', 404)
182
- error = Contentful::Error[response.raw.status].new(response)
183
-
184
- message = "HTTP status code: 404\n"\
185
- "Message: The requested resource or endpoint could not be found.\n"\
186
- "Details: The requested Space could not be found.\n"\
187
- "Request ID: 85f-351076632"
188
- expect(error.message).to eq message
189
- end
190
- end
191
-
192
- it 'can specify the resource id' do
193
- response = Contentful::Response.new raw_fixture('404_id', 404)
194
- error = Contentful::Error[response.raw.status].new(response)
195
-
196
- message = "HTTP status code: 404\n"\
197
- "Message: The requested resource or endpoint could not be found.\n"\
198
- "Details: The requested Asset could not be found. ID: foobar.\n"\
199
- "Request ID: 85f-351076632"
200
- expect(error.message).to eq message
201
- end
202
- end
203
-
204
- describe '429' do
205
- it 'can show the time until reset' do
206
- response = Contentful::Response.new raw_fixture('default_429', 429, false, {'x-contentful-ratelimit-reset' => 60})
207
- error = Contentful::Error[response.raw.status].new(response)
208
-
209
- message = "HTTP status code: 429\n"\
210
- "Message: Rate limit exceeded. Too many requests.\n"\
211
- "Request ID: 85f-351076632\n"\
212
- "Time until reset (seconds): 60"
213
- expect(error.message).to eq message
214
- end
215
- end
216
- end
217
-
218
- describe 'generic error' do
219
- it 'with everything' do
220
- response = Contentful::Response.new raw_fixture('other_error', 512)
221
- error = Contentful::Error[response.raw.status].new(response)
222
-
223
- message = "HTTP status code: 512\n"\
224
- "Message: Some error occurred.\n"\
225
- "Details: some text\n"\
226
- "Request ID: 85f-351076632"
227
- expect(error.message).to eq message
228
- end
229
-
230
- it 'no details' do
231
- response = Contentful::Response.new raw_fixture('other_error_no_details', 512)
232
- error = Contentful::Error[response.raw.status].new(response)
233
-
234
- message = "HTTP status code: 512\n"\
235
- "Message: Some error occurred.\n"\
236
- "Request ID: 85f-351076632"
237
- expect(error.message).to eq message
238
- end
239
-
240
- it 'no request id' do
241
- response = Contentful::Response.new raw_fixture('other_error_no_request_id', 512)
242
- error = Contentful::Error[response.raw.status].new(response)
243
-
244
- message = "HTTP status code: 512\n"\
245
- "Message: Some error occurred.\n"\
246
- "Details: some text"
247
- expect(error.message).to eq message
248
- end
249
-
250
- it 'no message' do
251
- response = Contentful::Response.new raw_fixture('other_error_no_message', 512)
252
- error = Contentful::Error[response.raw.status].new(response)
253
-
254
- message = "HTTP status code: 512\n"\
255
- "Message: The following error was received: {\n"\
256
- " \"sys\": {\n"\
257
- " \"type\": \"Error\",\n"\
258
- " \"id\": \"SomeError\"\n"\
259
- " },\n"\
260
- " \"details\": \"some text\",\n"\
261
- " \"requestId\": \"85f-351076632\"\n"\
262
- "}\n"\
263
- "\n"\
264
- "Details: some text\n"\
265
- "Request ID: 85f-351076632"
266
- expect(error.message).to eq message
267
- end
268
-
269
- it 'nothing' do
270
- response = Contentful::Response.new raw_fixture('other_error_nothing', 512)
271
- error = Contentful::Error[response.raw.status].new(response)
272
-
273
- message = "HTTP status code: 512\n"\
274
- "Message: The following error was received: {\n"\
275
- " \"sys\": {\n"\
276
- " \"type\": \"Error\",\n"\
277
- " \"id\": \"SomeError\"\n"\
278
- " }\n"\
279
- "}\n"
280
- expect(error.message).to eq message
281
- end
282
- end
283
- end
284
- end
285
-
286
- describe Contentful::UnparsableJson do
287
- describe '#message' do
288
- it 'returns the json parser\'s message' do
289
- uj = Contentful::Response.new raw_fixture('unparsable')
290
- expect(Contentful::UnparsableJson.new(uj).message).to \
291
- include 'unexpected token'
292
- end
293
- end
294
- end
295
-
296
- describe '.[]' do
297
- it 'returns BadRequest error class for 400' do
298
- expect(Contentful::Error[400]).to eq Contentful::BadRequest
299
- end
300
-
301
- it 'returns Unauthorized error class for 401' do
302
- expect(Contentful::Error[401]).to eq Contentful::Unauthorized
303
- end
304
-
305
- it 'returns AccessDenied error class for 403' do
306
- expect(Contentful::Error[403]).to eq Contentful::AccessDenied
307
- end
308
-
309
- it 'returns NotFound error class for 404' do
310
- expect(Contentful::Error[404]).to eq Contentful::NotFound
311
- end
312
-
313
- it 'returns ServerError error class for 500' do
314
- expect(Contentful::Error[500]).to eq Contentful::ServerError
315
- end
316
-
317
- it 'returns ServiceUnavailable error class for 503' do
318
- expect(Contentful::Error[503]).to eq Contentful::ServiceUnavailable
319
- end
320
-
321
- it 'returns generic error class for any other value' do
322
- expect(Contentful::Error[nil]).to eq Contentful::Error
323
- expect(Contentful::Error[200]).to eq Contentful::Error
324
- end
325
- end
326
-
327
- end
@@ -1,87 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class NonCachingClient < Contentful::Client
4
- def request_headers
5
- headers = super
6
- headers['Cf-No-Cache'] = 'foobar'
7
- headers
8
- end
9
- end
10
-
11
- class RetryLoggerMock < Logger
12
- attr_reader :retry_attempts
13
-
14
- def initialize(*)
15
- super
16
- @retry_attempts = 0
17
- end
18
-
19
- def info(message)
20
- super
21
- @retry_attempts += 1 if message.include?('Contentful API Rate Limit Hit! Retrying')
22
- end
23
- end
24
-
25
- describe 'Error Requests' do
26
- it 'will return 404 (Unauthorized) if resource not found' do
27
- expect_vcr('not found')do
28
- create_client.content_type 'not found'
29
- end.to raise_error(Contentful::NotFound)
30
- end
31
-
32
- it 'will return 400 (BadRequest) if invalid parameters have been passed' do
33
- expect_vcr('bad request')do
34
- create_client.entries(some: 'parameter')
35
- end.to raise_error(Contentful::BadRequest)
36
- end
37
-
38
- it 'will return 403 (AccessDenied) if ...' do
39
- skip
40
- end
41
-
42
- it 'will return 401 (Unauthorized) if wrong credentials are given' do
43
- client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')
44
-
45
- expect_vcr('unauthorized'){
46
- client.entry('nyancat')
47
- }.to raise_error(Contentful::Unauthorized)
48
- end
49
-
50
- it 'will return 500 (ServerError) if ...' do
51
- skip
52
- end
53
-
54
- it 'will return a 429 if the ratelimit is reached and is not set to retry' do
55
- client = Contentful::Client.new(space: 'wrong', access_token: 'credentials', max_rate_limit_retries: 0)
56
- expect_vcr('ratelimit') {
57
- client.entry('nyancat')
58
- }.to raise_error(Contentful::RateLimitExceeded)
59
- end
60
-
61
- it 'will retry on 429 by default' do
62
- logger = RetryLoggerMock.new(STDOUT)
63
- client = NonCachingClient.new(
64
- api_url: 'cdnorigin.flinkly.com',
65
- space: '164vhtp008kz',
66
- access_token: '7699b6c6f6cee9b6abaa216c71fbcb3eee56cb6f082f57b5e21b2b50f86bdea0',
67
- raise_errors: true,
68
- logger: logger
69
- )
70
-
71
- vcr('ratelimit_retry') {
72
- 3.times {
73
- client.assets
74
- }
75
- }
76
-
77
- expect(logger.retry_attempts).to eq 1
78
- end
79
-
80
- it 'will return 503 (ServiceUnavailable) when the service is unavailable' do
81
- client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')
82
-
83
- expect_vcr('unavailable'){
84
- client.entry('nyancat')
85
- }.to raise_error(Contentful::ServiceUnavailable)
86
- end
87
- end
data/spec/field_spec.rb DELETED
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Contentful::Field do
4
- let(:field) { vcr('field') { create_client.content_type('cat').fields.first } }
5
- let(:linkField) { vcr('linkField') {
6
- create_client.content_type('cat').fields.select { |f| f.id == 'image' }.first
7
- } }
8
- let(:arrayField) { vcr('arrayField') {
9
- Contentful::Client.new(
10
- space: 'wl1z0pal05vy',
11
- access_token: '9b76e1bbc29eb513611a66b9fc5fb7acd8d95e83b0f7d6bacfe7ec926c819806'
12
- ).content_type('2PqfXUJwE8qSYKuM0U6w8M').fields.select { |f| f.id == 'categories' }.first
13
- } }
14
-
15
- describe 'Properties' do
16
- it 'has #id' do
17
- expect(field.id).to eq 'name'
18
- end
19
-
20
- it 'has #name' do
21
- expect(field.name).to eq 'Name'
22
- end
23
-
24
- it 'has #type' do
25
- expect(field.type).to eq 'Text'
26
- end
27
-
28
- it 'could have #items' do
29
- expect(field).to respond_to :items
30
- end
31
-
32
- it 'has #required' do
33
- expect(field.required).to be_truthy
34
- end
35
-
36
- it 'has #localized' do
37
- expect(field.required).to be_truthy
38
- end
39
- end
40
-
41
- describe 'Link field properties' do
42
- it 'has #type' do
43
- expect(linkField.type).to eq 'Link'
44
- end
45
-
46
- it 'has #linkType' do
47
- expect(linkField.link_type).to eq 'Asset'
48
- end
49
- end
50
-
51
- describe 'Array field properties' do
52
- it 'has #type' do
53
- expect(arrayField.type).to eq 'Array'
54
- end
55
-
56
- it 'has #items' do
57
- expect(arrayField.items.type).to eq 'Link'
58
- expect(arrayField.items.link_type).to eq 'Entry'
59
- end
60
- end
61
-
62
- describe 'issues' do
63
- describe 'json field' do
64
- it 'can coerce properly when top level is not object' do
65
- coercion = Contentful::ObjectCoercion.new([{foo: 123}])
66
- expect(coercion.coerce).to eq [{foo: 123}]
67
-
68
- coercion = Contentful::ObjectCoercion.new('foobar')
69
- expect(coercion.coerce).to eq 'foobar'
70
-
71
- coercion = Contentful::ObjectCoercion.new(true)
72
- expect(coercion.coerce).to eq true
73
-
74
- coercion = Contentful::ObjectCoercion.new(123)
75
- expect(coercion.coerce).to eq 123
76
-
77
- coercion = Contentful::ObjectCoercion.new({foo: 123})
78
- expect(coercion.coerce).to eq(foo: 123)
79
- end
80
- end
81
-
82
- describe 'datetime field' do
83
- it 'can coerce properly when value is nil' do
84
- coercion = Contentful::DateCoercion.new(nil)
85
- expect(coercion.coerce).to eq(nil)
86
- end
87
-
88
- it 'can coerce properly when value is already datetime' do
89
- value = DateTime.new
90
- coercion = Contentful::DateCoercion.new(value)
91
- expect(coercion.coerce).to eq value
92
- end
93
- end
94
- end
95
- end
data/spec/file_spec.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Contentful::File do
4
- let(:file) { vcr('asset') { create_client.asset('nyancat').file } }
5
-
6
- describe 'Properties' do
7
- it 'has #file_name' do
8
- expect(file.file_name).to eq 'Nyan_cat_250px_frame.png'
9
- end
10
-
11
- it 'has #content_type' do
12
- expect(file.content_type).to eq 'image/png'
13
- end
14
-
15
- it 'has #url' do
16
- expect(file.url).to eq '//images.contentful.com/cfexampleapi/4gp6taAwW4CmSgumq2ekUm/9da0cd1936871b8d72343e895a00d611/Nyan_cat_250px_frame.png'
17
- end
18
-
19
- it 'has #details' do
20
- expect(file.details).to be_instance_of Hash
21
- end
22
- end
23
-
24
- describe 'camel case' do
25
- it 'supports camel case' do
26
- vcr('asset') {
27
- file = create_client(use_camel_case: true).asset('nyancat').file
28
- expect(file.contentType).to eq 'image/png'
29
- expect(file.fileName).to eq 'Nyan_cat_250px_frame.png'
30
- }
31
- end
32
- end
33
- end
@@ -1,14 +0,0 @@
1
- {
2
- "sys": {
3
- "type": "Error",
4
- "id": "BadRequest"
5
- },
6
- "details": {
7
- "errors": [
8
- {
9
- "details": "some error"
10
- }
11
- ]
12
- },
13
- "requestId": "85f-351076632"
14
- }
@@ -1,12 +0,0 @@
1
- {
2
- "sys": {
3
- "type": "Error",
4
- "id": "BadRequest"
5
- },
6
- "details": {
7
- "errors": [
8
- "some error"
9
- ]
10
- },
11
- "requestId": "85f-351076632"
12
- }
@@ -1,8 +0,0 @@
1
- {
2
- "sys": {
3
- "type": "Error",
4
- "id": "BadRequest"
5
- },
6
- "details": "some error",
7
- "requestId": "85f-351076632"
8
- }
@@ -1,13 +0,0 @@
1
- {
2
- "sys": {
3
- "type": "Error",
4
- "id": "AccessDenied"
5
- },
6
- "details": {
7
- "reasons": [
8
- "foo",
9
- "bar"
10
- ]
11
- },
12
- "requestId": "85f-351076632"
13
- }
@@ -1,8 +0,0 @@
1
- {
2
- "sys": {
3
- "type": "Error",
4
- "id": "NotFound"
5
- },
6
- "details": "The resource could not be found",
7
- "requestId": "85f-351076632"
8
- }
@@ -1,11 +0,0 @@
1
- {
2
- "sys": {
3
- "type": "Error",
4
- "id": "NotFound"
5
- },
6
- "details": {
7
- "type": "Asset",
8
- "id": "foobar"
9
- },
10
- "requestId": "85f-351076632"
11
- }
@@ -1,12 +0,0 @@
1
- {
2
- "sys": {
3
- "type": "Error",
4
- "id": "NotFound"
5
- },
6
- "details": {
7
- "sys": {
8
- "type": "Space"
9
- }
10
- },
11
- "requestId": "85f-351076632"
12
- }
@@ -1,10 +0,0 @@
1
- {
2
- "sys": {
3
- "type": "Error",
4
- "id": "NotFound"
5
- },
6
- "details": {
7
- "type": "Asset"
8
- },
9
- "requestId": "85f-351076632"
10
- }