contentful-management 0.2.0 → 0.2.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.
Files changed (34) hide show
  1. data/CHANGELOG.md +11 -6
  2. data/RELEASE.md +8 -0
  3. data/examples/blog.rb +2 -2
  4. data/examples/content_types.rb +2 -2
  5. data/examples/create_space.rb +0 -1
  6. data/lib/contentful/management/asset.rb +7 -8
  7. data/lib/contentful/management/client.rb +7 -7
  8. data/lib/contentful/management/content_type.rb +13 -13
  9. data/lib/contentful/management/content_type_entry_methods_factory.rb +1 -3
  10. data/lib/contentful/management/dynamic_entry.rb +8 -8
  11. data/lib/contentful/management/entry.rb +15 -29
  12. data/lib/contentful/management/field.rb +1 -1
  13. data/lib/contentful/management/locale.rb +2 -2
  14. data/lib/contentful/management/request.rb +3 -3
  15. data/lib/contentful/management/resource.rb +5 -5
  16. data/lib/contentful/management/resource/array_like.rb +2 -2
  17. data/lib/contentful/management/resource/asset_fields.rb +3 -3
  18. data/lib/contentful/management/resource/fields.rb +0 -1
  19. data/lib/contentful/management/resource/system_properties.rb +9 -9
  20. data/lib/contentful/management/resource_builder.rb +8 -8
  21. data/lib/contentful/management/response.rb +1 -1
  22. data/lib/contentful/management/space_asset_methods_factory.rb +1 -3
  23. data/lib/contentful/management/space_association_methods_factory.rb +2 -4
  24. data/lib/contentful/management/space_content_type_methods_factory.rb +1 -3
  25. data/lib/contentful/management/space_entry_methods_factory.rb +2 -4
  26. data/lib/contentful/management/space_locale_methods_factory.rb +1 -3
  27. data/lib/contentful/management/space_webhook_methods_factory.rb +2 -4
  28. data/lib/contentful/management/version.rb +1 -1
  29. data/spec/fixtures/vcr_cassettes/entry/create.yml +412 -85
  30. data/spec/fixtures/vcr_cassettes/entry/create_with_symbols.yml +2 -3
  31. data/spec/lib/contentful/management/content_type_spec.rb +2 -2
  32. data/spec/lib/contentful/management/entry_spec.rb +94 -6
  33. metadata +5 -6
  34. data/spec/fixtures/vcr_cassettes/entry/create_test.yml +0 -150
@@ -172,8 +172,7 @@ http_interactions:
172
172
  uri: https://api.contentful.com/spaces/yr5m0jky5hsh/entries/
173
173
  body:
174
174
  encoding: UTF-8
175
- string: '{"fields":{"name":{"en-US":"SymbolTest"},"symbols":{"en-US":["USD,
176
- PL, XX"]}}}'
175
+ string: '{"fields":{"name":{"en-US":"SymbolTest"},"symbols":{"en-US":["USD","PL","XX"]}}}'
177
176
  headers:
178
177
  User-Agent:
179
178
  - RubyContenfulManagementGem/0.0.1
@@ -226,7 +225,7 @@ http_interactions:
226
225
  },
227
226
  "symbols": {
228
227
  "en-US": [
229
- "USD, PL, XX"
228
+ "USD","PL","XX"
230
229
  ]
231
230
  }
232
231
  },
@@ -494,10 +494,10 @@ module Contentful
494
494
  content_type = subject.find('v2umtz8ths9v', 'category_content_type')
495
495
  entry = content_type.entries.new
496
496
  entry.name = 'Some testing EN name'
497
- entry.description= ' some testing EN description '
497
+ entry.description = ' some testing EN description '
498
498
  entry.locale = 'de-DE'
499
499
  entry.name = 'Some testing DE name'
500
- entry.description= ' some testing DE description'
500
+ entry.description = ' some testing DE description'
501
501
  entry.save
502
502
  expect(entry).to be_kind_of Contentful::Management::Entry
503
503
  end
@@ -196,6 +196,43 @@ module Contentful
196
196
  describe '.create' do
197
197
  let(:content_type_id) { '5DSpuKrl04eMAGQoQckeIq' }
198
198
  let(:content_type) { Contentful::Management::ContentType.find(space_id, content_type_id) }
