contentful 2.15.4 → 2.16.0

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: 4e84df2f0ef19ecf855ce77085b4270a9c01090ca58983f0ec08216e5e45b840
4
- data.tar.gz: bba7eb0daaaf9d83120e4efec27e378d1876c798faf2290f1291db84d6c50160
3
+ metadata.gz: 1e63bedb0c0b22d7e44ea7c6c34ad61f9ff8acb9facc21820184cddf2db79990
4
+ data.tar.gz: 56197434b185928e747670908fdefac768e4ce8dc6be79e3849fd0fc91a022f5
5
5
  SHA512:
6
- metadata.gz: 69620f883503572654fba4f5d6f0b4df752bb17f8f2c7d69dd01e246962e8a66fffa67c88ab0a77474075779c5bea3df74a89fd4eedd4a8c6097a30f39e3f73f
7
- data.tar.gz: 490570518b664f9227e9fa28aba01276238187b24253ea7b52a4bbaa3ae76dcc5573eb810d704db090ef6ca18ec55ca75e86f3a1bd5e894fb4ccdee408c93201
6
+ metadata.gz: 5953cd706cfe07072824f19776a98342561e8259c7ac58f78d869ff533123b147ccdf156d919cbd557e009e21c52829b0309beaf7dc3f1e1f9df2cd28e180613
7
+ data.tar.gz: 1cdc591423e4586e84e44962a1860eb22288e053b0fc73d6105b46bf76c135621092f65d88ec976ec4fa370b72977a7b0584fa5c48cc61e2e27ec446a47a88a4
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.16.0
6
+
7
+ ### Added
8
+ * Added `Contentful::ArrayLike#to_ary`. [#200](https://github.com/contentful/contentful.rb/issues/200)
9
+ * Added `_metadata[:tags]` to read metadata tags on `entry` and `asset`.
10
+
5
11
  ## 2.15.4
6
12
 
7
13
  ### Fixed
data/README.md CHANGED
@@ -424,6 +424,15 @@ entry.color # 'rainbow'
424
424
  entry.birthday # #<DateTime: 2011-04-04T22:00:00+00:00 ((2455656j,79200s,0n),+0s,2299161j)>
425
425
  ```
426
426
 
427
+ #### Accessing tags
428
+
429
+ Tags can be accessed via the `#_metadata` method.
430
+
431
+ ```ruby
432
+ entry = client.entry 'nyancat'
433
+ entry._metadata[:tags] # => [<Contentful::Link id='tagID'>]
434
+ ```
435
+
427
436
  #### Dynamic entries
428
437
 
429
438
  However, you can (and should) set `:dynamic_entries` to `:auto` in your client configuration.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Contentful
2
4
  # Useful methods for array-like resources that can be included if an
3
5
  # :items property exists
@@ -47,5 +49,12 @@ module Contentful
47
49
  def last
48
50
  items.last
49
51
  end
52
+
53
+ # Delegates to items#to_ary
54
+ #
55
+ # @return [Contentful::Entry, Contentful::Asset]
56
+ def to_ary
57
+ items
58
+ end
50
59
  end
51
60
  end
@@ -5,7 +5,7 @@ require_relative 'support'
5
5
  module Contentful
6
6
  # Base definition of a Contentful Resource containing Sys properties
7
7
  class BaseResource
8
- attr_reader :raw, :default_locale, :sys
8
+ attr_reader :raw, :default_locale, :sys, :_metadata
9
9
 
10
10
  # rubocop:disable Metrics/ParameterLists
11
11
  def initialize(item, configuration = {}, _localized = false, _includes = [], entries = {}, depth = 0, _errors = [])
@@ -15,6 +15,7 @@ module Contentful
15
15
  @depth = depth
16
16
  @configuration = configuration
17
17
  @sys = hydrate_sys
18
+ @_metadata = hydrate_metadata
18
19
 
19
20
  define_sys_methods!
20
21
  end
@@ -57,6 +58,7 @@ module Contentful
57
58
  @configuration = raw_object[:configuration]
58
59
  @default_locale = @configuration[:default_locale]
59
60
  @sys = hydrate_sys
61
+ @_metadata = hydrate_metadata
60
62
  @depth = 0
61
63
  define_sys_methods!
62
64
  end
@@ -93,6 +95,15 @@ module Contentful
93
95
  result
94
96
  end
95
97
 
98
+ def hydrate_metadata
99
+ result = {}
100
+ raw.fetch('metadata', {}).each do |k, v|
101
+ v.map! { |tag| build_link(tag) } if k == 'tags'
102
+ result[Support.snakify(k, @configuration[:use_camel_case]).to_sym] = v
103
+ end
104
+ result
105
+ end
106
+
96
107
  protected
97
108
 
98
109
  def repr_name
@@ -1,5 +1,5 @@
1
1
  # Contentful Namespace
2
2
  module Contentful
3
3
  # Gem Version
4
- VERSION = '2.15.4'
4
+ VERSION = '2.16.0'
5
5
  end
data/spec/array_spec.rb CHANGED
@@ -60,6 +60,16 @@ describe Contentful::Array do
60
60
  end
61
61
  end
62
62
 
63
+ describe "#to_ary" do
64
+ it 'is an array' do
65
+ expect(array.to_ary).to be_a ::Array
66
+ end
67
+
68
+ it 'returns items' do
69
+ expect(array.to_ary).to eq array.items
70
+ end
71
+ end
72
+
63
73
  describe '#next_page' do
64
74
  it 'requests more of the same content from the server, using its limit and skip values' do
65
75
  array_page_1 = vcr('array_page_1') { create_client.content_types(skip: 3, limit: 2) }
data/spec/asset_spec.rb CHANGED
@@ -189,4 +189,32 @@ describe Contentful::Asset do
189
189
  }
190
190
  end
191
191
  end
192
+
193
+ describe 'tags metadata' do
194
+ let(:asset_id) { '686aLBcjj1f47uFWxrepj6' }
195
+
196
+ it 'can load an asset with tags' do
197
+ vcr('asset/with_tags') {
198
+ expect {
199
+ asset = create_client.asset(asset_id)
200
+ }.not_to raise_error
201
+ }
202
+ end
203
+
204
+ it 'hydrates tags' do
205
+ vcr('asset/with_tags') {
206
+ asset = create_client.asset(asset_id)
207
+ expect(asset._metadata[:tags].first).to be_a Contentful::Link
208
+ }
209
+ end
210
+
211
+ it 'loads tag links with their proper attributes' do
212
+ vcr('asset/with_tags') {
213
+ asset = create_client.asset(asset_id)
214
+ tag = asset._metadata[:tags].first
215
+ expect(tag.id).to eq 'mobQa'
216
+ expect(tag.link_type).to eq 'Tag'
217
+ }
218
+ end
219
+ end
192
220
  end
data/spec/entry_spec.rb CHANGED
@@ -784,4 +784,32 @@ describe Contentful::Entry do
784
784
  }
785
785
  end
786
786
  end
787
+
788
+ describe 'tags metadata' do
789
+ let(:entry_id) { '52GcYcPOPhuhlaogl05DIh' }
790
+
791
+ it 'can load an entry with tags' do
792
+ vcr('entry/with_tags') {
793
+ expect {
794
+ entry = create_client.entry(entry_id)
795
+ }.not_to raise_error
796
+ }
797
+ end
798
+
799
+ it 'hydrates tags' do
800
+ vcr('entry/with_tags') {
801
+ entry = create_client.entry(entry_id)
802
+ expect(entry._metadata[:tags].first).to be_a Contentful::Link
803
+ }
804
+ end
805
+
806
+ it 'loads tag links with their proper attributes' do
807
+ vcr('entry/with_tags') {
808
+ entry = create_client.entry(entry_id)
809
+ tag = entry._metadata[:tags].first
810
+ expect(tag.id).to eq 'mobQa'
811
+ expect(tag.link_type).to eq 'Tag'
812
+ }
813
+ end
814
+ end
787
815
  end
@@ -0,0 +1,138 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cdn.contentful.com/spaces/cfexampleapi/environments/master/assets/686aLBcjj1f47uFWxrepj6
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ X-Contentful-User-Agent:
11
+ - sdk contentful.rb/2.15.4; platform ruby/2.7.1; os macOS/19;
12
+ Authorization:
13
+ - Bearer b4c0n73n7fu1
14
+ Content-Type:
15
+ - application/vnd.contentful.delivery.v1+json
16
+ Connection:
17
+ - close
18
+ Host:
19
+ - cdn.contentful.com
20
+ User-Agent:
21
+ - http.rb/4.4.1
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Connection:
28
+ - close
29
+ Content-Length:
30
+ - '1106'
31
+ Access-Control-Allow-Headers:
32
+ - 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
33
+ Access-Control-Allow-Methods:
34
+ - GET,HEAD,OPTIONS
35
+ Access-Control-Allow-Origin:
36
+ - "*"
37
+ Access-Control-Expose-Headers:
38
+ - Etag
39
+ Access-Control-Max-Age:
40
+ - '86400'
41
+ Cf-Environment-Id:
42
+ - master
43
+ Cf-Environment-Uuid:
44
+ - a8fd17fd-5c8e-465f-bf8d-eb67f144dca0
45
+ Cf-Organization-Id:
46
+ - 4kQeJmhUWIKtNNmMkketza
47
+ Cf-Space-Id:
48
+ - cfexampleapi
49
+ Content-Type:
50
+ - application/vnd.contentful.delivery.v1+json
51
+ Contentful-Api:
52
+ - cda_cached
53
+ Etag:
54
+ - W/"3103305513039094952"
55
+ Server:
56
+ - Contentful
57
+ X-Content-Type-Options:
58
+ - nosniff
59
+ X-Contentful-Region:
60
+ - us-east-1
61
+ X-Contentful-Route:
62
+ - "/spaces/:space/environments/:environment/assets/:id"
63
+ Via:
64
+ - 1.1 varnish, 1.1 varnish
65
+ Accept-Ranges:
66
+ - bytes
67
+ Date:
68
+ - Mon, 29 Mar 2021 10:27:50 GMT
69
+ Age:
70
+ - '0'
71
+ X-Served-By:
72
+ - cache-dca17737-DCA, cache-bom4746-BOM
73
+ X-Cache-Hits:
74
+ - 0, 0
75
+ X-Timer:
76
+ - S1617013670.812930,VS0,VE282
77
+ Vary:
78
+ - Accept-Encoding
79
+ X-Cache:
80
+ - MISS
81
+ X-Contentful-Request-Id:
82
+ - a82aa39b-c5fb-4f2c-8848-f1b26cc7d313
83
+ body:
84
+ encoding: ASCII-8BIT
85
+ string: |
86
+ {
87
+ "metadata": {
88
+ "tags": [
89
+ {
90
+ "sys": {
91
+ "type": "Link",
92
+ "linkType": "Tag",
93
+ "id": "mobQa"
94
+ }
95
+ }
96
+ ]
97
+ },
98
+ "sys": {
99
+ "space": {
100
+ "sys": {
101
+ "type": "Link",
102
+ "linkType": "Space",
103
+ "id": "cfexampleapi"
104
+ }
105
+ },
106
+ "id": "686aLBcjj1f47uFWxrepj6",
107
+ "type": "Asset",
108
+ "createdAt": "2021-02-06T05:59:37.794Z",
109
+ "updatedAt": "2021-03-29T10:22:06.152Z",
110
+ "environment": {
111
+ "sys": {
112
+ "id": "master",
113
+ "type": "Link",
114
+ "linkType": "Environment"
115
+ }
116
+ },
117
+ "revision": 2,
118
+ "locale": "en-US"
119
+ },
120
+ "fields": {
121
+ "title": "Avatar",
122
+ "description": "my photo",
123
+ "file": {
124
+ "url": "//images.ctfassets.net/cfexampleapi/686aLBcjj1f47uFWxrepj6/3bd27e35028b8210ca732eb037f4b567/WhatsApp_Image_2019-06-25_at_12.17.04.jpeg",
125
+ "details": {
126
+ "size": 108963,
127
+ "image": {
128
+ "width": 868,
129
+ "height": 1000
130
+ }
131
+ },
132
+ "fileName": "Avatar.jpeg",
133
+ "contentType": "image/jpeg"
134
+ }
135
+ }
136
+ }
137
+ recorded_at: Mon, 29 Mar 2021 10:27:49 GMT
138
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,238 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cdn.contentful.com/spaces/cfexampleapi/environments/master/content_types?limit=1000
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ X-Contentful-User-Agent:
11
+ - sdk contentful.rb/2.15.4; platform ruby/2.7.1; os macOS/19;
12
+ Authorization:
13
+ - Bearer b4c0n73n7fu1
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/4.4.1
24
+ response:
25
+ status:
26
+ code: 200
27
+ message: OK
28
+ headers:
29
+ Connection:
30
+ - close
31
+ Content-Length:
32
+ - '731'
33
+ Access-Control-Allow-Headers:
34
+ - 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
35
+ Access-Control-Allow-Methods:
36
+ - GET,HEAD,OPTIONS
37
+ Access-Control-Allow-Origin:
38
+ - "*"
39
+ Access-Control-Expose-Headers:
40
+ - Etag
41
+ Access-Control-Max-Age:
42
+ - '86400'
43
+ Cf-Environment-Id:
44
+ - master
45
+ Cf-Environment-Uuid:
46
+ - a8fd17fd-5c8e-465f-bf8d-eb67f144dca0
47
+ Cf-Organization-Id:
48
+ - 4kQeJmhUWIKtNNmMkketza
49
+ Cf-Space-Id:
50
+ - cfexampleapi
51
+ Content-Encoding:
52
+ - gzip
53
+ Content-Type:
54
+ - application/vnd.contentful.delivery.v1+json
55
+ Contentful-Api:
56
+ - cda_cached
57
+ Etag:
58
+ - W/"1428365732249037051"
59
+ Server:
60
+ - Contentful
61
+ X-Content-Type-Options:
62
+ - nosniff
63
+ X-Contentful-Region:
64
+ - us-east-1
65
+ X-Contentful-Route:
66
+ - "/spaces/:space/environments/:environment/content_types"
67
+ Accept-Ranges:
68
+ - bytes
69
+ Date:
70
+ - Sun, 28 Mar 2021 12:13:52 GMT
71
+ Via:
72
+ - 1.1 varnish
73
+ Age:
74
+ - '87766'
75
+ X-Served-By:
76
+ - cache-bom4721-BOM
77
+ X-Cache-Hits:
78
+ - '1'
79
+ X-Timer:
80
+ - S1616933633.514348,VS0,VE1
81
+ Vary:
82
+ - Accept-Encoding
83
+ X-Cache:
84
+ - HIT
85
+ X-Contentful-Request-Id:
86
+ - 4452e776-4432-4002-b3ea-ef8e597daa42
87
+ body:
88
+ encoding: ASCII-8BIT
89
+ string: !binary |-
90
+ H4sIAAAAAAAAA+1XTY/aMBC9769APhdkJyEsuaFqK1XqqcupFUIGzGKRrzqGlq747x07OImDWVB3FxWpvoA9nhnP8+R55vmu00HFrkBR5xn+wkTucgYzNBKC7hCs7T+oPTKTNIZ1X8+KNc9hgvUk5gmXMCMYlwtcskRZ/K4tlnZbbrSrIqdz5cvsKBcbh1ELetEc6gtP10g5rQe4T9fjw6EftcXWBr5Q8WTBKnwa/vTzLOMqLDP21X8daDlQqSNZIb2GueocH7NUslRqtw2tuWBUssVIoYE87JEu9rqkP8ZhFPgRwb3Qv//WVNjki2MFDxSCyB9EhPSCYGgpsHTLRZYm4Pwi4Mo4ElpIJtq4XArqQ8PnWeAE2/KCZ6nKB++wuwIWLXiRx3T3ibNYX0rCJAUEaHU0lNJEp58NPVqwYi54LkvLqN6/VKbqZFPXZ6VTCUBOUyv6ys2RwIDyGS74qYUZirM5jflvps6+pHHBmpmGBPux4eKEECKns/iEMIMPCPLGWHVlpCOoI/BU8FVkbqkJ73GXzLLYxuTq0R3inOjfQ5LcMFvQjVxlza/sr+gCh2Pcj/phhMOeT4LzdKEUYLcXBUFvMOzfLF2cZwvJZVzzbZXpIxv313IF3QIh2WRZuXLJTtLotejCIqHmazgqCibrt67xvjnYRPD5asx+STdPuqUm9K9O3avzSQ2EIz47eSyqHFt5pUX/efJ9q6p25WTwvrywIl2PjAmGIiki/R4Jw3NMCQrAlMMI+1GAe/cDuxK7pcLKC84WVqp8murayF1aTTXg5oN5LWWmm2TGBHFTRymctqRvU2dJsbFrsHcosxxQ2uwBUNuRm9iO6fTfokQg9bV8ifId0jei/GtcnGBLJljaagirt/yE2ARY9r/223qd8t/yaXrp5ot2piHeQo8CTRW0SrovmjTt6Xa97pcfUil0k29Goxu2q3OYTe72d38AoWM06DAQAAA=
91
+ recorded_at: Sun, 28 Mar 2021 12:13:52 GMT
92
+ - request:
93
+ method: get
94
+ uri: https://cdn.contentful.com/spaces/cfexampleapi/environments/master/entries?sys.id=52GcYcPOPhuhlaogl05DIh
95
+ body:
96
+ encoding: UTF-8
97
+ string: ''
98
+ headers:
99
+ X-Contentful-User-Agent:
100
+ - sdk contentful.rb/2.15.4; platform ruby/2.7.1; os macOS/19;
101
+ Authorization:
102
+ - Bearer b4c0n73n7fu1
103
+ Content-Type:
104
+ - application/vnd.contentful.delivery.v1+json
105
+ Accept-Encoding:
106
+ - gzip
107
+ Connection:
108
+ - close
109
+ Host:
110
+ - cdn.contentful.com
111
+ User-Agent:
112
+ - http.rb/4.4.1
113
+ response:
114
+ status:
115
+ code: 200
116
+ message: OK
117
+ headers:
118
+ Connection:
119
+ - close
120
+ Content-Length:
121
+ - '956'
122
+ Access-Control-Allow-Headers:
123
+ - 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
124
+ Access-Control-Allow-Methods:
125
+ - GET,HEAD,OPTIONS
126
+ Access-Control-Allow-Origin:
127
+ - "*"
128
+ Access-Control-Expose-Headers:
129
+ - Etag
130
+ Access-Control-Max-Age:
131
+ - '86400'
132
+ Cf-Environment-Id:
133
+ - master
134
+ Cf-Environment-Uuid:
135
+ - a8fd17fd-5c8e-465f-bf8d-eb67f144dca0
136
+ Cf-Organization-Id:
137
+ - 4kQeJmhUWIKtNNmMkketza
138
+ Cf-Space-Id:
139
+ - cfexampleapi
140
+ Content-Type:
141
+ - application/vnd.contentful.delivery.v1+json
142
+ Contentful-Api:
143
+ - cda_cached
144
+ Etag:
145
+ - '"18024233839947354630"'
146
+ Server:
147
+ - Contentful
148
+ X-Content-Type-Options:
149
+ - nosniff
150
+ X-Contentful-Region:
151
+ - us-east-1
152
+ X-Contentful-Route:
153
+ - "/spaces/:space/environments/:environment/entries"
154
+ Accept-Ranges:
155
+ - bytes
156
+ Date:
157
+ - Sun, 28 Mar 2021 12:13:52 GMT
158
+ Via:
159
+ - 1.1 varnish
160
+ Age:
161
+ - '0'
162
+ X-Served-By:
163
+ - cache-bom4749-BOM
164
+ X-Cache-Hits:
165
+ - '1'
166
+ X-Timer:
167
+ - S1616933633.546080,VS0,VE285
168
+ Vary:
169
+ - Accept-Encoding
170
+ X-Cache:
171
+ - HIT
172
+ X-Contentful-Request-Id:
173
+ - 129a8fd6-d7a1-4873-8d23-b61c7fe7b62b
174
+ body:
175
+ encoding: ASCII-8BIT
176
+ string: |
177
+ {
178
+ "sys": {
179
+ "type": "Array"
180
+ },
181
+ "total": 1,
182
+ "skip": 0,
183
+ "limit": 100,
184
+ "items": [
185
+ {
186
+ "metadata": {
187
+ "tags": [
188
+ {
189
+ "sys": {
190
+ "type": "Link",
191
+ "linkType": "Tag",
192
+ "id": "mobQa"
193
+ }
194
+ }
195
+ ]
196
+ },
197
+ "sys": {
198
+ "space": {
199
+ "sys": {
200
+ "type": "Link",
201
+ "linkType": "Space",
202
+ "id": "cfexampleapi"
203
+ }
204
+ },
205
+ "id": "52GcYcPOPhuhlaogl05DIh",
206
+ "type": "Entry",
207
+ "createdAt": "2021-02-21T06:31:58.023Z",
208
+ "updatedAt": "2021-02-25T04:29:51.706Z",
209
+ "environment": {
210
+ "sys": {
211
+ "id": "master",
212
+ "type": "Link",
213
+ "linkType": "Environment"
214
+ }
215
+ },
216
+ "revision": 3,
217
+ "contentType": {
218
+ "sys": {
219
+ "type": "Link",
220
+ "linkType": "ContentType",
221
+ "id": "test2"
222
+ }
223
+ },
224
+ "locale": "en-US"
225
+ },
226
+ "fields": {
227
+ "title": {
228
+ "en-US": "Can't publish this"
229
+ },
230
+ "shortDescription": {
231
+ "en-US": "What is going on here can I still write? changed"
232
+ }
233
+ }
234
+ }
235
+ ]
236
+ }
237
+ recorded_at: Sun, 28 Mar 2021 12:13:52 GMT
238
+ recorded_with: VCR 6.0.0