contentful_model 1.1.0 → 1.2.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: 124ae1820078574b614c6cd41c9ba657222d75209637d1d0090ebd05aa367864
4
- data.tar.gz: f309c31e27596c7d90954cf0d5d18112ed09c355eb8ed475591274174eaa8b7b
3
+ metadata.gz: 95936de4fccef8852abcdd2d2e1053f73210d3026add835f392287681eb570cf
4
+ data.tar.gz: ad3a0a352825eeea13e7a3661a63dc2c4c251ad61d8a8c58953c425a67f90f34
5
5
  SHA512:
6
- metadata.gz: 1cd57a8ee48783aa9f5e1f91f779ac399446e563f9f6babf90e11c0c7801ee0b5cd9338ecd9b4b1d8e1fb838f9b48a641531137105ce906dd97400c75c9883ef
7
- data.tar.gz: 527a17a0771d104b41c22d45db937f442f605acff40714dce57725b0ce728ea9af23de82e9896a7c22845ff0dd8d86b1e4cd92c31591b2286ec4885b6a2d6c55
6
+ metadata.gz: 98eef95a34aa622730863c966a4631669ff24ada5d0f7aa9e325a000c7d2ff3e91e19d67aa4f37fab9d00d4978865c6b69b6e4449a73ceca2824624315d4873a
7
+ data.tar.gz: 81c0e9a361ee70ffc23007f86fe5555ea1aaba2a0cd622813766fb20d8fa9548fb09065cd235cf8933a64f0b4453f226e6da79aa1ab7869fd02091417fcafc27
@@ -14,13 +14,21 @@ module ContentfulModel
14
14
  configuration[:api_url] = PREVIEW_API_URL
15
15
  configuration[:access_token] = configuration[:preview_access_token]
16
16
  end
17
- super({
17
+
18
+ configuration = {
18
19
  raise_errors: true,
19
20
  dynamic_entries: :auto,
20
21
  integration_name: 'contentful_model',
21
22
  integration_version: ::ContentfulModel::VERSION,
22
23
  raise_for_empty_fields: false
23
- }.merge(configuration))
24
+ }.merge(configuration)
25
+
26
+ # Apply delivery specific options (if any)
27
+ if configuration[:delivery_api]
28
+ configuration.merge!(configuration[:delivery_api])
29
+ end
30
+
31
+ super(configuration)
24
32
  end
25
33
  end
26
34
  end
@@ -79,9 +79,7 @@ module ContentfulModel
79
79
  private
80
80
 
81
81
  def management_proxy
82
- @management_proxy ||= self.class.management(
83
- default_locale: locale
84
- ).entries(
82
+ @management_proxy ||= self.class.management.entries(
85
83
  space.id,
86
84
  ContentfulModel.configuration.environment
87
85
  )
@@ -133,12 +131,7 @@ module ContentfulModel
133
131
  module ClassMethods
134
132
  def management(options = {})
135
133
  @management ||= ContentfulModel::Management.new(
136
- options.merge(
137
- default_locale: ContentfulModel.configuration.default_locale,
138
- raise_errors: true,
139
- integration_name: 'contentful_model',
140
- integration_version: ::ContentfulModel::VERSION
141
- )
134
+ options.merge(raise_errors: true)
142
135
  )
143
136
  end
144
137
 
@@ -2,6 +2,12 @@ module ContentfulModel
2
2
  # Wrapper for the CMA Client
3
3
  class Management < Contentful::Management::Client
4
4
  def initialize(options = {})
5
+ # Apply management specific options (if any)
6
+ options = ContentfulModel.configuration.to_hash.merge(options)
7
+ if options[:management_api]
8
+ options = options.merge(options[:management_api])
9
+ end
10
+
5
11
  super(ContentfulModel.configuration.management_token, options)
6
12
  end
7
13
  end
@@ -29,7 +29,7 @@ module ContentfulModel
29
29
  )
30
30
  else
31
31
  @management_content_type.fields = @fields
32
- @management_content_type.displayField = display_field if display_field
32
+ @management_content_type.display_field = display_field if display_field
33
33
  @management_content_type.save
34
34
  end
35
35
 
@@ -62,6 +62,7 @@ module ContentfulModel
62
62
 
63
63
  def remove_field(field_id)