199
+
200
+ it 'create with all attributes' do
201
+ vcr('entry/create') do
202
+ content_type = Contentful::Management::ContentType.find('ene4qtp2sh7u', '5BHZB1vi4ooq4wKcmA8e2c')
203
+ location = Location.new.tap do |location|
204
+ location.lat = 22.44
205
+ location.lon = 33.33
206
+ end
207
+ file = Asset.find('ene4qtp2sh7u', '2oNoT3vSAs82SOIQmKe0KG')
208
+ entry_att = Entry.find('ene4qtp2sh7u', '60zYC7nY9GcKGiCYwAs4wm')
209
+ entry = subject.create(content_type,
210
+ name: 'Test name',
211
+ number: 30,
212
+ float1: 1.1,
213
+ boolean: true, date: '2000-07-12T11:11:00+02:00',
214
+ time: '2000-07-12T11:11:00+02:00',
215
+ location: location,
216
+ file: file,
217
+ image: file,
218
+ array: %w(PL USD XX),
219
+ entry: entry_att,
220
+ entries: [entry_att, entry_att],
221
+ object_json: {'test' => {'@type' => 'Codequest'}}
222
+ )
223
+ expect(entry.name).to eq 'Test name'
224
+ expect(entry.number).to eq 30
225
+ expect(entry.float1).to eq 1.1
226
+ expect(entry.boolean).to eq true
227
+ expect(entry.date.to_s).to eq '2000-07-12T11:11:00+02:00'
228
+ expect(entry.time.to_s).to eq '2000-07-12T11:11:00+02:00'
229
+ expect(entry.file['sys']['id']).to eq '2oNoT3vSAs82SOIQmKe0KG'
230
+ expect(entry.image['sys']['id']).to eq '2oNoT3vSAs82SOIQmKe0KG'
231
+ expect(entry.array).to eq %w(PL USD XX)
232
+ expect(entry.entry['sys']['id']).to eq entry_att.id
233
+ expect(entry.entries.first['sys']['id']).to eq entry_att.id
234
+ end
235
+ end
199
236
  it 'with location' do
200
237
  vcr('entry/create_with_location') do
201
238
  location = Location.new
@@ -249,8 +286,9 @@ module Contentful
249
286
  end
250
287
  it 'with symbols' do
251
288
  vcr('entry/create_with_symbols') do
252
- entry = subject.create(content_type, name: 'SymbolTest', symbols: 'USD, PL, XX')
289
+ entry = subject.create(content_type, name: 'SymbolTest', symbols: %w(PL USD XX))
253
290
  expect(entry.name).to eq 'SymbolTest'
291
+ expect(entry.symbols).to eq %w(USD PL XX)
254
292
  end
255
293
  end
256
294
  it 'with custom id' do
@@ -284,9 +322,11 @@ module Contentful
284
322
  result = entry.update(name: 'Tom Handy', age: 20, birthday: '2000-07-12T11:11:00+02:00',
285
323
  city: location,
286
324
  bool: false,
287
- asset: asset, assets: [asset, asset, asset],
288
- entry: entry_att, entries: [entry_att, entry_att, entry_att],
289
- symbols: ['PL', 'USD', 'XX'])
325
+ asset: asset,
326
+ assets: [asset, asset, asset],
327
+ entry: entry_att,
328
+ entries: [entry_att, entry_att, entry_att],
329
+ symbols: %w(PL USD XX))
290
330
 
291
331
  expect(result).to be_kind_of Contentful::Management::Entry
292
332
 
@@ -355,8 +395,9 @@ module Contentful
355
395
  end
356
396
 
357
397
  describe 'search filters' do
358
- let(:space) { Contentful::Management::Space.find('bfsvtul0c41g')
359
- }
398
+ let(:space) do
399
+ Contentful::Management::Space.find('bfsvtul0c41g')
400
+ end
360
401
  context 'order' do
361
402
  it 'returns ordered entries by createdAt' do
362
403
  vcr('entry/search_filter/order_sys.createdAt') do
@@ -512,6 +553,53 @@ module Contentful
512
553
  end
513
554
  end
514
555
  end
