contentful 2.17.2 → 2.19.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a2120e270825f1bb0434d26f0b4eb42a445b7cb8df9fff01d7b1e71e1e76d91
4
- data.tar.gz: 031e64513bfb83c80fcbc6bef5e426eadc1a24e11cf7ba0d69c04253a25e0447
3
+ metadata.gz: 3f73573b5e007f3d6ef23b5d347f1d524a0c88e7e1ad90f044a20290b71eb1df
4
+ data.tar.gz: d9ba166255a82387acbea7127f665c4aedd5181b36f5dab67a6ddc6286d87876
5
5
  SHA512:
6
- metadata.gz: 94d85b10674c340396c1c8bb3605135645422d7f9ffda1ca25223850d84df20c5c0a598029a1cc6775ccd46c7b43477ba7d9139dbcfbdd3ea672cc4762bdfa1a
7
- data.tar.gz: 4b671bee29520ebd6413e021a278278be4bba1b24813d6baff4b4053b5ed6ca42d1b76b8dccb7ce0fc3987065e63638e480d4448b3a89c147f0adc9380f8e3ae
6
+ metadata.gz: '0693f89bec3ad2bc4324b523fc6086260c26f0f48e20614df3005c8ae39d733915193ce7fe8f7698fe90c383610af030a8e18becd5ea4d8ae9dbb5dc0e6553d9'
7
+ data.tar.gz: aef73a49aad4da0757a2a2f8e013a46137e5bb6ebed392de2a3c916093b3a4ef96deabca8e33c1360c6eff9dd4b1edce58be4b18309cdd95934ba6ae0d5d28f2
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.19.0
6
+ * Added `http_instrumenter` configuration option to allow instrumenting HTTP requests. [#266](https://github.com/contentful/contentful.rb/pull/266)
7
+ * Updated `http` gem version to `> 4`
8
+
9
+ ## 2.18.0
10
+ * Added support for Taxonomy endpoints
11
+
5
12
  ## 2.17.2
6
13
 
7
14
  ### Fixed
data/README.md CHANGED
@@ -56,6 +56,8 @@
56
56
  - [Configuration](#configuration)
57
57
  - [Reference documentation](#reference-documentation)
58
58
  - [Basic queries](#basic-queries)
59
+ - [Taxonomy Concepts](#taxonomy-concepts)
60
+ - [Taxonomy Concept Schemes](#taxonomy-concept-schemes)
59
61
  - [Filtering options](#filtering-options)
60
62
  - [Accessing fields and sys properties](#accessing-fields-and-sys-properties)
61
63
  - [Dynamic entries](#dynamic-entries)
@@ -367,6 +369,15 @@ client = Contentful::Client.new(
367
369
  the original log_level on the logger, for example when using Rails.logger.
368
370
  </td>
369
371
  </tr>
372
+ <tr>
373
+ <td><code>http_instrumenter</code></td>
374
+ <td><code>nil</code></td>
375
+ <td>
376
+ An HTTP instrumenter object that implements the <code>HTTP::Features::Instrumentation::Instrumenter</code> interface.
377
+ When provided, it will be used to instrument all HTTP requests made by the client.
378
+ This is useful for monitoring, logging, or tracking HTTP requests.
379
+ </td>
380
+ </tr>
370
381
  </tbody>
371
382
  </table>
372
383
 
@@ -381,6 +392,89 @@ nyancat = client.entry 'nyancat'
381
392
  entries = client.entries
382
393
  assets = client.assets
383
394
  nyancat_asset = client.asset 'nyancat'
395
+ taxonomy_concept = client.taxonomy_concept '3DMf5gdax6J22AfcJ6fvsC'
396
+ taxonomy_concept_scheme = client.taxonomy_concept_scheme '7CzXPy6XvYYd0D7SomitgI'
397
+ ```
398
+
399
+ ### Assets
400
+
401
+ There is a helpful method to add image resize options for an asset image:
402
+
403
+ ```ruby
404
+ client.asset('happycat').url
405
+ # => "//images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/
406
+ # 382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg"
407
+
408
+ client.asset('happycat').url(width: 300, height: 200, format: 'jpg', quality: 100)
409
+ # => "//images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/
410
+ # 382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg?w=300&h=200&fm=jpg&q=100"
411
+ ```
412
+
413
+ ### Taxonomy Concepts
414
+
415
+ You can retrieve taxonomy concepts using the taxonomy_concept method:
416
+
417
+ ```ruby
418
+ # Get a specific taxonomy concept
419
+ concept = client.taxonomy_concept('3DMf5gdax6J22AfcJ6fvsC')
420
+
421
+ # Access basic properties
422
+ concept.sys[:id] # => '3DMf5gdax6J22AfcJ6fvsC'
423
+ concept.sys[:type] # => 'TaxonomyConcept'
424
+ concept.uri # => nil or URI string
425
+
426
+ # Access localized fields
427
+ concept.pref_label # => 'sofa'
428
+ concept.alt_labels # => []
429
+ concept.definition # => ''
430
+ concept.note # => ''
431
+
432
+ # Access relationships
433
+ concept.broader # => Array of broader concept links
434
+ concept.related # => Array of related concept links
435
+ concept.concept_schemes # => Array of concept scheme links
436
+ ```
437
+
438
+ ### Taxonomy Concept Schemes
439
+
440
+ You can retrieve taxonomy concept schemes using the taxonomy_concept_scheme method:
441
+
442
+ ```ruby
443
+ # Get a specific taxonomy concept scheme
444
+ scheme = client.taxonomy_concept_scheme('7CzXPy6XvYYd0D7SomitgI')
445
+
446
+ # Access basic properties
447
+ scheme.sys[:id] # => '7CzXPy6XvYYd0D7SomitgI'
448
+ scheme.sys[:type] # => 'TaxonomyConceptScheme'
449
+ scheme.uri # => nil or URI string
450
+ scheme.total_concepts # => 1
451
+
452
+ # Access localized fields
453
+ scheme.pref_label # => 'furniture'
454
+ scheme.definition # => ''
455
+
456
+ # Access relationships
457
+ scheme.top_concepts # => Array of top concept links
458
+ scheme.concepts # => Array of concept links
459
+
460
+ # Get all taxonomy concept schemes
461
+ schemes = client.taxonomy_concept_schemes
462
+
463
+ # You can also use query parameters for filtering and pagination
464
+ schemes = client.taxonomy_concept_schemes(limit: 10, order: 'sys.createdAt')
465
+ schemes = client.taxonomy_concept_schemes(limit: 5, skip: 10)
466
+
467
+ # The result is a Contentful::Array that you can iterate over
468
+ schemes.each do |scheme|
469
+ puts "Scheme: #{scheme.pref_label} (ID: #{scheme.sys[:id]})"
470
+ puts "Total concepts: #{scheme.total_concepts}"
471
+ end
472
+
473
+ # Access pagination information
474
+ if schemes.next_page_url
475
+ next_page = schemes.next_page_url
476
+ # You can use this URL to get the next page of results
477
+ end
384
478
  ```
385
479
 
386
480
  #### Filtering options
@@ -424,13 +518,14 @@ entry.color # 'rainbow'
424
518
  entry.birthday # #<DateTime: 2011-04-04T22:00:00+00:00 ((2455656j,79200s,0n),+0s,2299161j)>
425
519
  ```
426
520
 
427
- #### Accessing tags
521
+ #### Accessing tags and concepts
428
522
 
429
- Tags can be accessed via the `#_metadata` method.
523
+ Tags and concepts can be accessed via the `#_metadata` method.
430
524
 
431
525
  ```ruby
432
526
  entry = client.entry 'nyancat'
433
527
  entry._metadata[:tags] # => [<Contentful::Link id='tagID'>]
528
+ entry._metadata[:concepts] # => [<Contentful::Link id='conceptID'>]
434
529
  ```
435
530
 
436
531
  #### Dynamic entries
@@ -494,20 +589,6 @@ happycat.image
494
589
  happycat.image.resolve(client) # => #<Contentful::Asset: @fields={ ...
495
590
  ```
496
591
 
497
- ### Assets
498
-
499
- There is a helpful method to add image resize options for an asset image:
500
-
501
- ```ruby
502
- client.asset('happycat').url
503
- # => "//images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/
504
- # 382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg"
505
-
506
- client.asset('happycat').url(width: 300, height: 200, format: 'jpg', quality: 100)
507
- # => "//images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/
508
- # 382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg?w=300&h=200&fm=jpg&q=100"
509
- ```
510
-
511
592
  #### Resource options
512
593
 
513
594
  Resources, that have been requested directly (i.e. no child resources), can be fetched from the server again by calling `#reload`:
@@ -75,7 +75,8 @@ module Contentful
75
75
  'ContentType' => 'content_types',
76
76
  'Entry' => 'entries',
77
77
  'Asset' => 'assets',
78
- 'Locale' => 'locales'
78
+ 'Locale' => 'locales',
79
+ 'TaxonomyConcept' => 'taxonomy_concepts'
79
80
  }
80
81
 
81
82
  client.public_send(plurals[items.first.type], query.merge(limit: limit, skip: new_skip))
@@ -98,7 +98,7 @@ module Contentful
98
98
  def hydrate_metadata
99
99
  result = {}
100
100
  raw.fetch('metadata', {}).each do |k, v|
101
- v = v.map { |tag| build_link(tag) } if k == 'tags'
101
+ v = v.map { |item| build_link(item) } if %w[tags concepts].include?(k)
102
102
  result[Support.snakify(k, @configuration[:use_camel_case]).to_sym] = v
103
103
  end
104
104
  result
@@ -44,16 +44,18 @@ module Contentful
44
44
  application_name: nil,
45
45
  application_version: nil,
46
46
  integration_name: nil,
47
- integration_version: nil
47
+ integration_version: nil,
48
+ http_instrumenter: nil
48
49
  }
49
50
 
50
51
  attr_reader :configuration, :logger, :proxy
51
52
 
52
53
  # Wraps the actual HTTP request via proxy
53
54
  # @private
54
- def self.get_http(url, query, headers = {}, proxy = {}, timeout = {})
55
+ def self.get_http(url, query, headers = {}, proxy = {}, timeout = {}, instrumenter)
55
56
  http = HTTP[headers]
56
57
  http = http.timeout(timeout) if timeout.any?
58
+ http = http.use(instrumentation: { instrumenter: instrumenter }) if instrumenter
57
59
  if proxy[:host]
58
60
  http.via(proxy[:host], proxy[:port], proxy[:username], proxy[:password]).get(url, params: query)
59
61
  else
@@ -92,6 +94,10 @@ module Contentful
92
94
  # @option given_configuration [String] :application_version
93
95
  # @option given_configuration [String] :integration_name
94
96
  # @option given_configuration [String] :integration_version
97
+ # @option given_configuration [HTTP::Features::Instrumentation::Instrumenter, nil] :http_instrumenter
98
+ # An HTTP instrumenter object that implements the instrumentation interface.
99
+ # When provided, it will be used to instrument all HTTP requests made by the client.
100
+ # This is useful for monitoring, logging, or tracking HTTP requests.
95
101
  def initialize(given_configuration = {})
96
102
  @configuration = default_configuration.merge(given_configuration)
97
103
  normalize_configuration!
@@ -215,6 +221,44 @@ module Contentful
215
221
  Request.new(self, environment_url('/locales'), query).get
216
222
  end
217
223
 
224
+ # Gets a specific taxonomy concept
225
+ #
226
+ # @param [String] id
227
+ # @param [Hash] query
228
+ #
229
+ # @return [Contentful::TaxonomyConcept]
230
+ def taxonomy_concept(id, query = {})
231
+ Request.new(self, environment_url('/taxonomy/concepts'), query, id).get
232
+ end
233
+
234
+ # Gets a collection of taxonomy concepts
235
+ #
236
+ # @param [Hash] query
237
+ #
238
+ # @return [Contentful::Array<Contentful::TaxonomyConcept>]
239
+ def taxonomy_concepts(query = {})
240
+ Request.new(self, environment_url('/taxonomy/concepts'), query).get
241
+ end
242
+
243
+ # Gets a specific taxonomy concept scheme
244
+ #
245
+ # @param [String] id
246
+ # @param [Hash] query
247
+ #
248
+ # @return [Contentful::TaxonomyConceptScheme]
249
+ def taxonomy_concept_scheme(id, query = {})
250
+ Request.new(self, environment_url('/taxonomy/concept-schemes'), query, id).get
251
+ end
252
+
253
+ # Gets a collection of taxonomy concept schemes
254
+ #
255
+ # @param [Hash] query
256
+ #
257
+ # @return [Contentful::Array<Contentful::TaxonomyConceptScheme>]
258
+ def taxonomy_concept_schemes(query = {})
259
+ Request.new(self, environment_url('/taxonomy/concept-schemes'), query).get
260
+ end
261
+
218
262
  # Returns the base url for all of the client's requests
219
263
  # @private
220
264
  def base_url
@@ -372,7 +416,8 @@ module Contentful
372
416
  request_query(request.query),
373
417
  request_headers,
374
418
  proxy_params,
375
- timeout_params
419
+ timeout_params,
420
+ configuration[:http_instrumenter]
376
421
  ), request
377
422
  )
378
423
  end
@@ -9,6 +9,8 @@ require_relative 'deleted_entry'
9
9
  require_relative 'deleted_asset'
10
10
  require_relative 'locale'
11
11
  require_relative 'includes'
12
+ require_relative 'taxonomy_concept'
13
+ require_relative 'taxonomy_concept_scheme'
12
14
 
13
15
  module Contentful
14
16
  # Transforms a Contentful::Response into a Contentful::Resource or a Contentful::Error
@@ -25,13 +27,15 @@ module Contentful
25
27
  'Link' => Link,
26
28
  'DeletedEntry' => DeletedEntry,
27
29
  'DeletedAsset' => DeletedAsset,
28
- 'Locale' => Locale
30
+ 'Locale' => Locale,
31
+ 'TaxonomyConcept' => TaxonomyConcept,
32
+ 'TaxonomyConceptScheme' => TaxonomyConceptScheme
29
33
  }.freeze
30
34
  # Default Entry Mapping
31
35
  # @see _ README for more information on Entry Mapping
32
36
  DEFAULT_ENTRY_MAPPING = {}.freeze
33
37
  # Buildable Resources
34
- BUILDABLES = %w[Entry Asset ContentType Space DeletedEntry DeletedAsset Locale].freeze
38
+ BUILDABLES = %w[Entry Asset ContentType Space DeletedEntry DeletedAsset Locale TaxonomyConcept TaxonomyConceptScheme].freeze
35
39
 
36
40
  attr_reader :json, :default_locale, :endpoint, :depth, :localized, :resource_mapping, :entry_mapping, :resource, :query
37
41
 
@@ -0,0 +1,95 @@
1
+ require_relative 'base_resource'
2
+
3
+ module Contentful
4
+ # Resource class for TaxonomyConcept.
5
+ # @see _ https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/taxonomy/concept
6
+ class TaxonomyConcept < BaseResource
7
+ attr_reader :uri, :notations, :broader, :related, :concept_schemes
8
+
9
+ def initialize(item, *)
10
+ super
11
+
12
+ @uri = item.fetch('uri', nil)
13
+ @notations = item.fetch('notations', [])
14
+ @broader = item.fetch('broader', [])
15
+ @related = item.fetch('related', [])
16
+ @concept_schemes = item.fetch('conceptSchemes', [])
17
+ end
18
+
19
+ # Returns true for resources that are taxonomy concepts
20
+ def taxonomy_concept?
21
+ true
22
+ end
23
+
24
+ # Returns false for resources that are not entries
25
+ def entry?
26
+ false
27
+ end
28
+
29
+ # Returns false for resources that are not assets
30
+ def asset?
31
+ false
32
+ end
33
+
34
+ # Access localized fields
35
+ def pref_label(locale = nil)
36
+ locale ||= default_locale
37
+ pref_label = raw.fetch('prefLabel', {})
38
+ pref_label.is_a?(Hash) ? pref_label.fetch(locale.to_s, nil) : pref_label
39
+ end
40
+
41
+ def alt_labels(locale = nil)
42
+ locale ||= default_locale
43
+ alt_labels = raw.fetch('altLabels', {})
44
+ alt_labels.is_a?(Hash) ? alt_labels.fetch(locale.to_s, []) : alt_labels
45
+ end
46
+
47
+ def hidden_labels(locale = nil)
48
+ locale ||= default_locale
49
+ hidden_labels = raw.fetch('hiddenLabels', {})
50
+ hidden_labels.is_a?(Hash) ? hidden_labels.fetch(locale.to_s, []) : hidden_labels
51
+ end
52
+
53
+ def note(locale = nil)
54
+ locale ||= default_locale
55
+ note = raw.fetch('note', {})
56
+ note.is_a?(Hash) ? note.fetch(locale.to_s, '') : note
57
+ end
58
+
59
+ def change_note(locale = nil)
60
+ locale ||= default_locale
61
+ change_note = raw.fetch('changeNote', {})
62
+ change_note.is_a?(Hash) ? change_note.fetch(locale.to_s, '') : change_note
63
+ end
64
+
65
+ def definition(locale = nil)
66
+ locale ||= default_locale
67
+ definition = raw.fetch('definition', {})
68
+ definition.is_a?(Hash) ? definition.fetch(locale.to_s, '') : definition
69
+ end
70
+
71
+ def editorial_note(locale = nil)
72
+ locale ||= default_locale
73
+ editorial_note = raw.fetch('editorialNote', {})
74
+ editorial_note.is_a?(Hash) ? editorial_note.fetch(locale.to_s, '') : editorial_note
75
+ end
76
+
77
+ def example(locale = nil)
78
+ locale ||= default_locale
79
+ example = raw.fetch('example', {})
80
+ example.is_a?(Hash) ? example.fetch(locale.to_s, '') : example
81
+ end
82
+
83
+ def history_note(locale = nil)
84
+ locale ||= default_locale
85
+ history_note = raw.fetch('historyNote', {})
86
+ history_note.is_a?(Hash) ? history_note.fetch(locale.to_s, '') : history_note
87
+ end
88
+
89
+ def scope_note(locale = nil)
90
+ locale ||= default_locale
91
+ scope_note = raw.fetch('scopeNote', {})
92
+ scope_note.is_a?(Hash) ? scope_note.fetch(locale.to_s, '') : scope_note
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,51 @@
1
+ require_relative 'base_resource'
2
+
3
+ module Contentful
4
+ # Resource class for TaxonomyConceptScheme.
5
+ # @see _ https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/taxonomy/concept-scheme
6
+ class TaxonomyConceptScheme < BaseResource
7
+ attr_reader :uri, :top_concepts, :concepts, :total_concepts
8
+
9
+ def initialize(item, *)
10
+ super
11
+
12
+ @uri = item.fetch('uri', nil)
13
+ @top_concepts = item.fetch('topConcepts', [])
14
+ @concepts = item.fetch('concepts', [])
15
+ @total_concepts = item.fetch('totalConcepts', 0)
16
+ end
17
+
18
+ # Returns true for resources that are taxonomy concept schemes
19
+ def taxonomy_concept_scheme?
20
+ true
21
+ end
22
+
23
+ # Returns false for resources that are not taxonomy concepts
24
+ def taxonomy_concept?
25
+ false
26
+ end
27
+
28
+ # Returns false for resources that are not entries
29
+ def entry?
30
+ false
31
+ end
32
+
33
+ # Returns false for resources that are not assets
34
+ def asset?
35
+ false
36
+ end
37
+
38
+ # Access localized fields
39
+ def pref_label(locale = nil)
40
+ locale ||= default_locale
41
+ pref_label = raw.fetch('prefLabel', {})
42
+ pref_label.is_a?(Hash) ? pref_label.fetch(locale.to_s, nil) : pref_label
43
+ end
44
+
45
+ def definition(locale = nil)
46
+ locale ||= default_locale
47
+ definition = raw.fetch('definition', {})
48
+ definition.is_a?(Hash) ? definition.fetch(locale.to_s, '') : definition
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  # Contentful Namespace
2
2
  module Contentful
3
3
  # Gem Version
4
- VERSION = '2.17.2'
4
+ VERSION = '2.19.0'
5
5
  end
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.17.2
4
+ version: 2.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contentful GmbH (Jan Lelis)
@@ -278,6 +278,8 @@ files:
278
278
  - lib/contentful/support.rb
279
279
  - lib/contentful/sync.rb
280
280
  - lib/contentful/sync_page.rb
281
+ - lib/contentful/taxonomy_concept.rb
282
+ - lib/contentful/taxonomy_concept_scheme.rb
281
283
  - lib/contentful/version.rb
282
284
  homepage: https://github.com/contentful/contentful.rb
283
285
  licenses: