contentful-management 1.6.0 → 1.7.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.rubocop_todo.yml +3 -3
  4. data/.travis.yml +4 -3
  5. data/CHANGELOG.md +5 -0
  6. data/Gemfile +0 -8
  7. data/Guardfile +3 -54
  8. data/README.md +45 -0
  9. data/Rakefile +0 -5
  10. data/contentful-management.gemspec +8 -5
  11. data/lib/contentful/management/client.rb +44 -14
  12. data/lib/contentful/management/client_upload_methods_factory.rb +19 -0
  13. data/lib/contentful/management/content_type.rb +19 -19
  14. data/lib/contentful/management/dynamic_entry.rb +1 -1
  15. data/lib/contentful/management/entry.rb +57 -50
  16. data/lib/contentful/management/http_client.rb +7 -1
  17. data/lib/contentful/management/request.rb +14 -9
  18. data/lib/contentful/management/resource.rb +7 -7
  19. data/lib/contentful/management/resource/array_like.rb +2 -2
  20. data/lib/contentful/management/resource/system_properties.rb +2 -1
  21. data/lib/contentful/management/resource_builder.rb +6 -3
  22. data/lib/contentful/management/resource_requester.rb +3 -3
  23. data/lib/contentful/management/support.rb +1 -1
  24. data/lib/contentful/management/upload.rb +42 -0
  25. data/lib/contentful/management/version.rb +1 -1
  26. data/spec/fixtures/pixel.jpg +0 -0
  27. data/spec/fixtures/vcr_cassettes/upload/associate_with_asset.yml +426 -0
  28. data/spec/fixtures/vcr_cassettes/upload/create_file.yml +85 -0
  29. data/spec/fixtures/vcr_cassettes/upload/create_path.yml +85 -0
  30. data/spec/fixtures/vcr_cassettes/upload/destroy.yml +133 -0
  31. data/spec/fixtures/vcr_cassettes/upload/find.yml +82 -0
  32. data/spec/fixtures/vcr_cassettes/upload/find_not_found.yml +66 -0
  33. data/spec/lib/contentful/management/client_spec.rb +25 -0
  34. data/spec/lib/contentful/management/upload_spec.rb +92 -0
  35. data/spec/spec_helper.rb +9 -1
  36. metadata +91 -11
@@ -46,6 +46,31 @@ module Contentful
46
46
  end
47
47
  end
48
48
 
49
+ describe '#host_url' do
50
+ describe 'uploads' do
51
+ it 'returns uploads url when its a properly formed upload url' do
52
+ expect(subject.host_url(RequestDouble.new('/some_space_id/uploads'))).to eq subject.uploads_url
53
+ expect(subject.host_url(RequestDouble.new('/some_space_id/uploads/upload_id'))).to eq subject.uploads_url
54
+ expect(subject.host_url(RequestDouble.new('/uploads/uploads/uploads'))).to eq subject.uploads_url
55
+ end
56
+
57
+ it 'returns base url for non uploads url' do
58
+ uploads_as_space_id = '/uploads/entries/upload_id'
59
+ expect(subject.host_url(RequestDouble.new(uploads_as_space_id))).to eq subject.base_url
60
+
61
+ uploads_as_entry_id = '/some_space_id/entries/uploads'
62
+ expect(subject.host_url(RequestDouble.new(uploads_as_entry_id))).to eq subject.base_url
63
+
64
+ uploads_as_only_thing = '/uploads'
65
+ expect(subject.host_url(RequestDouble.new(uploads_as_only_thing))).to eq subject.base_url
66
+ end
67
+ end
68
+
69
+ it 'returns base url otherwise' do
70
+ expect(subject.host_url(RequestDouble.new('/some_space_id'))).to eq subject.base_url
71
+ end
72
+ end
73
+
49
74
  describe '#protocol' do
50
75
  its(:protocol) { should eql 'https' }