556
+
557
+ describe '#fields_from_attributes' do
558
+
559
+ it 'parses all kind of fields' do
560
+
561
+ location = Location.new.tap do |location|
562
+ location.lat = 22.44
563
+ location.lon = 33.33
564
+ end
565
+ # file = Asset.find('ene4qtp2sh7u', '2oNoT3vSAs82SOIQmKe0KG')
566
+ # entry_att = Entry.find('ene4qtp2sh7u', '60zYC7nY9GcKGiCYwAs4wm')
567
+
568
+ attributes = {
569
+ name: 'Test name',
570
+ number: 30,
571
+ float1: 1.1,
572
+ boolean: true, date: '2000-07-12T11:11:00+02:00',
573
+ time: '2000-07-12T11:11:00+02:00',
574
+ location: location,
575
+ image: Asset.new,
576
+ images: [Asset.new, Asset.new],
577
+ array: %w(PL USD XX),
578
+ entry: Entry.new,
579
+ entries: [Entry.new, Entry.new],
580
+ object_json: {'test' => {'@type' => 'Codequest'}}
581
+ }
582
+
583
+ parsed_attributes = Entry.new.fields_from_attributes(attributes)
584
+
585
+ expect(parsed_attributes[:name]).to match('en-US' => 'Test name')
586
+ expect(parsed_attributes[:number]).to match('en-US' => 30)
587
+ expect(parsed_attributes[:float1]).to match('en-US' => 1.1)
588
+ expect(parsed_attributes[:boolean]).to match('en-US' => true)
589
+ expect(parsed_attributes[:date]).to match('en-US' => '2000-07-12T11:11:00+02:00')
590
+ expect(parsed_attributes[:time]).to match('en-US' => '2000-07-12T11:11:00+02:00')
591
+ expect(parsed_attributes[:location]).to match('en-US' => {lat: 22.44, lon: 33.33})
592
+ expect(parsed_attributes[:array]).to match('en-US' => %w(PL USD XX))
593
+ expect(parsed_attributes[:object_json]).to match('en-US' => {'test' => {'@type' => 'Codequest'}})
594
+ expect(parsed_attributes[:image]).to match('en-US' => {sys: {type: 'Link', linkType: 'Asset', id: nil}})
595
+ expect(parsed_attributes[:images]).to match('en-US' => [{sys: {type: 'Link', linkType: 'Asset', id: nil}}, {sys: {type: 'Link', linkType: 'Asset', id: nil}}])
596
+ expect(parsed_attributes[:entry]).to match('en-US' => {sys: {type: 'Link', linkType: 'Entry', id: nil}})
597
+ expect(parsed_attributes[:entries]).to match('en-US' => [{sys: {type: 'Link', linkType: 'Entry', id: nil}}, {sys: {type: 'Link', linkType: 'Entry', id: nil}}])
598
+
599
+ end
600
+
601
+ end
602
+
515
603
  end
516
604
  end
517
605
  end
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: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-09-04 00:00:00.000000000 Z
14
+ date: 2014-09-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: http
@@ -198,6 +198,7 @@ files:
198
198
  - Gemfile
199
199
  - LICENSE.txt
200
200
  - README.md
201
+ - RELEASE.md
201
202
  - Rakefile
202
203
  - bin/cma-console
203
204
  - contentful-management.gemspec
@@ -329,7 +330,6 @@ files:
329
330
  - spec/fixtures/vcr_cassettes/entry/archived_true.yml
330
331
  - spec/fixtures/vcr_cassettes/entry/content_type_entires.yml
331
332
  - spec/fixtures/vcr_cassettes/entry/create.yml
332
- - spec/fixtures/vcr_cassettes/entry/create_test.yml
333
333
  - spec/fixtures/vcr_cassettes/entry/create_with_asset.yml
334
334
  - spec/fixtures/vcr_cassettes/entry/create_with_assets.yml
335
335
  - spec/fixtures/vcr_cassettes/entry/create_with_custom_id.yml
@@ -444,7 +444,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
444
444
  version: '0'
445
445
  segments:
446
446
  - 0
447
- hash: -2896588542136824987
447
+ hash: 3064200717268341167
448
448
  required_rubygems_version: !ruby/object:Gem::Requirement
449
449
  none: false
450
450
  requirements:
@@ -453,7 +453,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
453
453
  version: '0'
454
454
  segments:
455
455
  - 0
456
- hash: -2896588542136824987
456
+ hash: 3064200717268341167
457
457
  requirements: []
458
458
  rubyforge_project:
459
459
  rubygems_version: 1.8.23
@@ -551,7 +551,6 @@ test_files:
551
551
  - spec/fixtures/vcr_cassettes/entry/archived_true.yml
552
552
  - spec/fixtures/vcr_cassettes/entry/content_type_entires.yml
553
553
  - spec/fixtures/vcr_cassettes/entry/create.yml
554
- - spec/fixtures/vcr_cassettes/entry/create_test.yml
555
554
  - spec/fixtures/vcr_cassettes/entry/create_with_asset.yml
556
555
  - spec/fixtures/vcr_cassettes/entry/create_with_assets.yml
557
556
  - spec/fixtures/vcr_cassettes/entry/create_with_custom_id.yml
