contentful 2.8.0 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb7f32509e288f94600ecba8ee9758975a92bf7e8fe1ab39e5c6d72e5fad0697
4
- data.tar.gz: cefa5968867483761224da652f892300268ccc4ea6bd99cc282309a66a049bbd
3
+ metadata.gz: 1ad7719eac2d1ecec165d0a791478cce7cc1525bf6618b867b4b39284f6b84a2
4
+ data.tar.gz: 8d4441d877f5fda9817b9a6d813d18d0a489cdd01bf9668ad4f33fd0892db318
5
5
  SHA512:
6
- metadata.gz: 1ea5c191ba3e20361a2c933dd2b8445fb62c27e6621e90d10bb7400d42bd9c5804f9705875b6b9296619afe2ad0791ded8e631a99820d27cd14de81dc610446e
7
- data.tar.gz: cc711e933719830331302591d36c2428a5cc6f8358c084f311f7e631f10da61efbba6381364bea4f566817f79c7062d90e2d8878404952405008f5476f3a6afc
6
+ metadata.gz: 62491bdaddf51c6e0ae687959969210ba3508cc32c991da3085b676dfe28c05d6c95c6d51732c07b49556a94d9df61d6fe4975503b1becc3b6a50a088f5a6313
7
+ data.tar.gz: a0f0e6b4cb28382025573024d72d5ec913772fd0d88ae152291008c7541dc07eebce0897953726fdc08906f34c94ef9d99ef3c80ebd88f762181f8872f80e6f6
data/CHANGELOG.md CHANGED
@@ -2,9 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.8.1
6
+ ### Fixed
7
+ * Fixed deeply nested resources now also filter unresolvable entries. [#177](https://github.com/contentful/contentful.rb/issues/177)
8
+
5
9
  ## 2.8.0
6
10
  ### Added
7
- * Add support for `sync` on environments other than `master`.
11
+ * Added support for `sync` on environments other than `master`.
8
12
 
9
13
  ## 2.7.0
10
14
  ### Added
data/LICENSE.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2014 Contentful GmbH - Jan Lelis
4
- Copyright (c) 2016 Contentful GmbH - David Litvak
4
+ Copyright (c) 2015-2018 Contentful GmbH - David Litvak
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,11 +1,108 @@
1
- # contentful.rb
2
- [![Gem Version](https://badge.fury.io/rb/contentful.png)](http://badge.fury.io/rb/contentful) [![Build Status](https://travis-ci.org/contentful/contentful.rb.png)](https://travis-ci.org/contentful/contentful.rb)
3
-
4
- Ruby client for the [Contentful](https://www.contentful.com) Content Delivery API.
5
-
6
- [Contentful](https://www.contentful.com) provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.
7
-
8
- ## Setup
1
+ ![header](./.github/header.png)
2
+ <p align="center">
3
+ <a href="https://www.contentful.com/slack/">
4
+ <img src="https://img.shields.io/badge/-Join%20Community%20Slack-2AB27B.svg?logo=slack&maxAge=31557600" alt="Join Contentful Community Slack">
5
+ </a>
6
+ &nbsp;
7
+ <a href="https://www.contentfulcommunity.com/">
8
+ <img src="https://img.shields.io/badge/-Join%20Community%20Forum-3AB2E6.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MiA1OSI+CiAgPHBhdGggZmlsbD0iI0Y4RTQxOCIgZD0iTTE4IDQxYTE2IDE2IDAgMCAxIDAtMjMgNiA2IDAgMCAwLTktOSAyOSAyOSAwIDAgMCAwIDQxIDYgNiAwIDEgMCA5LTkiIG1hc2s9InVybCgjYikiLz4KICA8cGF0aCBmaWxsPSIjNTZBRUQyIiBkPSJNMTggMThhMTYgMTYgMCAwIDEgMjMgMCA2IDYgMCAxIDAgOS05QTI5IDI5IDAgMCAwIDkgOWE2IDYgMCAwIDAgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0UwNTM0RSIgZD0iTTQxIDQxYTE2IDE2IDAgMCAxLTIzIDAgNiA2IDAgMSAwLTkgOSAyOSAyOSAwIDAgMCA0MSAwIDYgNiAwIDAgMC05LTkiLz4KICA8cGF0aCBmaWxsPSIjMUQ3OEE0IiBkPSJNMTggMThhNiA2IDAgMSAxLTktOSA2IDYgMCAwIDEgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0JFNDMzQiIgZD0iTTE4IDUwYTYgNiAwIDEgMS05LTkgNiA2IDAgMCAxIDkgOSIvPgo8L3N2Zz4K&maxAge=31557600"
9
+ alt="Join Contentful Community Forum">
10
+ </a>
11
+ </p>
12
+
13
+ # contentful.rb - Contentful Ruby Delivery SDK
14
+ [![Gem Version](https://badge.fury.io/rb/contentful.png)](http://badge.fury.io/rb/contentful)
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.
17
+
18
+ <p align="center">
19
+ <img src="https://img.shields.io/badge/Status-Maintained-green.svg" alt="This repository is actively maintained" /> &nbsp;
20
+ <a href="LICENSE.txt">
21
+ <img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License" />
22
+ </a>
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">
26
+ </a>
27
+ </p>
28
+
29
+ <p align="center">
30
+ <a href="https://rubygems.org/gems/contentful">
31
+ <img src="https://img.shields.io/gem/v/contentful.svg" alt="RubyGems version">
32
+ </a>
33
+ &nbsp;
34
+ <a href="https://rubygems.org/gems/contentful">
35
+ <img src="https://img.shields.io/gem/dt/contentful.svg" alt="RubyGems downloads">
36
+ </a>
37
+ </p>
38
+
39
+ **What is Contentful?**
40
+
41
+ [Contentful](https://www.contentful.com/) provides content infrastructure for digital teams to power websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship their products faster.
42
+
43
+ <details>
44
+ <summary>Table of contents</summary>
45
+
46
+ <!-- TOC -->
47
+
48
+ - [contentful.rb - Contentful Ruby Delivery SDK](#contentfulrb---contentful-ruby-delivery-sdk)
49
+ - [Core Features](#core-features)
50
+ - [Getting started](#getting-started)
51
+ - [Installation](#installation)
52
+ - [Your first request](#your-first-request)
53
+ - [Using this SDK with the Preview API](#using-this-sdk-with-the-preview-api)
54
+ - [Authentication](#authentication)
55
+ - [Documentation & References](#documentation--references)
56
+ - [Configuration](#configuration)
57
+ - [Reference documentation](#reference-documentation)
58
+ - [Basic queries](#basic-queries)
59
+ - [Filtering options](#filtering-options)
60
+ - [Accessing fields and sys properties](#accessing-fields-and-sys-properties)
61
+ - [Dynamic entries](#dynamic-entries)
62
+ - [Using different locales](#using-different-locales)
63
+ - [Arrays](#arrays)
64
+ - [Links](#links)
65
+ - [Assets](#assets)
66
+ - [Resource options](#resource-options)
67
+ - [Field type `Object`](#field-type-object)
68
+ - [Advanced concepts](#advanced-concepts)
69
+ - [Proxy example](#proxy-example)
70
+ - [Custom resource classes](#custom-resource-classes)
71
+ - [Synchronization](#synchronization)
72
+ - [Migrating to 2.x](#migrating-to-2x)
73
+ - [Tutorials & other resources](#tutorials--other-resources)
74
+ - [Reach out to us](#reach-out-to-us)
75
+ - [You have questions about how to use this library?](#you-have-questions-about-how-to-use-this-library)
76
+ - [You found a bug or want to propose a feature?](#you-found-a-bug-or-want-to-propose-a-feature)
77
+ - [You need to share confidential information or have other questions?](#you-need-to-share-confidential-information-or-have-other-questions)
78
+ - [Get involved](#get-involved)
79
+ - [License](#license)
80
+ - [Code of Conduct](#code-of-conduct)
81
+
82
+ <!-- /TOC -->
83
+
84
+ </details>
85
+
86
+ ## Core Features
87
+
88
+ - Content retrieval through [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/).
89
+ - [Synchronization](https://www.contentful.com/developers/docs/concepts/sync/)
90
+ - [Localization support](https://www.contentful.com/developers/docs/concepts/locales/)
91
+ - [Link resolution](https://www.contentful.com/developers/docs/concepts/links/)
92
+ - Built in rate limiting recovery procedures
93
+ - Supports [Environments](https://www.contentful.com/developers/docs/concepts/multiple-environments/) (**since v2.6.0 - 16. April 2018**)
94
+
95
+ ## Getting started
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.
98
+
99
+ - [Installation](#installation)
100
+ - [Your first request](#your-first-request)
101
+ - [Using this SDK with the Preview API](#using-this-sdk-with-the-preview-api)
102
+ - [Authentication](#authentication)
103
+ - [Documentation & References](#documentation--references)
104
+
105
+ ### Installation
9
106
 
10
107
  Add to your Gemfile and bundle:
11
108
 
@@ -13,21 +110,38 @@ Add to your Gemfile and bundle:
13
110
  gem 'contentful'
14
111
  ```
15
112
 
16
- ## Usage
113
+ Or install it directly from your console:
114
+
115
+ ```bash
116
+ gem i contentful
117
+ ```
118
+
119
+ ### Your first request
120
+
121
+ The following code snippet is the most basic one you can use to get some content from Contentful with this SDK:
17
122
 
18
123
  ```ruby
124
+ require 'contentful'
125
+
19
126
  client = Contentful::Client.new(
20
- access_token: 'b4c0n73n7fu1',
21
- space: 'cfexampleapi'
127
+ space: 'cfexampleapi', # This is the space ID. A space is like a project folder in Contentful terms
128
+ access_token: 'b4c0n73n7fu1' # This is the access token for this space. Normally you get both ID and the token in the Contentful web app
22
129
  )
130
+
131
+ # This API call will request an entry with the specified ID from the space defined at the top, using a space-specific access token.
132
+ entry = client.entry('nyancat')
23
133
  ```
24
134
 
25
- If you plan on using the [Preview API](https://www.contentful.com/developers/docs/references/content-preview-api/) you need to specify the `api_url`:
135
+ ### Using this SDK with the Preview API
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:
26
138
 
27
139
  ```ruby
140
+ require 'contentful'
141
+
28
142
  client = Contentful::Client.new(
29
- access_token: 'b4c0n73n7fu1',
30
143
  space: 'cfexampleapi',
144
+ access_token: 'b4c0n73n7fu1',
31
145
  api_url: 'preview.contentful.com'
32
146
  )
33
147
  ```
@@ -35,11 +149,225 @@ client = Contentful::Client.new(
35
149
  You can query for entries, assets, etc. very similar as described in the
36
150
  [Delivery API Documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/). Please note, that **all methods of the Ruby client library are snake_cased, instead of JavaScript's camelCase**:
37
151
 
152
+ ### Authentication
153
+
154
+ To get your own content from Contentful, an app should authenticate with an OAuth bearer token.
155
+
156
+ You can create API keys using the [Contentful web interface](https://app.contentful.com). Go to the app, open the space that you want to access (top left corner lists all the spaces), and navigate to the APIs area. Open the API Keys section and create your first token. Done.
157
+
158
+ Don't forget to also get your Space ID.
159
+
160
+ For more information, check the [Contentful REST API reference on Authentication](https://www.contentful.com/developers/docs/references/authentication/).
161
+
162
+ ## Documentation & References
163
+
164
+ - [Configuration](#configuration)
165
+ - [Reference documentation](#reference-documentation)
166
+ - [Tutorials & other resources](#tutorials--other-resources)
167
+ - [Advanced Concepts](#advanced-concepts)
168
+ - [Migrating to 2.x](#migrating-to-2x)
169
+
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.
172
+
173
+ ### Configuration
174
+
175
+ The client constructor supports several options you may set to achieve the expected behavior:
176
+
38
177
  ```ruby
39
- client.content_types
40
- client.entry 'nyancat'
178
+ client = Contentful::Client.new(
179
+ # ... your options here ...
180
+ )
181
+ ```
182
+
183
+ <table>
184
+ <thead>
185
+ <tr>
186
+ <th>Name</th>
187
+ <th>Default</th>
188
+ <th>Description</th>
189
+ </tr>
190
+ </thead>
191
+ <tbody>
192
+ <tr>
193
+ <td><code>access_token</code></td>
194
+ <td></td>
195
+ <td><strong>Required</strong>. Your access token.</td>
196
+ </tr>
197
+ <tr>
198
+ <td><code>space</code></td>
199
+ <td></td>
200
+ <td><strong>Required</strong>. Your space ID.</td>
201
+ </tr>
202
+ <tr>
203
+ <td><code>environment</code></td>
204
+ <td>'master'</td>
205
+ <td>Your environment ID.</td>
206
+ </tr>
207
+ <tr>
208
+ <td><code>api_url</code></td>
209
+ <td><code>'cdn.contentful.com'</code></td>
210
+ <td>Set the host used to build the request URIs.</td>
211
+ </tr>
212
+ <tr>
213
+ <td><code>default_locale</code></td>
214
+ <td><code>'en-US'</code></td>
215
+ <td>Defines default locale for the client.</td>
216
+ </tr>
217
+ <tr>
218
+ <td><code>environment</code></td>
219
+ <td><code>'master'</code></td>
220
+ <td>Defines default environment to access.</td>
221
+ </tr>
222
+ <tr>
223
+ <td><code>secure</code></td>
224
+ <td><code>true</code></td>
225
+ <td>Defines whether to use HTTPS or HTTP. By default we use HTTPS.</td>
226
+ </tr>
227
+ <tr>
228
+ <td><code>authentication_mechanism</code></td>
229
+ <td><code>:header</code></td>
230
+ <td>Sets the authentication mechanisms, valid options are <code>:header</code> or <code>:query_string</code></td>
231
+ </tr>
232
+ <tr>
233
+ <td><code>raise_errors</code></td>
234
+ <td><code>true</code></td>
235
+ <td>Determines whether errors are raised or returned.</td>
236
+ </tr>
237
+ <tr>
238
+ <td><code>dynamic_entries</code></td>
239
+ <td><code>:manual</code></td>
240
+ <td>
241
+ Determines if content type caching is enabled automatically or not,
242
+ allowing for accessing of fields even when they are not present on the response.
243
+ Valid options are <code>:auto</code> and <code>:manual</code>.
244
+ </td>
245
+ </tr>
246
+ <tr>
247
+ <td><code>raw_mode</code></td>
248
+ <td><code>false</code></td>
249
+ <td>If enabled, API responses are not parsed and the raw response object is returned instead.</td>
250
+ </tr>
251
+ <tr>
252
+ <td><code>resource_mapping</code></td>
253
+ <td><code>{}</code></td>
254
+ <td>Allows for overriding default resource classes with custom ones.</td>
255
+ </tr>
256
+ <tr>
257
+ <td><code>entry_mapping</code></td>
258
+ <td><code>{}</code></td>
259
+ <td>Allows for overriding of specific entry classes by content type.</td>
260
+ </tr>
261
+ <tr>
262
+ <td><code>gzip_encoded</code></td>
263
+ <td><code>true</code></td>
264
+ <td>Enables gzip response content encoding.</td>
265
+ </tr>
266
+ <tr>
267
+ <td><code>max_rate_limit_retries</code></td>
268
+ <td><code>1</code></td>
269
+ <td>
270
+ To increase or decrease the retry attempts after a 429 Rate Limit error. Default value is 1. Using 0 will disable retry behaviour.
271
+ Each retry will be attempted after the value (in seconds) of the <code>X-Contentful-RateLimit-Reset</code> header,
272
+ which contains the amount of seconds until the next non rate limited request is available, has passed.
273
+ This is blocking per execution thread.
274
+ </td>
275
+ </tr>
276
+ <tr>
277
+ <td><code>max_rate_limit_wait</code></td>
278
+ <td><code>60</code></td>
279
+ <td>
280
+ Maximum time to wait for next available request (in seconds). Default value is 60 seconds.
281
+ Keep in mind that if you hit the hourly rate limit maximum, you can have up to 60 minutes of blocked requests.
282
+ It is set to a default of 60 seconds in order to avoid blocking processes for too long, as rate limit retry behaviour
283
+ is blocking per execution thread.
284
+ </td>
285
+ </tr>
286
+ <tr>
287
+ <td><code>max_include_resolution_depth</code></td>
288
+ <td><code>20</code></td>
289
+ <td>
290
+ Maximum amount of levels to resolve includes for SDK entities
291
+ (this is independent of API-level includes - it represents the maximum depth the include resolution
292
+ tree is allowed to resolved before falling back to <code>Link</code> objects).
293
+ This include resolution strategy is in place in order to avoid having infinite circular recursion on resources with circular dependencies.
294
+ <strong>Note</strong>: If you're using something like <code>Rails::cache</code> it's advisable to considerably lower this value
295
+ (around 5 has proven to be a good compromise - but keep it higher or equal than your maximum API-level include parameter if you need the entire tree resolution).
296
+ Note that when <code>reuse_entries</code> is enabled, the max include resolution depth only affects
297
+ deep chains of unique objects (ie, not simple circular references).
298
+ </td>
299
+ </tr>
300
+ <tr>
301
+ <td><code>reuse_entries</code></td>
302
+ <td><code>false</code></td>
303
+ <td>
304
+ When enabled, reuse hydrated Entry and Asset objects within the same request when possible.
305
+ Can result in a large speed increase and better handles cyclical object graphs.
306
+ This can be a good alternative to <code>max_include_resolution_depth</code> if your content model contains (or can contain) circular references.
307
+ <strong>Caching may break if this option is enabled, as it may generate stack errors.</strong>
308
+ When caching, deactivate this option and opt for a conservative <code>max_include_resolution_depth</code> value.
309
+ </td>
310
+ </tr>
311
+ <tr>
312
+ <td><code>use_camel_case</code></td>
313
+ <td><code>false</code></td>
314
+ <td>
315
+ When doing the v2 upgrade, all keys and accessors were changed to always use <code>snake_case</code>.
316
+ This option introduces the ability to use <code>camelCase</code> for keys and method accessors.
317
+ This is very useful for isomorphic applications.
318
+ </td>
319
+ </tr>
320
+ <tr>
321
+ <td><code>proxy_host</code></td>
322
+ <td><code>nil</code></td>
323
+ <td>To be able to perform a request behind a proxy, this needs to be set. It can be a domain or IP address of the proxy server.</td>
324
+ </tr>
325
+ <tr>
326
+ <td><code>proxy_port</code></td>
327
+ <td><code>nil</code></td>
328
+ <td>Specify the port number that is used by the proxy server for client connections.</td>
329
+ </tr>
330
+ <tr>
331
+ <td><code>proxy_username</code></td>
332
+ <td><code>nil</code></td>
333
+ <td>Username for proxy authentication.</td>
334
+ </tr>
335
+ <tr>
336
+ <td><code>proxy_password</code></td>
337
+ <td><code>nil</code></td>
338
+ <td>Password for proxy authentication.</td>
339
+ </tr>
340
+ <tr>
341
+ <td><code>logger</code></td>
342
+ <td><code>nil</code></td>
343
+ <td>To enable logging pass a logger instance compatible with <code>::Logger</code>.</td>
344
+ </tr>
345
+ <tr>
346
+ <td><code>log_level</code></td>
347
+ <td><code>::Logger::INFO</code></td>
348
+ <td>
349
+ The default severity is set to INFO and logs only the request attributes (headers, parameters and url).
350
+ Setting it to DEBUG will also log the raw JSON response.
351
+ </td>
352
+ </tr>
353
+ </tbody>
354
+ </table>
355
+
356
+ ### Reference documentation
357
+
358
+ #### Basic queries
359
+
360
+ ```ruby
361
+ content_types = client.content_types
362
+ cat_content_type = client.content_type 'cat'
363
+ nyancat = client.entry 'nyancat'
364
+ entries = client.entries
365
+ assets = client.assets
366
+ nyancat_asset = client.asset 'nyancat'
41
367
  ```
42
368
 
369
+ #### Filtering options
370
+
43
371
  You can pass the usual filter options to the query:
44
372
 
45
373
  ```ruby
@@ -49,7 +377,12 @@ client.entries(include: 1) # include one level of linked resources
49
377
  client.entries(content_type: 'cat', include: 1) # you can also combine multiple parameters
50
378
  ```
51
379
 
52
- The results are returned as Contentful::Resource objects. Multiple results will be returned as Contentful::Array. The properties of a resource can be accessed through Ruby methods.
380
+ To read more about filtering options you can check our [search parameters documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters).
381
+
382
+ The results are returned as `Contentful::BaseResource` objects. Multiple results will be returned as `Contentful::Array`.
383
+ The properties of a resource can be accessed through Ruby methods.
384
+
385
+ #### Accessing fields and sys properties
53
386
 
54
387
  ```ruby
55
388
  content_type = client.content_type 'cat'
@@ -64,18 +397,20 @@ entry.type # => 'Entry'
64
397
  asset.sys # { id: '...', type: '...' }
65
398
  ```
66
399
 
67
- Entry Fields usually don't have direct method accessors, since they are based on individual content types. These fields can be accessed through the `#fields` method:
400
+ Entry fields also have direct accessors and will be coerced to the type defined in it's content type.
401
+ However, if using `dynamic_entries: :manual`, coercion will not be done.
68
402
 
69
403
  ```ruby
70
404
  entry = client.entry 'nyancat'
71
- entry.fields[:color] # rainbow
405
+ entry.fields[:color] # 'rainbow'
406
+ entry.color # 'rainbow'
407
+ entry.birthday # #<DateTime: 2011-04-04T22:00:00+00:00 ((2455656j,79200s,0n),+0s,2299161j)>
72
408
  ```
73
409
 
74
- Please note, that no field type conversions will be done for entries by default.
410
+ #### Dynamic entries
75
411
 
76
- ### Dynamic Entries
77
-
78
- However, you can (and should) set `:dynamic_entries` to `:auto` in your client configuration. When using this option, the client will fetch all available content types and use them to create dynamic entries on the fly.
412
+ However, you can (and should) set `:dynamic_entries` to `:auto` in your client configuration.
413
+ When using this option, the client will cache all available content types and use them to hydrate entries when fields are missing in the response and coerce fields to their proper types.
79
414
 
80
415
  ```ruby
81
416
  client = Contentful::Client.new(
@@ -84,13 +419,14 @@ client = Contentful::Client.new(
84
419
  dynamic_entries: :auto
85
420
  )
86
421
 
87
- entry = client.entry 'nyancat' # => #<Contentful::DynamicEntry[cat]: ...>
422
+ entry = client.entry 'nyancat' # => #<Contentful::Entry[cat]: ...>
88
423
  entry.color # => 'rainbow'
424
+ entry.birthday # #<DateTime: 2011-04-04T22:00:00+00:00 ((2455656j,79200s,0n),+0s,2299161j)>
89
425
  ```
90
426
 
91
427
  Dynamic entries will have getter classes for the fields and do type conversions properly.
92
428
 
93
- The `:auto` mode will fetch all content types on initialization. If you want to do it by hand later, you will need to set the option to `:manual` and call `client.update_dynamic_entry_cache!` to initialize all dynamic entries.
429
+ The `:auto` mode will fetch all content types on initialization. If you want to do it by hand later, you will need to set the option to `:manual` and call `client.update_dynamic_entry_cache!` to initialize the cache.
94
430
 
95
431
  #### Using different locales
96
432
 
@@ -114,22 +450,22 @@ my_spanish_name = entries.first.fields('es-AR')[:name]
114
450
 
115
451
  When requesting multiple locales, the object accessor shortcuts only work for the default locale.
116
452
 
117
- ### Arrays
453
+ #### Arrays
118
454
 
119
455
  Contentful::Array has an `#each` method that delegates to its items. It also includes Ruby's Enumerable module, providing methods like `#min` or `#first`. See the Ruby core documentation for further details.
120
456
 
121
457
  Arrays also have a `#next_page` URL, which will rerun the request with a increased skip parameter, as described in [the documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/skip).
122
458
 
123
459
 
124
- ### Links
460
+ #### Links
125
461
 
126
462
  You can easily request a resource that is represented by a link by calling `#resolve`:
127
463
 
128
464
  ```ruby
129
465
  happycat = client.entry 'happycat'
130
- happycat.fields[:image]
466
+ happycat.image
131
467
  # => #<Contentful::Link: @sys={:type=>"Link", :linkType=>"Asset", :id=>"happycat"}>
132
- happycat.fields[:image].resolve # => #<Contentful::Asset: @fields={ ...
468
+ happycat.image.resolve(client) # => #<Contentful::Asset: @fields={ ...
133
469
  ```
134
470
 
135
471
  ### Assets
@@ -137,16 +473,16 @@ happycat.fields[:image].resolve # => #<Contentful::Asset: @fields={ ...
137
473
  There is a helpful method to add image resize options for an asset image:
138
474
 
139
475
  ```ruby
140
- client.asset('happycat').image_url
476
+ client.asset('happycat').url
141
477
  # => "//images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/
142
478
  # 382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg"
143
479
 
144
- client.asset('happycat').image_url width: 300, height: 200, format: 'jpg', quality: 100
480
+ client.asset('happycat').url(width: 300, height: 200, format: 'jpg', quality: 100)
145
481
  # => "//images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/
146
482
  # 382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg?w=300&h=200&fm=jpg&q=100"
147
483
  ```
148
484
 
149
- ### Resource Options
485
+ #### Resource options
150
486
 
151
487
  Resources, that have been requested directly (i.e. no child resources), can be fetched from the server again by calling `#reload`:
152
488
 
@@ -155,120 +491,15 @@ entries = client.entries
155
491
  entries.reload # Fetches the array of entries again
156
492
  ```
157
493
 
158
- ### Field Type "Object"
159
-
160
- While for known field types, the field data is accessible using methods or the `#fields` hash with symbol keys, it behaves differently for nested data of the type "Object". The client will treat them as arbitrary hashes and will not parse the data inside, which also means, this data is indexed by Ruby strings, not symbols.
161
-
162
-
163
- ## Client Configuration Options
164
- ### :space
165
-
166
- Required option. The name of the space you want to access.
167
-
168
- ### :access_token
169
-
170
- Required option. The space's secret token.
171
-
172
- ### :default_locale
173
-
174
- Defines default locale for the client. Defaults to `en-US`.
175
-
176
- ### :environment
177
-
178
- Defines default environment to access. Defaults to `master`.
179
-
180
- ### :secure
181
-
182
- Whether to use https. Defaults to `true`.
183
-
184
- ### :authentication_mechanism
185
-
186
- How to authenticate with the API. Supports `:header` (default) or `:query_string`.
494
+ #### Field type `Object`
187
495
 
188
- ### :raise_errors
496
+ While for known field types, the field data is accessible using methods or the `#fields` hash with symbol keys, it behaves differently for nested data of the type "Object".
497
+ The client will treat them as arbitrary hashes and will not parse the data inside.
189
498
 
190
- If set to `true` (default), error responses will be raised. If set to `false`, the error objects will simply be returned.
191
499
 
192
- ### :dynamic_entries
500
+ ### Advanced concepts
193
501
 
194
- `:auto` or `:manual`. See resource description above for details on usage.
195
-
196
- ### :raw_mode
197
-
198
- Defaults to `false`. If enabled, the API responses will not be parsed to resource objects. Might be useful for debugging.
199
-
200
- ### :resource_mapping
201
-
202
- See next paragraph for explanation
203
-
204
- ### :gzip_encoded
205
-
206
- Enables gzip response content encoding, default to: true
207
-
208
- ### :logger
209
-
210
- Logging is disabled by default, it can be enabled by setting a logger instance and a logging severity.
211
- ```ruby
212
- client = Contentful::Client.new(
213
- access_token: 'b4c0n73n7fu1',
214
- space: 'cfexampleapi',
215
- logger: logger_instance,
216
- log_level: Logger::DEBUG
217
- )
218
- ```
219
- Example loggers:
220
-
221
- ```ruby
222
- Rails.logger
223
- Logger.new('logfile.log')
224
- ```
225
-
226
- ### :log_level
227
- The default severity is set to INFO and logs only the request attributes (headers, parameters and url). Setting it to DEBUG will also log the raw JSON response.
228
-
229
- ### :proxy_host
230
-
231
- To be able to perform a request behind a proxy, you need to specify a ```:proxy_host```. This can be a domain or IP address of the proxy server.
232
-
233
- ### :proxy_port
234
-
235
- Specify the port number that is used by the proxy server for client connections.
236
-
237
- ### :port_password, :port_username
238
-
239
- To use the proxy with authentication, you need to specify ```port_username``` and ```port_password```.
240
-
241
- ### :max_rate_limit_retries
242
-
243
- To increase or decrease the retry attempts after a 429 Rate Limit error. Default value is 1. Using 0 will disable retry behaviour.
244
- Each retry will be attempted after the value (in seconds) of the `X-Contentful-RateLimit-Reset` header, which contains the amount of seconds until the next
245
- non rate limited request is available, has passed. This is blocking per execution thread.
246
-
247
- ### :max_rate_limit_wait
248
-
249
- Maximum time to wait for next available request (in seconds). Default value is 60 seconds. Keep in mind that if you hit the hourly rate limit maximum, you
250
- can have up to 60 minutes of blocked requests. It is set to a default of 60 seconds in order to avoid blocking processes for too long, as rate limit retry behaviour
251
- is blocking per execution thread.
252
-
253
- ### :reuse_entries
254
-
255
- When true, reuse hydrated Entry and Asset objects within the same request when possible. Can result in a large speed increase and better handles cyclical object graphs.
256
- This can be a good alternative to `max_include_resolution_depth` if your content model contains (or can contain) circular references.
257
-
258
- ### :max_include_resolution_depth
259
-
260
- Maximum amount of levels to resolve includes for SDK entities (this is independent of API-level includes - it represents the maximum depth the include resolution
261
- tree is allowed to resolved before falling back to `Link` objects). This include resolution strategy is in place in order to avoid having infinite circular recursion
262
- on resources with circular dependencies. Defaults to 20. _Note_: If you're using something like `Rails::cache` it's advisable to considerably lower this value
263
- (around 5 has proven to be a good compromise - but keep it higher or equal than your maximum API-level include parameter if you need the entire tree resolution).
264
- Note that when `reuse_entries` is enabled, the max include resolution depth only affects deep chains of unique objects (ie, not simple circular references).
265
-
266
- ### :use_camel_case
267
-
268
- When doing the v2 upgrade, all keys and accessors were changed to always use `snake_case`. This option introduces the ability to use `camelCase` for keys and method
269
- accessors. This is very useful for isomorphic applications.
270
-
271
- ### Proxy example
502
+ #### Proxy example
272
503
 
273
504
  ```ruby
274
505
  client = Contentful::Client.new(
@@ -281,8 +512,7 @@ client = Contentful::Client.new(
281
512
  )
282
513
  ```
283
514
 
284
- ## Advanced Usage
285
- ### Custom Resource Classes
515
+ #### Custom resource classes
286
516
 
287
517
  You can define your own classes that will be returned instead of the predefined ones. Consider, you want to build a better Asset class. One way to do this is:
288
518
 
@@ -306,9 +536,10 @@ client = Contentful::Client.new(
306
536
  )
307
537
  ```
308
538
 
309
- More information on `:resource_mapping` can be found in examples/resource_mapping.rb and more on custom classes in examples/custom_classes.rb
539
+ More information on `:resource_mapping` can be found in [examples/resource_mapping.rb](./examples/resource_mapping.rb)
540
+ and more on custom classes in [examples/custom_classes.rb](./examples/custom_classes.rb).
310
541
 
311
- You can also register custom entry classes to be used based on the entry's content_type using the :entry_mapping configuration:
542
+ You can also register custom entry classes to be used based on the entry's content_type using the `:entry_mapping` configuration:
312
543
 
313
544
  ```ruby
314
545
  class Cat < Contentful::Entry
@@ -326,9 +557,12 @@ client = Contentful::Client.new(
326
557
  client.entry('nyancat') # is instance of Cat
327
558
  ```
328
559
 
329
- ## Synchronization
560
+ #### Synchronization
330
561
 
331
- The client also includes a wrapper for the synchronization endpoint. You can initialize it with the options described in the [Delivery API Documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization) or an URL you received from a previous sync:
562
+ The client also includes a wrapper for the synchronization endpoint.
563
+ You can initialize it with the options described in the
564
+ [Delivery API Documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization)
565
+ or an URL you received from a previous sync:
332
566
 
333
567
  ```ruby
334
568
  client = Contentful::Client.new(
@@ -376,11 +610,7 @@ first_entry = client.sync(initial: true, type: 'Entry').first_page.items.first
376
610
  first_entry.fields('de-DE') # Returns German localizations
377
611
  ```
378
612
 
379
- ## Workarounds
380
-
381
- - When an entry has related entries that are unpublished, they still end up in the resource as unresolved links. We consider this correct, because it is in line with the API responses and our other SDKs. However, you can use the workaround from [issue #60](/../../issues/60) if you happen to want this working differently.
382
-
383
- ## Migrating to 2.x
613
+ ### Migrating to 2.x
384
614
 
385
615
  If you're a `0.x` or a `1.x` user of this gem, and are planning to migrate to the current `2.x` branch.
386
616
  There are a few breaking changes you have to take into account:
@@ -396,9 +626,37 @@ There are a few breaking changes you have to take into account:
396
626
 
397
627
  For more information on the internal changes present in the 2.x release, please read the [CHANGELOG](CHANGELOG.md)
398
628
 
629
+ ### Tutorials & other resources
630
+
631
+ * This library is a wrapper around our Contentful Delivery REST API. Some more specific details such as search parameters and pagination are better explained on the [REST API reference](https://www.contentful.com/developers/docs/references/content-delivery-api/), and you can also get a better understanding of how the requests look under the hood.
632
+ * Check the [Contentful for Ruby](https://www.contentful.com/developers/docs/ruby/) page for Tutorials, Demo Apps, and more information on other ways of using Ruby with Contentful
633
+
634
+ ## Reach out to us
635
+
636
+ ### You have questions about how to use this library?
637
+ * Reach out to our community forum: [![Contentful Community Forum](https://img.shields.io/badge/-Join%20Community%20Forum-3AB2E6.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MiA1OSI+CiAgPHBhdGggZmlsbD0iI0Y4RTQxOCIgZD0iTTE4IDQxYTE2IDE2IDAgMCAxIDAtMjMgNiA2IDAgMCAwLTktOSAyOSAyOSAwIDAgMCAwIDQxIDYgNiAwIDEgMCA5LTkiIG1hc2s9InVybCgjYikiLz4KICA8cGF0aCBmaWxsPSIjNTZBRUQyIiBkPSJNMTggMThhMTYgMTYgMCAwIDEgMjMgMCA2IDYgMCAxIDAgOS05QTI5IDI5IDAgMCAwIDkgOWE2IDYgMCAwIDAgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0UwNTM0RSIgZD0iTTQxIDQxYTE2IDE2IDAgMCAxLTIzIDAgNiA2IDAgMSAwLTkgOSAyOSAyOSAwIDAgMCA0MSAwIDYgNiAwIDAgMC05LTkiLz4KICA8cGF0aCBmaWxsPSIjMUQ3OEE0IiBkPSJNMTggMThhNiA2IDAgMSAxLTktOSA2IDYgMCAwIDEgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0JFNDMzQiIgZD0iTTE4IDUwYTYgNiAwIDEgMS05LTkgNiA2IDAgMCAxIDkgOSIvPgo8L3N2Zz4K&maxAge=31557600)](https://support.contentful.com/)
638
+ * Jump into our community slack channel: [![Contentful Community Slack](https://img.shields.io/badge/-Join%20Community%20Slack-2AB27B.svg?logo=slack&maxAge=31557600)](https://www.contentful.com/slack/)
639
+
640
+ ### You found a bug or want to propose a feature?
641
+
642
+ * File an issue here on GitHub: [![File an issue](https://img.shields.io/badge/-Create%20Issue-6cc644.svg?logo=github&maxAge=31557600)](https://github.com/contentful/contentful.rb/issues/new). Make sure to remove any credential from your code before sharing it.
643
+
644
+ ### You need to share confidential information or have other questions?
645
+
646
+ * File a support ticket at our Contentful Customer Support: [![File support ticket](https://img.shields.io/badge/-Submit%20Support%20Ticket-3AB2E6.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MiA1OSI+CiAgPHBhdGggZmlsbD0iI0Y4RTQxOCIgZD0iTTE4IDQxYTE2IDE2IDAgMCAxIDAtMjMgNiA2IDAgMCAwLTktOSAyOSAyOSAwIDAgMCAwIDQxIDYgNiAwIDEgMCA5LTkiIG1hc2s9InVybCgjYikiLz4KICA8cGF0aCBmaWxsPSIjNTZBRUQyIiBkPSJNMTggMThhMTYgMTYgMCAwIDEgMjMgMCA2IDYgMCAxIDAgOS05QTI5IDI5IDAgMCAwIDkgOWE2IDYgMCAwIDAgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0UwNTM0RSIgZD0iTTQxIDQxYTE2IDE2IDAgMCAxLTIzIDAgNiA2IDAgMSAwLTkgOSAyOSAyOSAwIDAgMCA0MSAwIDYgNiAwIDAgMC05LTkiLz4KICA8cGF0aCBmaWxsPSIjMUQ3OEE0IiBkPSJNMTggMThhNiA2IDAgMSAxLTktOSA2IDYgMCAwIDEgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0JFNDMzQiIgZD0iTTE4IDUwYTYgNiAwIDEgMS05LTkgNiA2IDAgMCAxIDkgOSIvPgo8L3N2Zz4K&maxAge=31557600)](https://www.contentful.com/support/)
647
+
648
+ ## Get involved
649
+
650
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?maxAge=31557600)](http://makeapullrequest.com)
651
+
652
+ We appreciate any help on our repositories. For more details about how to contribute see our [CONTRIBUTING.md](CONTRIBUTING.md) document.
653
+
399
654
  ## License
400
655
 
401
- Copyright (c) 2014 Contentful GmbH - Jan Lelis.
402
- Copyright (c) 2016 Contentful GmbH - David Litvak.
656
+ This repository is published under the [MIT](LICENSE.txt) license.
657
+
658
+ ## Code of Conduct
659
+
660
+ We want to provide a safe, inclusive, welcoming, and harassment-free space and experience for all participants, regardless of gender identity and expression, sexual orientation, disability, physical appearance, socioeconomic status, body size, ethnicity, nationality, level of experience, age, religion (or lack thereof), or other identity markers.
403
661
 
404
- See LICENSE.txt for further details.
662
+ [Read our full Code of Conduct](https://github.com/contentful-developer-relations/community-code-of-conduct).
data/contentful.gemspec CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |gem|
34
34
  gem.add_development_dependency 'guard-rspec'
35
35
  gem.add_development_dependency 'guard-rubocop'
36
36
  gem.add_development_dependency 'guard-yard'
37
- gem.add_development_dependency 'rubocop', '~> 0.41.0'
37
+ gem.add_development_dependency 'rubocop', '~> 0.49.1'
38
38
  gem.add_development_dependency 'rspec', '~> 3'
39
39
  gem.add_development_dependency 'rr'
40
40
  gem.add_development_dependency 'vcr'
@@ -80,7 +80,7 @@ module Contentful
80
80
  file_json = raw.fetch('fields', {}).fetch('file', nil)
81
81
  return if file_json.nil?
82
82
 
83
- is_localized = file_json.keys.none? { |f| %w(fileName contentType details url).include? f }
83
+ is_localized = file_json.keys.none? { |f| %w[fileName contentType details url].include? f }
84
84
  if is_localized
85
85
  locales.each do |locale|
86
86
  @fields[locale][:file] = ::Contentful::File.new(file_json[locale.to_s] || {}, @configuration)
@@ -66,9 +66,9 @@ module Contentful
66
66
  def hydrate_sys
67
67
  result = {}
68
68
  raw.fetch('sys', {}).each do |k, v|
69
- if %w(space contentType environment).include?(k)
69
+ if %w[space contentType environment].include?(k)
70
70
  v = build_link(v)
71
- elsif %w(createdAt updatedAt deletedAt).include?(k)
71
+ elsif %w[createdAt updatedAt deletedAt].include?(k)
72
72
  v = DateTime.parse(v)
73
73
  end
74
74
  result[Support.snakify(k, @configuration[:use_camel_case]).to_sym] = v
@@ -364,10 +364,9 @@ module Contentful
364
364
  logger.debug(response: response) if logger
365
365
  configuration[:resource_builder].new(
366
366
  response.object,
367
- configuration,
367
+ configuration.merge(endpoint: response.request.endpoint),
368
368
  (response.request.query || {}).fetch(:locale, nil) == '*',
369
- 0,
370
- response.request.endpoint
369
+ 0
371
370
  ).run
372
371
  end
373
372
 
@@ -414,7 +413,7 @@ module Contentful
414
413
  end
415
414
 
416
415
  def normalize_configuration!
417
- [:space, :access_token, :api_url, :default_locale].each { |s| configuration[s] = configuration[s].to_s }
416
+ %i[space access_token api_url default_locale].each { |s| configuration[s] = configuration[s].to_s }
418
417
  configuration[:authentication_mechanism] = configuration[:authentication_mechanism].to_sym
419
418
  end
420
419
 
@@ -424,10 +423,10 @@ module Contentful
424
423
  fail ArgumentError, 'The client configuration needs to contain an :api_url' if configuration[:api_url].empty?
425
424
  fail ArgumentError, 'The client configuration needs to contain a :default_locale' if configuration[:default_locale].empty?
426
425
  fail ArgumentError, 'The :api_version must be a positive number or nil' unless configuration[:api_version].to_i >= 0
427
- fail ArgumentError, 'The authentication mechanism must be :header or :query_string' unless [:header, :query_string].include?(
426
+ fail ArgumentError, 'The authentication mechanism must be :header or :query_string' unless %i[header query_string].include?(
428
427
  configuration[:authentication_mechanism]
429
428
  )
430
- fail ArgumentError, 'The :dynamic_entries mode must be :auto or :manual' unless [:auto, :manual].include?(
429
+ fail ArgumentError, 'The :dynamic_entries mode must be :auto or :manual' unless %i[auto manual].include?(
431
430
  configuration[:dynamic_entries]
432
431
  )
433
432
  end
@@ -17,7 +17,7 @@ module Contentful
17
17
 
18
18
  def coerce(field_id, value, includes, errors, entries = {})
19
19
  if Support.link?(value) && !Support.unresolvable?(value, errors)
20
- return build_nested_resource(value, includes, entries)
20
+ return build_nested_resource(value, includes, entries, errors)
21
21
  end
22
22
  return coerce_link_array(value, includes, errors, entries) if Support.link_array?(value)
23
23
 
@@ -35,7 +35,8 @@ module Contentful
35
35
  def coerce_link_array(value, includes, errors, entries)
36
36
  items = []
37
37
  value.each do |link|
38
- items << build_nested_resource(link, includes, entries) unless Support.unresolvable?(link, errors)
38
+ nested_resource = build_nested_resource(link, includes, entries, errors) unless Support.unresolvable?(link, errors)
39
+ items << nested_resource unless nested_resource.nil?
39
40
  end
40
41
 
41
42
  items
@@ -45,16 +46,16 @@ module Contentful
45
46
  # in case one of the included items has a reference in an upper level,
46
47
  # so we can keep the include chain for that object as well
47
48
  # Any included object after the maximum include resolution depth will be just a Link
48
- def build_nested_resource(value, includes, entries)
49
+ def build_nested_resource(value, includes, entries, errors)
49
50
  if @depth < @configuration.fetch(:max_include_resolution_depth, 20)
50
51
  resource = Support.resource_for_link(value, includes)
51
- return resolve_include(resource, includes, entries) unless resource.nil?
52
+ return resolve_include(resource, includes, entries, errors) unless resource.nil?
52
53
  end
53
54
 
54
55
  build_link(value)
55
56
  end
56
57
 
57
- def resolve_include(resource, includes, entries)
58
+ def resolve_include(resource, includes, entries, errors)
58
59
  require_relative 'resource_builder'
59
60
 
60
61
  ResourceBuilder.new(
@@ -66,7 +67,7 @@ module Contentful
66
67
  ),
67
68
  localized,
68
69
  @depth + 1,
69
- includes
70
+ errors
70
71
  ).run
71
72
  end
72
73
 
@@ -32,7 +32,7 @@ module Contentful
32
32
 
33
33
  attr_reader :json, :default_locale, :endpoint, :depth, :localized, :resource_mapping, :entry_mapping, :resource
34
34
 
35
- def initialize(json, configuration = {}, localized = false, depth = 0, endpoint = nil)
35
+ def initialize(json, configuration = {}, localized = false, depth = 0, errors = [])
36
36
  @json = json
37
37
  @default_locale = configuration.fetch(:default_locale, ::Contentful::Client::DEFAULT_CONFIGURATION[:default_locale])
38
38
  @resource_mapping = default_resource_mapping.merge(configuration.fetch(:resource_mapping, {}))
@@ -40,9 +40,10 @@ module Contentful
40
40
  @includes_for_single = configuration.fetch(:includes_for_single, [])
41
41
  @localized = localized
42
42
  @depth = depth
43
- @endpoint = endpoint
43
+ @endpoint = configuration.fetch(:endpoint, nil)
44
44
  @configuration = configuration
45
45
  @resource_cache = configuration[:_entries_cache] || {}
46
+ @errors = errors
46
47
  end
47
48
 
48
49
  # Starts the parsing process.
@@ -58,8 +59,8 @@ module Contentful
58
59
  private
59
60
 
60
61
  def build_array
61
- includes = fetch_includes
62
- errors = fetch_errors
62
+ includes = fetch_includes || @includes_for_single
63
+ errors = fetch_errors || @errors
63
64
 
64
65
  result = json['items'].map do |item|
65
66
  next if Support.unresolvable?(item, errors)
@@ -70,12 +71,13 @@ module Contentful
70
71
  end
71
72
 
72
73
  def build_single
74
+ return if Support.unresolvable?(json, @errors)
73
75
  includes = @includes_for_single
74
- build_item(json, includes)
76
+ build_item(json, includes, @errors)
75
77
  end
76
78
 
77
79
  def build_item(item, includes = [], errors = [])
78
- buildables = %w(Entry Asset ContentType Space DeletedEntry DeletedAsset Locale)
80
+ buildables = %w[Entry Asset ContentType Space DeletedEntry DeletedAsset Locale]
79
81
  item_type = buildables.detect { |b| b.to_s == item['sys']['type'] }
80
82
  fail UnparsableResource, 'Item type is not known, could not parse' if item_type.nil?
81
83
  item_class = resource_class(item)
@@ -102,7 +104,7 @@ module Contentful
102
104
  end
103
105
 
104
106
  def resource_class(item)
105
- return fetch_custom_resource_class(item) if %w(Entry DeletedEntry Asset DeletedAsset).include?(item['sys']['type'])
107
+ return fetch_custom_resource_class(item) if %w[Entry DeletedEntry Asset DeletedAsset].include?(item['sys']['type'])
106
108
  resource_mapping[item['sys']['type']]
107
109
  end
108
110
 
@@ -112,13 +114,13 @@ module Contentful
112
114
  resource_class = entry_mapping[item['sys']['contentType']['sys']['id']]
113
115
  return resource_class unless resource_class.nil?
114
116
 
115
- return fetch_custom_resource_mapping(item, 'Entry', Entry)
117
+ fetch_custom_resource_mapping(item, 'Entry', Entry)
116
118
  when 'Asset'
117
- return fetch_custom_resource_mapping(item, 'Asset', Asset)
119
+ fetch_custom_resource_mapping(item, 'Asset', Asset)
118
120
  when 'DeletedEntry'
119
- return fetch_custom_resource_mapping(item, 'DeletedEntry', DeletedEntry)
121
+ fetch_custom_resource_mapping(item, 'DeletedEntry', DeletedEntry)
120
122
  when 'DeletedAsset'
121
- return fetch_custom_resource_mapping(item, 'DeletedAsset', DeletedAsset)
123
+ fetch_custom_resource_mapping(item, 'DeletedAsset', DeletedAsset)
122
124
  end
123
125
  end
124
126
 
@@ -70,7 +70,7 @@ module Contentful
70
70
  json['items'].map(&:raw)
71
71
  end
72
72
 
73
- %w(Entry Asset).each do |type|
73
+ %w[Entry Asset].each do |type|
74
74
  if json.fetch('includes', {}).key?(type)
75
75
  includes.concat(json['includes'].fetch(type, []))
76
76
  end
@@ -1,5 +1,5 @@
1
1
  # Contentful Namespace
2
2
  module Contentful
3
3
  # Gem Version
4
- VERSION = '2.8.0'
4
+ VERSION = '2.8.1'
5
5
  end
data/spec/entry_spec.rb CHANGED
@@ -493,6 +493,14 @@ describe Contentful::Entry do
493
493
  expect(entry.modules.size).to eq 2
494
494
  }
495
495
  end
496
+
497
+ it 'unresolvable entries get filtered from results in deeply nested objects - #177' do
498
+ vcr('entries/unresolvable_filter_deeply_nested') {
499
+ client = create_client(space: 'z471hdso7l1a', access_token: '8a0e09fe71f1cb41e8788ace86a8c8d9d084599fe43a40070f232045014d2585', dynamic_entries: :auto)
500
+ entry = client.entry('1hb8sipClkQ8ggeGaeSQWm', include: 3)
501
+ expect(entry.should_published.first.should_unpublished.size).to eq 0
502
+ }
503
+ end
496
504
  end
497
505
 
498
506
  describe 'camel case' do
@@ -0,0 +1,167 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cdn.contentful.com/spaces/z471hdso7l1a/environments/master/content_types?limit=1000
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Contentful-User-Agent:
11
+ - sdk contentful.rb/2.8.0; platform ruby/2.5.1; os macOS/16;
12
+ Authorization:
13
+ - Bearer 8a0e09fe71f1cb41e8788ace86a8c8d9d084599fe43a40070f232045014d2585
14
+ Content-Type:
15
+ - application/vnd.contentful.delivery.v1+json
16
+ Accept-Encoding:
17
+ - gzip
18
+ Connection:
19
+ - close
20
+ Host:
21
+ - cdn.contentful.com
22
+ User-Agent:
23
+ - http.rb/2.2.2
24
+ response:
25
+ status:
26
+ code: 200
27
+ message: OK
28
+ headers:
29
+ Access-Control-Allow-Headers:
30
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation,X-Contentful-User-Agent,X-Contentful-Enable-Alpha-Feature
31
+ Access-Control-Allow-Methods:
32
+ - GET,HEAD,OPTIONS
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Expose-Headers:
36
+ - Etag
37
+ Access-Control-Max-Age:
38
+ - '86400'
39
+ Cache-Control:
40
+ - max-age=0
41
+ Content-Encoding:
42
+ - gzip
43
+ Content-Type:
44
+ - application/vnd.contentful.delivery.v1+json
45
+ Contentful-Api:
46
+ - cda_cached
47
+ Etag:
48
+ - W/"bd9b085d7149d27eb641ade78b5f9e95"
49
+ Server:
50
+ - Contentful
51
+ X-Content-Type-Options:
52
+ - nosniff
53
+ X-Contentful-Region:
54
+ - us-east-1
55
+ X-Contentful-Request-Id:
56
+ - d3448e736eb5c558812b3661b39230cc
57
+ Content-Length:
58
+ - '519'
59
+ Accept-Ranges:
60
+ - bytes
61
+ Date:
62
+ - Thu, 16 Aug 2018 12:15:11 GMT
63
+ Via:
64
+ - 1.1 varnish
65
+ Age:
66
+ - '644'
67
+ Connection:
68
+ - close
69
+ X-Served-By:
70
+ - cache-hhn1528-HHN
71
+ X-Cache:
72
+ - HIT
73
+ X-Cache-Hits:
74
+ - '1'
75
+ X-Timer:
76
+ - S1534421711.465073,VS0,VE1
77
+ Vary:
78
+ - Accept-Encoding
79
+ body:
80
+ encoding: ASCII-8BIT
81
+ string: !binary |-
82
+ H4sIAAAAAAAAA+1W3U/CMBB/568gfRayATLDGxp8Mr7ok4aYstXQ0LWz7Uim4X/32u6jIxBmYkxUGhJ21/ve3e/20ev3kSoUmvU/4BEIXWQEKDSXEhcIeLsLI6OFxgz4Y0upDc2ACCzBaEo1UGEQOAbVJDUWn61FZ3fPjXWlMhwbX5WEY3rBGIZlVkHdUb5BxmlzwD3fPJZBP1iLewI0Mfm8T6JwnSgRsRCbtKqzq59tou4gpxN7puoYbgTXhGvr0tOIJcGaJHNTCTQKwqtBcDUIp4/haBbALxxOptMnXyHPkq8pEL6lUvAUnHcqmsshxUoTuV+TrgVdeD5PFk2SLVVUcNMLpXBdU5RQlTFc3FLC7PvgOG3q5yjg3tSBooSoWNJMO4OouXg1Jpr+Mm+s1UEu75Z9I1P7uPc925uqGg9FuhKsVSvERIwZfScm6FfMFPG7C0nyllN55BJSxit25FLA0EC/VFabLiyflva/rN8vnqHVN81QOBtFw8to3HmGDir8hxm6Ps9QM6MHkEGtRc6Sl5xn+YpRtYYhbM20RQ7AIifXPyrX3pQtEz8EGi2f1db1Mz6xOreAbLCEAGEtnC73Fqe/WRdcS/s5UB1vb/4xxMLfhFjBbBINx6PuW/+gwn9ArPkZsbogVje8OiJ1RiuHXBVuld9XgF3L3q73CSJUdwcIDQAA
83
+ http_version:
84
+ recorded_at: Thu, 16 Aug 2018 12:15:11 GMT
85
+ - request:
86
+ method: get
87
+ uri: https://cdn.contentful.com/spaces/z471hdso7l1a/environments/master/entries?include=3&sys.id=1hb8sipClkQ8ggeGaeSQWm
88
+ body:
89
+ encoding: US-ASCII
90
+ string: ''
91
+ headers:
92
+ X-Contentful-User-Agent:
93
+ - sdk contentful.rb/2.8.0; platform ruby/2.5.1; os macOS/16;
94
+ Authorization:
95
+ - Bearer 8a0e09fe71f1cb41e8788ace86a8c8d9d084599fe43a40070f232045014d2585
96
+ Content-Type:
97
+ - application/vnd.contentful.delivery.v1+json
98
+ Accept-Encoding:
99
+ - gzip
100
+ Connection:
101
+ - close
102
+ Host:
103
+ - cdn.contentful.com
104
+ User-Agent:
105
+ - http.rb/2.2.2
106
+ response:
107
+ status:
108
+ code: 200
109
+ message: OK
110
+ headers:
111
+ Access-Control-Allow-Headers:
112
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation,X-Contentful-User-Agent,X-Contentful-Enable-Alpha-Feature
113
+ Access-Control-Allow-Methods:
114
+ - GET,HEAD,OPTIONS
115
+ Access-Control-Allow-Origin:
116
+ - "*"
117
+ Access-Control-Expose-Headers:
118
+ - Etag
119
+ Access-Control-Max-Age:
120
+ - '86400'
121
+ Cache-Control:
122
+ - max-age=0
123
+ Content-Encoding:
124
+ - gzip
125
+ Content-Type:
126
+ - application/vnd.contentful.delivery.v1+json
127
+ Contentful-Api:
128
+ - cda_cached
129
+ Etag:
130
+ - W/"be07dee9caef17c1b08b49fd01c2a0f0"
131
+ Server:
132
+ - Contentful
133
+ X-Content-Type-Options:
134
+ - nosniff
135
+ X-Contentful-Region:
136
+ - us-east-1
137
+ X-Contentful-Request-Id:
138
+ - c429d5bbcc5f56956ee750efcbe815e0
139
+ Content-Length:
140
+ - '647'
141
+ Accept-Ranges:
142
+ - bytes
143
+ Date:
144
+ - Thu, 16 Aug 2018 12:15:13 GMT
145
+ Via:
146
+ - 1.1 varnish
147
+ Age:
148
+ - '0'
149
+ Connection:
150
+ - close
151
+ X-Served-By:
152
+ - cache-hhn1550-HHN
153
+ X-Cache:
154
+ - MISS
155
+ X-Cache-Hits:
156
+ - '0'
157
+ X-Timer:
158
+ - S1534421714.565119,VS0,VE235
159
+ Vary:
160
+ - Accept-Encoding
161
+ body:
162
+ encoding: ASCII-8BIT
163
+ string: !binary |-
164
+ H4sIAAAAAAAAA61WXW+bMBR9z6+IeF4qIFlL8xZF3fawqcvaquumanJir7EwNrVNpqzKf68/MBgKJJPGA8LX9v0499wjXkbjcSD2IpiPX9SnWsh9jtQqWHAO9oGyHd7pM5JJQJQ9MiuR4lwtQrMgOMNSb4V2jSXKtMOfxqF124piIokcbHQod8IavVy0wRhdTp8xTQMds35UdJreljnfGI+tAxjqcv7OLqItFOyCREBX5Z5D9W3qtE9g70TbdSJwviTpKnl6Qh8BulndZ57/KrErKvne39hwBCSCC41LEIdRMgmTSXR+G8XzMJ7PpmfJ7PKHf6HI4b9dQHSHOaMZojrGcQxtSRkQEvE2RKfie+XFPIohRzssMKOONCW0G0alyrls2fG8T81t6fntZMAJbSdsA4hhP6KTuxvHk4oZwW+MCKyHRZcUUJCZK18B173wWCS2rCDwV16sCRZbpHloZ8JC4dfeMR8lXgP1m9mr2d8mYYPLU7hbLOmH2fMsDVmM42x5d/2w8CdBTXpnTx9Lq93V70cz9ohzxk+Zc8s8yuQ3JBjZgbWC2EPJFWj8vYUcIgkwaWHeA8ogHOVQTz/t5fmafOf4zz1bLYvn9CFOr6u4pti6SEw3pIDI00eLct3JuosNHS3B79K4/9HrLqVTfoe1rtVhf0ocON0saZx02L+lWzCsetPk7PJ95KueynhY9zqv9CtfP7ID6qcu9dCp7GFzxmrV9aZlCNluHVRR+5Wwv47TM+3Xw4on64Hxb7S8RxfLf4MSpg5tVJGcOn7BEDbmXtdo9bGgfQpZ/z3YGL24HOuh2j+ulBUuwxLhUvHVstl/p5i11Z7V9sPoMHoFbbYo2XUJAAA=
165
+ http_version:
166
+ recorded_at: Thu, 16 Aug 2018 12:15:13 GMT
167
+ recorded_with: VCR 4.0.0
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: 2.8.0
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contentful GmbH (Jan Lelis)
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-04-27 00:00:00.000000000 Z
13
+ date: 2018-08-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http
@@ -150,14 +150,14 @@ dependencies:
150
150
  requirements:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
- version: 0.41.0
153
+ version: 0.49.1
154
154
  type: :development
155
155
  prerelease: false
156
156
  version_requirements: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - "~>"
159
159
  - !ruby/object:Gem::Version
160
- version: 0.41.0
160
+ version: 0.49.1
161
161
  - !ruby/object:Gem::Dependency
162
162
  name: rspec
163
163
  requirement: !ruby/object:Gem::Requirement
@@ -453,6 +453,7 @@ files:
453
453
  - spec/fixtures/vcr_cassettes/entries/issue_117.yml
454
454
  - spec/fixtures/vcr_cassettes/entries/issue_125.yml
455
455
  - spec/fixtures/vcr_cassettes/entries/unresolvable_filter.yml
456
+ - spec/fixtures/vcr_cassettes/entries/unresolvable_filter_deeply_nested.yml
456
457
  - spec/fixtures/vcr_cassettes/entry.yml
457
458
  - spec/fixtures/vcr_cassettes/entry/custom_resource.yml
458
459
  - spec/fixtures/vcr_cassettes/entry/include_resolution.yml
@@ -593,6 +594,7 @@ test_files:
593
594
  - spec/fixtures/vcr_cassettes/entries/issue_117.yml
594
595
  - spec/fixtures/vcr_cassettes/entries/issue_125.yml
595
596
  - spec/fixtures/vcr_cassettes/entries/unresolvable_filter.yml
597
+ - spec/fixtures/vcr_cassettes/entries/unresolvable_filter_deeply_nested.yml
596
598
  - spec/fixtures/vcr_cassettes/entry.yml
597
599
  - spec/fixtures/vcr_cassettes/entry/custom_resource.yml
598
600
  - spec/fixtures/vcr_cassettes/entry/include_resolution.yml