51
76
 
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+ require 'contentful/management/space'
3
+ require 'contentful/management/client'
4
+
5
+ module Contentful
6
+ module Management
7
+ describe Upload do
8
+ let(:token) { '<ACCESS_TOKEN>' }
9
+ let(:space_id) { 'facgnwwgj5fe' }
10
+ let(:upload_id) { 'IUMb6WLjk9fjQ0WZfG971' }
11
+ let(:pixel_path) { ::File.join('spec', 'fixtures', 'pixel.jpg') }
12
+ let!(:client) { Client.new(token) }
13
+
14
+ subject { client.uploads }
15
+
16
+ describe '.find' do
17
+ it 'class method also works' do
18
+ vcr('upload/find') {
19
+ upload = Contentful::Management::Upload.find(client, space_id, upload_id)
20
+ expect(upload).to be_kind_of Contentful::Management::Upload
21
+ expect(upload.id).to eq upload_id
22
+ }
23
+ end
24
+ it 'returns a Contentful::Management::Upload' do
25
+ vcr('upload/find') {
26
+ upload = subject.find(space_id, upload_id)
27
+ expect(upload).to be_kind_of Contentful::Management::Upload
28
+ expect(upload.id).to eq upload_id
29
+ }
30
+ end
31
+ it 'returns upload for a given key' do
32
+ vcr('upload/find') do
33
+ upload = subject.find(space_id, upload_id)
34
+ expect(upload).to be_kind_of Contentful::Management::Upload
35
+ expect(upload.id).to eq upload_id
36
+ end
37
+ end
38
+ it 'returns an error when upload does not exist' do
39
+ vcr('upload/find_not_found') do
40
+ result = subject.find(space_id, 'not_exist')
41
+ expect(result).to be_kind_of Contentful::Management::NotFound
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '.create' do
47
+ it 'creates an upload from a ::File' do
48
+ vcr('upload/create_file') do
49
+ ::File.open(pixel_path, 'rb') do |f|
50
+ upload = subject.create(space_id, f)
51
+ expect(upload).to be_kind_of Contentful::Management::Upload
52
+ end
53
+ end
54
+ end
55
+
56
+ it 'creates an upload from a /path/to/file' do
57
+ vcr('upload/create_path') do
58
+ upload = subject.create(space_id, pixel_path)
59
+ expect(upload).to be_kind_of Contentful::Management::Upload
60
+ end
61
+ end
62
+
63
+ it 'an upload can be associated to an asset' do
64
+ vcr('upload/associate_with_asset') do
65
+ upload = subject.create(space_id, pixel_path)
66
+
67
+ file = Contentful::Management::File.new
68
+ file.properties[:contentType] = 'image/jpeg'
69
+ file.properties[:fileName] = 'pixel'
70
+ file.properties[:uploadFrom] = upload.to_link_json
71
+
72
+ asset = client.assets.create(space_id, title: 'pixel', file: file)
73
+ asset.process_file
74
+ asset.reload
75
+
76
+ expect(asset.file.url).not_to be_nil
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '#destroy' do
82
+ it 'returns true' do
83
+ vcr('upload/destroy') do
84
+ upload = subject.find(space_id, upload_id)
85
+ result = upload.destroy
86
+ expect(result).to eq true
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'simplecov'
2
- SimpleCov.start
2
+ SimpleCov.start unless RUBY_PLATFORM == 'java'
3
3
 
4
4
  require 'rspec'
5
5
  require 'contentful/management'
@@ -12,3 +12,11 @@ RSpec.configure do |config|
12
12
  config.filter_run :focus => true
13
13
  config.run_all_when_everything_filtered = true
14
14
  end
15
+
16
+ class RequestDouble
17
+ attr_reader :url
18
+
19
+ def initialize(url)
20
+ @url = url
21
+ end
22
+ 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: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Protas
@@ -10,22 +10,28 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-04-11 00:00:00.000000000 Z
13
+ date: 2017-05-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">"
20
20
  - !ruby/object:Gem::Version
21
21
  version: '1.0'