64
64
  @management_content_type.fields.destroy(field_id)
65
+ @fields = fields_from_management_type
65
66
  end
66
67
 
67
68
  def new?
@@ -103,10 +104,16 @@ module ContentfulModel
103
104
  end
104
105
 
105
106
  def management_items(type)
106
- if %i[entry_array asset_array].include?(type.to_sym)
107
+ if %i[entry_array asset_array symbol_array].include?(type.to_sym)
108
+ array_type = type.split('_').first.capitalize
109
+
107
110
  items = Contentful::Management::Field.new
108
- items.type = 'Link'
109
- items.link_type = type.split('_').first.capitalize
111
+ if %i[entry_array asset_array].include?(type.to_sym)
112
+ items.type = 'Link'
113
+ items.link_type = array_type
114
+ else
115
+ items.type = array_type
116
+ end
110
117
 
111
118
  items
112
119
  else
@@ -1,3 +1,3 @@
1
1
  module ContentfulModel
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -35,6 +35,8 @@ module ContentfulModel
35
35
  def initialize
36
36
  @entry_mapping ||= {}
37
37
  @environment = 'master'
38
+ @integration_name = 'contentful_model'
39
+ @integration_version = ::ContentfulModel::VERSION
38
40
  end
39
41
 
40
42
  # Rather than listing out all the possible attributes as setters, we have a catchall
data/spec/client_spec.rb CHANGED
@@ -1,11 +1,32 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ContentfulModel::Client do
4
- subject { described_class.new({space: 'cfexampleapi', access_token: 'b4c0n73n7fu1'}) }
4
+ subject do
5
+ described_class.new({
6
+ space: 'cfexampleapi',
7
+ access_token: 'b4c0n73n7fu1',
8
+ management_api: {
9
+ timeout_connect: 3,
10
+ timeout_read: 6,
11
+ timeout_write: 20
12
+ },
13
+ delivery_api: {
14
+ timeout_connect: 4,
15
+ timeout_read: 7,
16
+ timeout_write: 21
17
+ }
18
+ })
19
+ end
5
20
 
6
21
  it 'is a Contentful::Client' do
7
22
  vcr('client') {
8
23
  expect(subject).to be_a(Contentful::Client)
9
24
  }
10
25
  end
26
+
27
+ it 'gets initialized with the configured delivery specific timeout_connect' do
28
+ vcr('client') {
29
+ expect(subject.configuration[:timeout_connect]).to eq(4)
30
+ }
31
+ end
11
32
  end
@@ -4,6 +4,22 @@ describe ContentfulModel::Management do
4
4
  before do
5
5
  ContentfulModel.configure do |c|
6
6
  c.management_token = 'foobar'
7
+ c.options = {
8
+ timeout_connect: 2,
9
+ timeout_read: 5,
10
+ timeout_write: 19,
11
+
12
+ management_api: {
13
+ timeout_connect: 3,
14
+ timeout_read: 6,
15
+ timeout_write: 20
16
+ },
17
+ delivery_api: {
18
+ timeout_connect: 4,
19
+ timeout_read: 7,
20
+ timeout_write: 21
21
+ }
22
+ }
7
23
  end
8
24
  end
9
25
 
@@ -14,4 +30,8 @@ describe ContentfulModel::Management do
14
30
  it 'gets initialized with the configured management token' do
15
31
  expect(subject.access_token).to eq('foobar')
16
32
  end
33
+
34
+ it 'gets initialized with the configured management specific timeout_read' do
35
+ expect(subject.configuration[:timeout_read]).to eq(6)
36
+ end
17
37
  end
@@ -61,7 +61,7 @@ describe ContentfulModel::Migrations::ContentType do
61
61
 
62
62
  it 'updates it' do
63
63
  expect(mock_ct).to receive(:fields=)
64
- expect(mock_ct).not_to receive(:displayField=)
64
+ expect(mock_ct).not_to receive(:display_field=)
65
65
  expect(mock_ct).to receive(:save)
66
66
 
67
67
  described_class.new(nil, mock_ct).save
@@ -69,7 +69,7 @@ describe ContentfulModel::Migrations::ContentType do
69
69
 
70
70
  it 'updates display field' do
71
71
  expect(mock_ct).to receive(:fields=)
72
- expect(mock_ct).to receive(:displayField=)
72
+ expect(mock_ct).to receive(:display_field=)
73
73
  expect(mock_ct).to receive(:save)
74
74
 
75
75
  ct = described_class.new(nil, mock_ct)
@@ -79,14 +79,25 @@ describe ContentfulModel::Migrations::ContentType do
79
79
  end
80
80
  end
81
81
 
82
- it '#remove_field' do
82
+ it '#remove_field and update fields' do
83
83
  mock_ct = Object.new
84
- mock_fields = Object.new
85
-
86
- expect(mock_ct).to receive(:fields) { mock_fields }
87
- expect(mock_fields).to receive(:destroy).with('foo')
88
-
89
- described_class.new(nil, mock_ct).remove_field('foo')
84
+ fields = [
85
+ Contentful::Management::Field.new.tap { |f| f.id = 'foo' },
86
+ Contentful::Management::Field.new.tap { |f| f.id = 'bar' },
87
+ ]
88
+ fields_from_management_type = [
89
+ Contentful::Management::Field.new.tap { |f| f.id = 'foo' }
90
+ ]
91
+ allow(mock_ct).to receive(:fields) { fields }
92
+ allow(mock_ct).to receive(:id) { 'foo' }
93
+
94
+ expect(fields).to receive(:destroy).with('foo')
95
+
96
+ subject = described_class.new(nil, mock_ct)
97
+ allow(subject).to receive(:fields_from_management_type) { fields_from_management_type }
98
+ subject.remove_field('foo')
99
+
100
+ expect(subject.fields).to eql fields_from_management_type
90
101
  end
91
102
 
92
103
  describe '#id' do
@@ -158,6 +169,21 @@ describe ContentfulModel::Migrations::ContentType do
158
169
  expect(items.link_type).to eq('Asset')
159
170
  end
160
171
 
172
+ it 'symbol array field' do
173
+ field = subject.field('foo', :symbol_array)
174
+
175
+ expect(field.id).to eq('foo')
176
+ expect(field.name).to eq('foo')
177
+ expect(field.type).to eq('Array')
178
+ expect(field.link_type).to eq(nil)
179
+
180
+ items = field.items
181
+
182
+ expect(items).to be_a(Contentful::Management::Field)
183
+ expect(items.type).to eq('Symbol')
184
+ expect(items.link_type).to eq(nil)
185
+ end
186
+
161
187
  it 'rich_text field' do
162
188
  field = subject.field('foo', :rich_text)
163
189
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contentful GmbH (David Litvak Bruno)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-05-09 00:00:00.000000000 Z
12
+ date: 2019-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: contentful
@@ -183,22 +183,16 @@ dependencies:
183
183
  name: webmock
184
184
  requirement: !ruby/object:Gem::Requirement
185
185
  requirements:
186
- - - "~>"
187
- - !ruby/object:Gem::Version
188
- version: '1'
189
186
  - - ">="
190
187
  - !ruby/object:Gem::Version
191
- version: 1.17.3
188
+ version: 3.7.6
192
189
  type: :development
193
190
  prerelease: false
194
191
  version_requirements: !ruby/object:Gem::Requirement
195
192
  requirements:
196
- - - "~>"
197
- - !ruby/object:Gem::Version
198
- version: '1'
199
193
  - - ">="
200
194
  - !ruby/object:Gem::Version
201
- version: 1.17.3
195
+ version: 3.7.6
202
196
  - !ruby/object:Gem::Dependency
203
197
  name: tins
204
198
  requirement: !ruby/object:Gem::Requirement
@@ -241,6 +235,20 @@ dependencies:
241
235
  - - "~>"
242
236
  - !ruby/object:Gem::Version
243
237
  version: 0.49.0
238
+ - !ruby/object:Gem::Dependency
239
+ name: listen
240
+ requirement: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - "~>"
243
+ - !ruby/object:Gem::Version
244
+ version: '2'
245
+ type: :development
246
+ prerelease: false
247
+ version_requirements: !ruby/object:Gem::Requirement
248
+ requirements:
249
+ - - "~>"
250
+ - !ruby/object:Gem::Version
251
+ version: '2'
244
252
  description: An ActiveModel-like wrapper for the Contentful SDKs
245
253
  email:
246
254
  - david.litvak@contentful.com