@@ -1,150 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: post
5
- uri: https://api.contentful.com/spaces/yr5m0jky5hsh/assets/
6
- body:
7
- encoding: UTF-8
8
- string: '{"fields":{"title":{"en-US":"titlebyCreateAPI"},"description":{"en-US":"descByAPI"},"file":{"en-US":{"contentType":"image/jpeg","fileName":"pic1.jpg","upload":"https://upload.wikimedia.org/wikipedia/commons/c/c7/Gasometer_Berlin_Sch%C3%B6neberg_2011.jpg"}}}}'
9
- headers:
10
- User-Agent:
11
- - RubyContenfulManagementGem/0.0.1
12
- Authorization:
13
- - Bearer <ACCESS_TOKEN>
14
- Content-Type:
15
- - application/vnd.contentful.management.v1+json
16
- Host:
17
- - api.contentful.com
18
- response:
19
- status:
20
- code: 201
21
- message: Created
22
- headers:
23
- Server:
24
- - nginx
25
- Date:
26
- - Thu, 31 Jul 2014 07:22:08 GMT
27
- Content-Type:
28
- - application/vnd.contentful.management.v1+json
29
- Content-Length:
30
- - '948'
31
- Connection:
32
- - keep-alive
33
- X-Powered-By:
34
- - Express
35
- Cf-Space-Id:
36
- - yr5m0jky5hsh
37
- Etag:
38
- - '"1a447007bb6851b9f8563dc94d86c5b8"'
39
- Access-Control-Allow-Origin:
40
- - "*"
41
- Access-Control-Allow-Headers:
42
- - 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
43
- Access-Control-Allow-Methods:
44
- - DELETE,GET,HEAD,POST,PUT,OPTIONS
45
- "^access-Control-Expose-Headers":
46
- - Etag
47
- Access-Control-Max-Age:
48
- - '1728000'
49
- body:
50
- encoding: UTF-8
51
- string: |
52
- {
53
- "fields": {
54
- "title": {
55
- "en-US": "titlebyCreateAPI"
56
- },
57
- "description": {
58
- "en-US": "descByAPI"
59
- },
60
- "file": {
61
- "en-US": {
62
- "contentType": "image/jpeg",
63
- "fileName": "pic1.jpg",
64
- "upload": "https://upload.wikimedia.org/wikipedia/commons/c/c7/Gasometer_Berlin_Sch%C3%B6neberg_2011.jpg"
65
- }
66
- }
67
- },
68
- "sys": {
69
- "id": "4DmT2j54pWY8ocimkEU6qS",
70
- "type": "Asset",
71
- "version": 1,
72
- "createdAt": "2014-07-31T07:22:08.621Z",
73
- "createdBy": {
74
- "sys": {
75
- "type": "Link",
76
- "linkType": "User",
77
- "id": "1E7acJL8I5XUXAMHQt9Grs"
78
- }
79
- },
80
- "space": {
81
- "sys": {
82
- "type": "Link",
83
- "linkType": "Space",
84
- "id": "yr5m0jky5hsh"
85
- }
86
- },
87
- "updatedAt": "2014-07-31T07:22:08.621Z",
88
- "updatedBy": {
89
- "sys": {
90
- "type": "Link",
91
- "linkType": "User",
92
- "id": "1E7acJL8I5XUXAMHQt9Grs"
93
- }
94
- }
95
- }
96
- }
97
- http_version:
98
- recorded_at: Thu, 31 Jul 2014 07:22:08 GMT
99
- - request:
100
- method: put
101
- uri: https://api.contentful.com/spaces/yr5m0jky5hsh/assets/4DmT2j54pWY8ocimkEU6qS/files/en-US/process
102
- body:
103
- encoding: US-ASCII
104
- string: ''
105
- headers:
106
- User-Agent:
107
- - RubyContenfulManagementGem/0.0.1
108
- Authorization:
109
- - Bearer <ACCESS_TOKEN>
110
- Content-Type:
111
- - application/vnd.contentful.management.v1+json
112
- X-Contentful-Version:
113
- - '1'
114
- Content-Length:
115
- - '0'
116
- Host:
117
- - api.contentful.com
118
- response:
119
- status:
120
- code: 204
121
- message: No Content
122
- headers:
123
- Server:
124
- - nginx
125
- Date:
126
- - Thu, 31 Jul 2014 07:22:09 GMT
127
- Content-Type:
128
- - application/vnd.contentful.management.v1+json
129
- Connection:
130
- - keep-alive
131
- X-Powered-By:
132
- - Express
133
- Cf-Space-Id:
134
- - yr5m0jky5hsh
135
- Access-Control-Allow-Origin:
136
- - "*"
137
- Access-Control-Allow-Headers:
138
- - 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
139
- Access-Control-Allow-Methods:
140
- - DELETE,GET,HEAD,POST,PUT,OPTIONS
141
- "^access-Control-Expose-Headers":
142
- - Etag
143
- Access-Control-Max-Age:
144
- - '1728000'
145
- body:
146
- encoding: UTF-8
147
- string: ''
148
- http_version:
149
- recorded_at: Thu, 31 Jul 2014 07:22:09 GMT
150
- recorded_with: VCR 2.9.2