contentful 2.16.3 → 2.17.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +3 -3
- data/lib/contentful/array.rb +2 -1
- data/lib/contentful/base_resource.rb +1 -1
- data/lib/contentful/coercions.rb +1 -4
- data/lib/contentful/entry.rb +4 -3
- data/lib/contentful/fields_resource.rb +3 -2
- data/lib/contentful/includes.rb +74 -0
- data/lib/contentful/resource_builder.rb +4 -3
- data/lib/contentful/support.rb +0 -35
- data/lib/contentful/version.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dee1859981813b1f776434d48109636bf85c1fb2a607788e147707cf9cd4949
|
4
|
+
data.tar.gz: 2195c59342837dd4772c063f27af1dcdb568bb6bbe7134d69ccf0cce5aeb9658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c21cda9e2af95df25dc7c38e3c019114de566d27a2c9b8a3d29229f45455ffd8da9ea94939bc9531a78d4d8dc9317bdc8780e27fd4500c237438cb1fdd0197d
|
7
|
+
data.tar.gz: 4fa5bbe0e7b9fad851269e0be826909e052e66808d8e9c4525ae73328b00d9932c5842dd0a6f392aee041d9e0b970b8a35af5e3b69473314d68e8253e03d5397
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,28 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 2.17.1
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
* Fixed typo in documentation
|
9
|
+
* Fixed changelog discrepancies
|
10
|
+
|
11
|
+
### Updated
|
12
|
+
* Updated `json` gem version
|
13
|
+
|
14
|
+
### Added
|
15
|
+
* Added ruby versions 3.1, 3.2 and 3.3 to CI. Removed 2.6 and 2.7.
|
16
|
+
|
17
|
+
## 2.17.0
|
18
|
+
|
19
|
+
### Updated
|
20
|
+
* Updated `http` gem version
|
21
|
+
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
* CI/CD vendor from travis to circleci
|
25
|
+
* 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)
|
26
|
+
|
5
27
|
## 2.16.3
|
6
28
|
### Fixed
|
7
29
|
* Fixed an issue where `raw['metadata']` was unexpectedly overwritten by `BaseResource#hydrate_metadata` method.
|
data/README.md
CHANGED
@@ -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
|
|
24
|
-
<a href="https://
|
25
|
-
<img src="https://
|
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
|
|
@@ -665,7 +665,7 @@ For more information on the internal changes present in the 2.x release, please
|
|
665
665
|
|
666
666
|
### You found a bug or want to propose a feature?
|
667
667
|
|
668
|
-
* File an issue here on GitHub: [](https://github.com/contentful/contentful.rb/issues/new). Make sure to remove any
|
668
|
+
* File an issue here on GitHub: [](https://github.com/contentful/contentful.rb/issues/new). Make sure to remove any credentials from your code before sharing it.
|
669
669
|
|
670
670
|
### You need to share confidential information or have other questions?
|
671
671
|
|
data/lib/contentful/array.rb
CHANGED
@@ -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)
|
@@ -47,7 +48,7 @@ module Contentful
|
|
47
48
|
require_relative 'resource_builder'
|
48
49
|
ResourceBuilder.new(
|
49
50
|
item.raw,
|
50
|
-
raw_object[:configuration].merge(includes_for_single:
|
51
|
+
raw_object[:configuration].merge(includes_for_single: Includes.from_response(raw, false)),
|
51
52
|
item.respond_to?(:localized) ? item.localized : false,
|
52
53
|
0,
|
53
54
|
raw_object[:configuration][:errors] || []
|
@@ -8,7 +8,7 @@ module Contentful
|
|
8
8
|
attr_reader :raw, :default_locale, :sys, :_metadata
|
9
9
|
|
10
10
|
# rubocop:disable Metrics/ParameterLists
|
11
|
-
def initialize(item, configuration = {}, _localized = false, _includes =
|
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]
|
data/lib/contentful/coercions.rb
CHANGED
@@ -155,10 +155,7 @@ module Contentful
|
|
155
155
|
|
156
156
|
return nil if Support.unresolvable?(node['data']['target'], configuration[:errors])
|
157
157
|
|
158
|
-
resource =
|
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?
|
data/lib/contentful/entry.rb
CHANGED
@@ -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.
|
@@ -30,7 +31,7 @@ module Contentful
|
|
30
31
|
content_type_field = content_type.field_for(field_id)
|
31
32
|
coercion_configuration = @configuration.merge(
|
32
33
|
includes_for_single:
|
33
|
-
@configuration.fetch(:includes_for_single,
|
34
|
+
@configuration.fetch(:includes_for_single, Includes.new) + includes,
|
34
35
|
_entries_cache: entries,
|
35
36
|
localized: localized,
|
36
37
|
depth: @depth,
|
@@ -58,7 +59,7 @@ module Contentful
|
|
58
59
|
# Any included object after the maximum include resolution depth will be just a Link
|
59
60
|
def build_nested_resource(value, includes, entries, errors)
|
60
61
|
if @depth < @configuration.fetch(:max_include_resolution_depth, 20)
|
61
|
-
resource =
|
62
|
+
resource = includes.find_link(value)
|
62
63
|
return resolve_include(resource, includes, entries, errors) unless resource.nil?
|
63
64
|
end
|
64
65
|
|
@@ -72,7 +73,7 @@ module Contentful
|
|
72
73
|
resource,
|
73
74
|
@configuration.merge(
|
74
75
|
includes_for_single:
|
75
|
-
@configuration.fetch(:includes_for_single,
|
76
|
+
@configuration.fetch(:includes_for_single, Includes.new) + includes,
|
76
77
|
_entries_cache: entries
|
77
78
|
),
|
78
79
|
localized,
|
@@ -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 =
|
13
|
+
def initialize(item, _configuration, localized = false, includes = Includes.new, entries = {}, depth = 0, errors = [])
|
13
14
|
super
|
14
15
|
|
15
16
|
@configuration[:errors] = errors
|
@@ -56,7 +57,7 @@ module Contentful
|
|
56
57
|
super(raw_object)
|
57
58
|
@localized = raw_object[:localized]
|
58
59
|
@fields = hydrate_fields(
|
59
|
-
raw_object[:configuration].fetch(:includes_for_single,
|
60
|
+
raw_object[:configuration].fetch(:includes_for_single, Includes.new),
|
60
61
|
{},
|
61
62
|
raw_object[:configuration].fetch(:errors, [])
|
62
63
|
)
|
@@ -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
|
@@ -8,6 +8,7 @@ require_relative 'link'
|
|
8
8
|
require_relative 'deleted_entry'
|
9
9
|
require_relative 'deleted_asset'
|
10
10
|
require_relative 'locale'
|
11
|
+
require_relative 'includes'
|
11
12
|
|
12
13
|
module Contentful
|
13
14
|
# Transforms a Contentful::Response into a Contentful::Resource or a Contentful::Error
|
@@ -39,7 +40,7 @@ module Contentful
|
|
39
40
|
@default_locale = configuration.fetch(:default_locale, ::Contentful::Client::DEFAULT_CONFIGURATION[:default_locale])
|
40
41
|
@resource_mapping = default_resource_mapping.merge(configuration.fetch(:resource_mapping, {}))
|
41
42
|
@entry_mapping = default_entry_mapping.merge(configuration.fetch(:entry_mapping, {}))
|
42
|
-
@includes_for_single = configuration.fetch(:includes_for_single,
|
43
|
+
@includes_for_single = configuration.fetch(:includes_for_single, Includes.new)
|
43
44
|
@localized = localized
|
44
45
|
@depth = depth
|
45
46
|
@endpoint = configuration.fetch(:endpoint, nil)
|
@@ -79,7 +80,7 @@ module Contentful
|
|
79
80
|
build_item(json, includes, @errors)
|
80
81
|
end
|
81
82
|
|
82
|
-
def build_item(item, includes =
|
83
|
+
def build_item(item, includes = Includes.new, errors = [])
|
83
84
|
item_type = BUILDABLES.detect { |b| b == item['sys']['type'] }
|
84
85
|
fail UnparsableResource, 'Item type is not known, could not parse' if item_type.nil?
|
85
86
|
item_class = resource_class(item)
|
@@ -98,7 +99,7 @@ module Contentful
|
|
98
99
|
end
|
99
100
|
|
100
101
|
def fetch_includes
|
101
|
-
|
102
|
+
Includes.from_response(json)
|
102
103
|
end
|
103
104
|
|
104
105
|
def fetch_errors
|
data/lib/contentful/support.rb
CHANGED
@@ -47,41 +47,6 @@ module Contentful
|
|
47
47
|
|
48
48
|
false
|
49
49
|
end
|
50
|
-
|
51
|
-
# Returns the resource that matches the link
|
52
|
-
#
|
53
|
-
# @param [Hash] link
|
54
|
-
# @param [::Array] includes
|
55
|
-
#
|
56
|
-
# @return [Hash]
|
57
|
-
def resource_for_link(link, includes)
|
58
|
-
includes.detect do |i|
|
59
|
-
i['sys']['id'] == link['sys']['id'] &&
|
60
|
-
i['sys']['type'] == link['sys']['linkType']
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# Returns combined include array from an API Response
|
65
|
-
#
|
66
|
-
# @param [Hash] json JSON Response
|
67
|
-
# @param [Bool] raw Response pre-proccessed?
|
68
|
-
#
|
69
|
-
# @return [Array]
|
70
|
-
def includes_from_response(json, raw = true)
|
71
|
-
includes = if raw
|
72
|
-
json['items'].dup
|
73
|
-
else
|
74
|
-
json['items'].map(&:raw)
|
75
|
-
end
|
76
|
-
|
77
|
-
%w[Entry Asset].each do |type|
|
78
|
-
if json.fetch('includes', {}).key?(type)
|
79
|
-
includes.concat(json['includes'].fetch(type, []))
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
includes
|
84
|
-
end
|
85
50
|
end
|
86
51
|
end
|
87
52
|
end
|
data/lib/contentful/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.17.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH (Jan Lelis)
|
8
8
|
- Contentful GmbH (Andreas Tiefenthaler)
|
9
9
|
- Contentful GmbH (David Litvak Bruno)
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-03-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: http
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0.8'
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
24
|
+
version: '6.0'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
version: '0.8'
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '6.0'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: multi_json
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,14 +150,14 @@ dependencies:
|
|
150
150
|
requirements:
|
151
151
|
- - "~>"
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version:
|
153
|
+
version: 1.60.2
|
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:
|
160
|
+
version: 1.60.2
|
161
161
|
- !ruby/object:Gem::Dependency
|
162
162
|
name: rspec
|
163
163
|
requirement: !ruby/object:Gem::Requirement
|
@@ -267,6 +267,7 @@ files:
|
|
267
267
|
- lib/contentful/field.rb
|
268
268
|
- lib/contentful/fields_resource.rb
|
269
269
|
- lib/contentful/file.rb
|
270
|
+
- lib/contentful/includes.rb
|
270
271
|
- lib/contentful/link.rb
|
271
272
|
- lib/contentful/locale.rb
|
272
273
|
- lib/contentful/location.rb
|
@@ -283,7 +284,7 @@ homepage: https://github.com/contentful/contentful.rb
|
|
283
284
|
licenses:
|
284
285
|
- MIT
|
285
286
|
metadata: {}
|
286
|
-
post_install_message:
|
287
|
+
post_install_message:
|
287
288
|
rdoc_options: []
|
288
289
|
require_paths:
|
289
290
|
- lib
|
@@ -298,8 +299,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
298
299
|
- !ruby/object:Gem::Version
|
299
300
|
version: '0'
|
300
301
|
requirements: []
|
301
|
-
rubygems_version: 3.
|
302
|
-
signing_key:
|
302
|
+
rubygems_version: 3.2.3
|
303
|
+
signing_key:
|
303
304
|
specification_version: 4
|
304
305
|
summary: contentful
|
305
306
|
test_files: []
|