22
+ - - "<"
23
+ - !ruby/object:Gem::Version
24
+ version: '3.0'
22
25
  type: :runtime
23
26
  prerelease: false
24
27
  version_requirements: !ruby/object:Gem::Requirement
25
28
  requirements:
26
- - - "~>"
29
+ - - ">"
27
30
  - !ruby/object:Gem::Version
28
31
  version: '1.0'
32
+ - - "<"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
29
35
  - !ruby/object:Gem::Dependency
30
36
  name: multi_json
31
37
  requirement: !ruby/object:Gem::Requirement
@@ -125,7 +131,49 @@ dependencies:
125
131
  - !ruby/object:Gem::Version
126
132
  version: '0'
127
133
  - !ruby/object:Gem::Dependency
128
- name: rubocop
134
+ name: guard
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ - !ruby/object:Gem::Dependency
148
+ name: guard-rspec
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ - !ruby/object:Gem::Dependency
162
+ name: guard-rubocop
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ - !ruby/object:Gem::Dependency
176
+ name: guard-yard
129
177
  requirement: !ruby/object:Gem::Requirement
130
178
  requirements:
131
179
  - - ">="
@@ -139,33 +187,33 @@ dependencies:
139
187
  - !ruby/object:Gem::Version
140
188
  version: '0'
141
189
  - !ruby/object:Gem::Dependency
142
- name: reek
190
+ name: rubocop
143
191
  requirement: !ruby/object:Gem::Requirement
144
192
  requirements:
145
193
  - - "~>"
146
194
  - !ruby/object:Gem::Version
147
- version: 2.2.1
195
+ version: 0.41.0
148
196
  type: :development
149
197
  prerelease: false
150
198
  version_requirements: !ruby/object:Gem::Requirement
151
199
  requirements:
152
200
  - - "~>"
153
201
  - !ruby/object:Gem::Version
154
- version: 2.2.1
202
+ version: 0.41.0
155
203
  - !ruby/object:Gem::Dependency
156
- name: unparser
204
+ name: listen
157
205
  requirement: !ruby/object:Gem::Requirement
158
206
  requirements:
159
207
  - - '='
160
208
  - !ruby/object:Gem::Version
161
- version: 0.2.4
209
+ version: 3.0.0
162
210
  type: :development
163
211
  prerelease: false
164
212
  version_requirements: !ruby/object:Gem::Requirement
165
213
  requirements:
166
214
  - - '='
167
215
  - !ruby/object:Gem::Version
168
- version: 0.2.4
216
+ version: 3.0.0
169
217
  - !ruby/object:Gem::Dependency
170
218
  name: vcr
171
219
  requirement: !ruby/object:Gem::Requirement
@@ -200,6 +248,20 @@ dependencies:
200
248
  - - ">="
201
249
  - !ruby/object:Gem::Version
202
250
  version: 1.17.3
251
+ - !ruby/object:Gem::Dependency
252
+ name: simplecov
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
203
265
  description: Ruby client for the https://www.contentful.com Content Management API
204
266
  email:
205
267
  - piotrek@codequest.com
@@ -245,6 +307,7 @@ files:
245
307
  - lib/contentful/management/client_role_methods_factory.rb
246
308
  - lib/contentful/management/client_snapshot_methods_factory.rb
247
309
  - lib/contentful/management/client_space_methods_factory.rb
310
+ - lib/contentful/management/client_upload_methods_factory.rb
248
311
  - lib/contentful/management/client_webhook_methods_factory.rb
249
312
  - lib/contentful/management/content_type.rb
250
313
  - lib/contentful/management/content_type_editor_interface_methods_factory.rb
@@ -290,9 +353,11 @@ files:
290
353
  - lib/contentful/management/space_role_methods_factory.rb
291
354
  - lib/contentful/management/space_webhook_methods_factory.rb
292
355
  - lib/contentful/management/support.rb
356
+ - lib/contentful/management/upload.rb
293
357
  - lib/contentful/management/validation.rb
