contentful-management 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: 9e9540f9f6f76faa7bc81ffc078b274f6ad41c9f
4
- data.tar.gz: 627329c7f26dcb8f7866def702f06d0c44721777
3
+ metadata.gz: 1844d46d629774fbe7c768093c7231e16398315a
4
+ data.tar.gz: a0d6f81a64b1476ded7a6b7b84733da67587f6f0
5
5
  SHA512:
6
- metadata.gz: 8d249c4f1a49c297c970a712c9e7a934b52928e839b2d7fa63e451c714ed7e002e26799eb8aa3550dd1cce1ab3d88537ebd6a30455c996bff32fd306fb6e0f13
7
- data.tar.gz: e6e6a254e522a42befd514c7877db377c4f0c32abca8760fc8fb2f291afc155a815fca42057fb77e89a490269ce6251a5f95d1c6e51eb6832ae9ee1a2166f794
6
+ metadata.gz: 476e62803a1c5c19e19eec87a980cd7e31ea195b432a4e8c2c36bb403cb978632bb8d20fc4e231888456570b76677ab46af1c35792b668cc74040c49208cdb8a
7
+ data.tar.gz: 4c5c1d5f4f053284c28c250da4fe08dd3ee6d03665380007df353d90c64c641ea0e2afc4b19478952fa38153b41ecff81059360efa04333b3029864c862d7ed5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 1.2.0
6
+ ### Added
7
+ * Add support for `::Contentful::Entry` and `::Contentful::Asset` serialization when using the CDA SDK along side this client [#105](https://github.com/contentful/contentful-management.rb/pull/105)
8
+ * Add `:optional` property to Locale
9
+
5
10
  ## 1.1.0
6
11
  ### Added
7
12
  * Add Roles and Permissions Support
@@ -17,8 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_dependency 'http', '~> 0.8'
20
+ spec.add_dependency 'http', '~> 1.0'
21
21
  spec.add_dependency 'multi_json', '~> 1'
22
+ spec.add_dependency 'json', '~> 1.8'
22
23
 
23
24
  spec.add_development_dependency 'bundler', '~> 1.6'
24
25
  spec.add_development_dependency 'rake'
@@ -194,14 +194,17 @@ module Contentful
194
194
 
195
195
  def self.parse_objects_array(attributes)
196
196
  attributes.each_with_object([]) do |attr, arr|
197
- arr << case attr
198
- when Entry then
199
- hash_with_link_object('Entry', attr)
200
- when Asset then
201
- hash_with_link_object('Asset', attr)
202
- when Hash then
203
- attr
204
- end
197
+ if attr.is_a? Entry
198
+ arr << hash_with_link_object('Entry', attr)
199
+ elsif attr.is_a? Asset
200
+ arr << hash_with_link_object('Asset', attr)
201
+ elsif attr.is_a? Hash
202
+ arr << attr
203
+ elsif attr.class.ancestors.map(&:to_s).include?('Contentful::Entry')
204
+ arr << hash_with_link_object('Entry', attr)
205
+ elsif attr.class.ancestors.map(&:to_s).include?('Contentful::Asset')
206
+ arr << hash_with_link_object('Asset', attr)
207
+ end
205
208
  end
206
209
  end
207
210
 
@@ -14,12 +14,15 @@ module Contentful
14
14
  property :contentDeliveryApi, :boolean
15
15
  property :publish, :boolean
16
16
  property :default, :boolean
17
+ property :optional, :boolean
17
18
 
18
19
  # @private
19
20
  def self.create_attributes(_client, attributes)
20
21
  {
21
22
  'name' => attributes.fetch(:name),
22
- 'code' => attributes.fetch(:code)
23
+ 'code' => attributes.fetch(:code),
24
+ 'default' => attributes.fetch(:default, false),
25
+ 'optional' => attributes.fetch(:default, false)
23
26
  }
24
27
  end
25
28
 
@@ -63,7 +63,7 @@ module Contentful
63
63
 
64
64
  def service_unavailable_error
65
65
  @status = :error
66
- @error_message = 'Service Unavailable, contenful.com API seems to be down'
66
+ @error_message = 'Service Unavailable, contentful.com API seems to be down'
67
67
  @object = Error[@raw.status].new(self)
68
68
  end
69
69
 
@@ -3,6 +3,6 @@ module Contentful
3
3
  # Management Namespace
4
4
  module Management
5
5
  # Gem Version
6
- VERSION = '1.1.0'
6
+ VERSION = '1.2.0'
7
7
  end
8
8
  end
@@ -0,0 +1,116 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/n5kqlvx9cnp1/locales/56eOu5hJwVNb4XfqsnQV97
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContentfulManagementGem/1.1.0
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Content-Length:
17
+ - '0'
18
+ Connection:
19
+ - close
20
+ Host:
21
+ - api.contentful.com
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Accept-Ranges:
28
+ - bytes
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
31
+ Access-Control-Allow-Methods:
32
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Expose-Headers:
36
+ - Etag
37
+ Access-Control-Max-Age:
38
+ - '1728000'
39
+ Cache-Control:
40
+ - max-age=0
41
+ Content-Type:
42
+ - application/vnd.contentful.management.v1+json
43
+ Date:
44
+ - Wed, 27 Jul 2016 00:44:26 GMT
45
+ Etag:
46
+ - '"55cd85af5d4a6ec286c5fd8fcf418afe"'
47
+ Server:
48
+ - Contentful
49
+ Status:
50
+ - 200 OK
51
+ Strict-Transport-Security:
52
+ - max-age=15768000
53
+ X-Content-Type-Options:
54
+ - nosniff
55
+ X-Contentful-Request-Id:
56
+ - 086fc258eb4a537487280b96617b5e63
57
+ Content-Length:
58
+ - '754'
59
+ Connection:
60
+ - Close
61
+ Set-Cookie:
62
+ - incap_ses_297_673446=Cfo7V1j0LSOHXEjVMCgfBOoDmFcAAAAArdX1Odg7P2/opp7MwEhlzA==;
63
+ path=/; Domain=.contentful.com
64
+ - nlbi_673446=axG2W5jXn1uXFbEA6lKYhQAAAACuJE1202IvmVx+m3GGQPBL; path=/; Domain=.contentful.com
65
+ - visid_incap_673446=TObhmbwsTT+o3L0XHRV2+OoDmFcAAAAAQUIPAAAAAADJudOA9eqqUlc43jLa7/NS;
66
+ expires=Wed, 26 Jul 2017 06:56:27 GMT; path=/; Domain=.contentful.com
67
+ X-Iinfo:
68
+ - 3-184110786-184110796 NNNN CT(136 136 0) RT(1469580265521 100) q(0 0 2 -1)
69
+ r(5 5) U5
70
+ X-Cdn:
71
+ - Incapsula
72
+ body:
73
+ encoding: UTF-8
74
+ string: |+
75
+ {
76
+ "name":"U.S. English",
77
+ "internal_code":"en-US",
78
+ "code":"en-US",
79
+ "fallbackCode":null,
80
+ "default":true,
81
+ "contentManagementApi":true,
82
+ "contentDeliveryApi":true,
83
+ "optional":false,
84
+ "sys":{
85
+ "type":"Locale",
86
+ "id":"56eOu5hJwVNb4XfqsnQV97",
87
+ "version":0,
88
+ "space":{
89
+ "sys":{
90
+ "type":"Link",
91
+ "linkType":"Space",
92
+ "id":"n5kqlvx9cnp1"
93
+ }
94
+ },
95
+ "createdBy":{
96
+ "sys":{
97
+ "type":"Link",
98
+ "linkType":"User",
99
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
100
+ }
101
+ },
102
+ "createdAt":"2016-07-27T00:40:35Z",
103
+ "updatedBy":{
104
+ "sys":{
105
+ "type":"Link",
106
+ "linkType":"User",
107
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
108
+ }
109
+ },
110
+ "updatedAt":"2016-07-27T00:40:35Z"
111
+ }
112
+ }
113
+
114
+ http_version:
115
+ recorded_at: Wed, 27 Jul 2016 00:44:26 GMT
116
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,116 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/n5kqlvx9cnp1/locales/7IHOkHoMY1PpFp1VSVlCpH
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContentfulManagementGem/1.1.0
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Content-Length:
17
+ - '0'
18
+ Connection:
19
+ - close
20
+ Host:
21
+ - api.contentful.com
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Accept-Ranges:
28
+ - bytes
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
31
+ Access-Control-Allow-Methods:
32
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Expose-Headers:
36
+ - Etag
37
+ Access-Control-Max-Age:
38
+ - '1728000'
39
+ Cache-Control:
40
+ - max-age=0
41
+ Content-Type:
42
+ - application/vnd.contentful.management.v1+json
43
+ Date:
44
+ - Wed, 27 Jul 2016 00:44:25 GMT
45
+ Etag:
46
+ - '"c304d29a9b8e3984be75c89e61d5c654"'
47
+ Server:
48
+ - Contentful
49
+ Status:
50
+ - 200 OK
51
+ Strict-Transport-Security:
52
+ - max-age=15768000
53
+ X-Content-Type-Options:
54
+ - nosniff
55
+ X-Contentful-Request-Id:
56
+ - 3f29b6d250357c0f2b9eeeb5f85a52e4
57
+ Content-Length:
58
+ - '746'
59
+ Connection:
60
+ - Close
61
+ Set-Cookie:
62
+ - incap_ses_297_673446=48KmHgDm8BoLWkjVMCgfBOkDmFcAAAAANI6+A4engIj7K8jRnSqZNg==;
63
+ path=/; Domain=.contentful.com
64
+ - nlbi_673446=ALw4DCCNPVJRCy616lKYhQAAAABd2u9LFkVQA7vvkVGgFAmX; path=/; Domain=.contentful.com
65
+ - visid_incap_673446=RkLokwvtTyCCKH647SBEz+kDmFcAAAAAQUIPAAAAAACD5yltV/lSRTzg/RdChCMr;
66
+ expires=Wed, 26 Jul 2017 06:56:27 GMT; path=/; Domain=.contentful.com
67
+ X-Iinfo:
68
+ - 8-283382040-283382143 NNNN CT(143 135 0) RT(1469580264487 299) q(0 0 3 -1)
69
+ r(6 6) U5
70
+ X-Cdn:
71
+ - Incapsula
72
+ body:
73
+ encoding: UTF-8
74
+ string: |+
75
+ {
76
+ "name":"Chinese",
77
+ "internal_code":"zh",
78
+ "code":"zh",
79
+ "fallbackCode":"en-US",
80
+ "default":false,
81
+ "contentManagementApi":true,
82
+ "contentDeliveryApi":true,
83
+ "optional":true,
84
+ "sys":{
85
+ "type":"Locale",
86
+ "id":"7IHOkHoMY1PpFp1VSVlCpH",
87
+ "version":0,
88
+ "space":{
89
+ "sys":{
90
+ "type":"Link",
91
+ "linkType":"Space",
92
+ "id":"n5kqlvx9cnp1"
93
+ }
94
+ },
95
+ "createdBy":{
96
+ "sys":{
97
+ "type":"Link",
98
+ "linkType":"User",
99
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
100
+ }
101
+ },
102
+ "createdAt":"2016-07-27T00:42:59Z",
103
+ "updatedBy":{
104
+ "sys":{
105
+ "type":"Link",
106
+ "linkType":"User",
107
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
108
+ }
109
+ },
110
+ "updatedAt":"2016-07-27T00:42:59Z"
111
+ }
112
+ }
113
+
114
+ http_version:
115
+ recorded_at: Wed, 27 Jul 2016 00:44:25 GMT
116
+ recorded_with: VCR 3.0.3
@@ -103,7 +103,7 @@ module Contentful
103
103
  vcr('entry/service_unavailable') do
104
104
  result = subject.find(space_id, 'not_exist')
105
105
  expect(result).to be_kind_of Contentful::Management::ServiceUnavailable
106
- expect(result.message).to eq 'Service Unavailable, contenful.com API seems to be down'
106
+ expect(result.message).to eq 'Service Unavailable, contentful.com API seems to be down'
107
107
  end
108
108
  end
109
109
  end
@@ -324,6 +324,45 @@ module Contentful
324
324
  end
325
325
  end
326
326
 
327
+ # Only here because we want to keep the contentful.rb-dependency out
328
+ class Contentful::Entry
329
+ attr_accessor :sys, :fields
330
+ def initialize(management_entry)
331
+ @sys = management_entry.sys
332
+ @fields = management_entry.fields
333
+ end
334
+
335
+ def id
336
+ @sys[:id]
337
+ end
338
+ end
339
+
340
+ class Contentful::BaseEntry < Contentful::Entry
341
+ end
342
+ #/ Only here because we want to keep the contentful.rb-dependency out
343
+
344
+ it 'with entry inherited from Contentful::Entry' do
345
+ vcr('entry/create_with_entry') do
346
+ entry_att = Contentful::BaseEntry.new(client.entries.find(space_id, '4o6ghKSmSko4i828YCYaEo'))
347
+ entry = subject.create(content_type, name: 'EntryWithEntry', age: 20, entry: entry_att)
348
+ expect(entry.name).to eq 'EntryWithEntry'
349
+ expect(entry.age).to eq 20
350
+ expect(entry.fields[:entry]['sys']['id']).to eq entry_att.id
351
+ end
352
+ end
353
+
354
+ it 'with entries inherited from Contentful::Entry' do
355
+ vcr('entry/create_with_entries') do
356
+ entry_att = Contentful::BaseEntry.new(subject.find(space_id, '1d1QDYzeiyWmgqQYysae8u'))
357
+ new_entry = subject.create(content_type,
358
+ name: 'EntryWithEntries',
359
+ age: 20,
360
+ entries: [entry_att, entry_att, entry_att])
361
+ expect(new_entry.name).to eq 'EntryWithEntries'
362
+ expect(new_entry.age).to eq 20
363
+ end
364
+ end
365
+
327
366
  it 'with asset' do
328
367
  vcr('entry/create_with_asset') do
329
368
  asset = client.assets.find(space_id, 'codequest_id_test_custom')
@@ -83,6 +83,25 @@ module Contentful
83
83
  end
84
84
  end
85
85
 
86
+ describe '#optional' do
87
+ let(:space_id) { 'n5kqlvx9cnp1' }
88
+ it 'is false for non optional' do
89
+ vcr('locale/find_not_optional') do
90
+ locale_id = '56eOu5hJwVNb4XfqsnQV97'
91
+ locale = subject.find(space_id, locale_id)
92
+ expect(locale.optional).to be_falsey
93
+ end
94
+ end
95
+
96
+ it 'is true for optional' do
97
+ vcr('locale/find_optional') do
98
+ locale_id = '7IHOkHoMY1PpFp1VSVlCpH'
99
+ locale = subject.find(space_id, locale_id)
100
+ expect(locale.optional).to be_truthy
101
+ end
102
+ end
103
+ end
104
+
86
105
  describe '#update' do
87
106
  let!(:space_id) { 'bjwq7b86vgmm' }
88
107
  let!(:locale_id) { '63274yOrU0s4XiJlAp1ZMQ' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful-management
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
  - Piotr Protas
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-05-31 00:00:00.000000000 Z
13
+ date: 2016-08-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '0.8'
21
+ version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '0.8'
28
+ version: '1.0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: multi_json
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -40,6 +40,20 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '1'
43
+ - !ruby/object:Gem::Dependency
44
+ name: json
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.8'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.8'
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: bundler
45
59
  requirement: !ruby/object:Gem::Requirement
@@ -446,6 +460,8 @@ files:
446
460
  - spec/fixtures/vcr_cassettes/locale/find_default.yml
447
461
  - spec/fixtures/vcr_cassettes/locale/find_for_space_not_found.yml
448
462
  - spec/fixtures/vcr_cassettes/locale/find_not_default.yml
463
+ - spec/fixtures/vcr_cassettes/locale/find_not_optional.yml
464
+ - spec/fixtures/vcr_cassettes/locale/find_optional.yml
449
465
  - spec/fixtures/vcr_cassettes/locale/reload.yml
450
466
  - spec/fixtures/vcr_cassettes/locale/update_both.yml
451
467
  - spec/fixtures/vcr_cassettes/locale/update_code.yml
@@ -736,6 +752,8 @@ test_files:
736
752
  - spec/fixtures/vcr_cassettes/locale/find_default.yml
737
753
  - spec/fixtures/vcr_cassettes/locale/find_for_space_not_found.yml
738
754
  - spec/fixtures/vcr_cassettes/locale/find_not_default.yml
755
+ - spec/fixtures/vcr_cassettes/locale/find_not_optional.yml
756
+ - spec/fixtures/vcr_cassettes/locale/find_optional.yml
739
757
  - spec/fixtures/vcr_cassettes/locale/reload.yml
740
758
  - spec/fixtures/vcr_cassettes/locale/update_both.yml
741
759
  - spec/fixtures/vcr_cassettes/locale/update_code.yml