294
358
  - lib/contentful/management/version.rb
295
359
  - lib/contentful/management/webhook.rb
360
+ - spec/fixtures/pixel.jpg
296
361
  - spec/fixtures/vcr_cassettes/api_key/all_for_space.yml
297
362
  - spec/fixtures/vcr_cassettes/api_key/create_for_space.yml
298
363
  - spec/fixtures/vcr_cassettes/api_key/find.yml
@@ -546,6 +611,12 @@ files:
546
611
  - spec/fixtures/vcr_cassettes/space/webhook/all.yml
547
612
  - spec/fixtures/vcr_cassettes/space/webhook/create.yml
548
613
  - spec/fixtures/vcr_cassettes/space/webhook/find.yml
614
+ - spec/fixtures/vcr_cassettes/upload/associate_with_asset.yml
615
+ - spec/fixtures/vcr_cassettes/upload/create_file.yml
616
+ - spec/fixtures/vcr_cassettes/upload/create_path.yml
617
+ - spec/fixtures/vcr_cassettes/upload/destroy.yml
618
+ - spec/fixtures/vcr_cassettes/upload/find.yml
619
+ - spec/fixtures/vcr_cassettes/upload/find_not_found.yml
549
620
  - spec/fixtures/vcr_cassettes/webhook/all.yml
550
621
  - spec/fixtures/vcr_cassettes/webhook/create.yml
551
622
  - spec/fixtures/vcr_cassettes/webhook/create_with_name_and_headers.yml
@@ -566,6 +637,7 @@ files:
566
637
  - spec/lib/contentful/management/role_spec.rb
567
638
  - spec/lib/contentful/management/snapshot_spec.rb
568
639
  - spec/lib/contentful/management/space_spec.rb
640
+ - spec/lib/contentful/management/upload_spec.rb
569
641
  - spec/lib/contentful/management/webhook_spec.rb
570
642
  - spec/spec_helper.rb
571
643
  - spec/support/vcr.rb
@@ -594,6 +666,7 @@ signing_key:
594
666
  specification_version: 4
595
667
  summary: contentful management api
596
668
  test_files:
669
+ - spec/fixtures/pixel.jpg
597
670
  - spec/fixtures/vcr_cassettes/api_key/all_for_space.yml
598
671
  - spec/fixtures/vcr_cassettes/api_key/create_for_space.yml
599
672
  - spec/fixtures/vcr_cassettes/api_key/find.yml
@@ -847,6 +920,12 @@ test_files:
847
920
  - spec/fixtures/vcr_cassettes/space/webhook/all.yml
848
921
  - spec/fixtures/vcr_cassettes/space/webhook/create.yml
849
922
  - spec/fixtures/vcr_cassettes/space/webhook/find.yml
923
+ - spec/fixtures/vcr_cassettes/upload/associate_with_asset.yml
924
+ - spec/fixtures/vcr_cassettes/upload/create_file.yml
925
+ - spec/fixtures/vcr_cassettes/upload/create_path.yml
926
+ - spec/fixtures/vcr_cassettes/upload/destroy.yml
927
+ - spec/fixtures/vcr_cassettes/upload/find.yml
928
+ - spec/fixtures/vcr_cassettes/upload/find_not_found.yml
850
929
  - spec/fixtures/vcr_cassettes/webhook/all.yml
851
930
  - spec/fixtures/vcr_cassettes/webhook/create.yml
852
931
  - spec/fixtures/vcr_cassettes/webhook/create_with_name_and_headers.yml
@@ -867,6 +946,7 @@ test_files:
867
946
  - spec/lib/contentful/management/role_spec.rb
868
947
  - spec/lib/contentful/management/snapshot_spec.rb
869
948
  - spec/lib/contentful/management/space_spec.rb
949
+ - spec/lib/contentful/management/upload_spec.rb
870
950
  - spec/lib/contentful/management/webhook_spec.rb
871
951
  - spec/spec_helper.rb
872
952
  - spec/support/vcr.rb