contentful 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=w5ZGw6JFwqZmVcKsE8Kow4grw45QdybCr8Okw6AYwqbDksO3ehvDpUPCgcKsKXbCiAwPC8K2w4LDvsOkw6nCjhPDpcOQADElWsOoU8KGR3HCtsOAwqd6wp_Dulp8w6LDsF_CtsK7Kk05wrMvwrLClMOgG2_Dn2sGPg
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContentfulGem/0.1.3
12
+ Authorization:
13
+ - Bearer b4c0n73n7fu1
14
+ Content-Type:
15
+ - application/vnd.contentful.delivery.v1+json
16
+ Host:
17
+ - cdn.contentful.com
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Fri, 25 Apr 2014 13:31:17 GMT
25
+ Server:
26
+ - nginx/1.1.19
27
+ Access-Control-Allow-Headers:
28
+ - 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
29
+ Access-Control-Allow-Methods:
30
+ - GET,HEAD,OPTIONS
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Max-Age:
34
+ - '86400'
35
+ Cache-Control:
36
+ - max-age=0
37
+ Content-Type:
38
+ - application/vnd.contentful.delivery.v1+json
39
+ Etag:
40
+ - '"382e4781b902b58d2edf3f10067167c7"'
41
+ X-Contentful-Request-Id:
42
+ - f1c-737770542
43
+ Content-Length:
44
+ - '300'
45
+ Accept-Ranges:
46
+ - bytes
47
+ Via:
48
+ - 1.1 varnish
49
+ Age:
50
+ - '0'
51
+ X-Served-By:
52
+ - cache-fra1229-FRA
53
+ X-Cache:
54
+ - MISS
55
+ X-Cache-Hits:
56
+ - '0'
57
+ Vary:
58
+ - Accept-Encoding
59
+ body:
60
+ encoding: UTF-8
61
+ string: |
62
+ {
63
+ "sys": {
64
+ "type": "Array"
65
+ },
66
+ "items": [],
67
+ "nextSyncUrl": "https://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=w5ZGw6JFwqZmVcKsE8Kow4grw45QdybCr8Okw6AYwqbDksO3ehvDpUPCgcKsKXbCiAwPC8K2w4LDvsOkw6nCjhPDpcOQADElWsOoU8KGR3HCtsOAwqd6wp_Dulp8w6LDsF_CtsK7Kk05wrMvwrLClMOgG2_Dn2sGPg"
68
+ }
69
+ http_version:
70
+ recorded_at: Fri, 25 Apr 2014 13:31:18 GMT
71
+ recorded_with: VCR 2.9.0
@@ -1,6 +1,3 @@
1
- require 'coveralls'
2
- Coveralls.wear!
3
-
4
1
  require 'rspec'
5
2
  require 'contentful'
6
3
  require 'securerandom'
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Contentful::SyncPage do
5
+ let(:page_with_more){ vcr('sync_page'){ create_client.sync(initial: true).first_page } }
6
+ let(:page){ vcr('sync_page_2'){ create_client.sync.get("https://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=w5ZGw6JFwqZmVcKsE8Kow4grw45QdybCr8Okw6AYwqbDksO3ehvDpUPCgcKsKXbCiAwPC8K2w4LDvsOkw6nCjhPDpcOQADElWsOoU8KGR3HCtsOAwqd6wp_Dulp8w6LDsF_CtsK7Kk05wrMvwrLClMOgG2_Dn2sGPg") } }
7
+
8
+ describe 'SystemProperties' do
9
+ it 'has a #sys getter returning a hash with symbol keys' do
10
+ expect( page.sys ).to be_a Hash
11
+ expect( page.sys.keys.sample ).to be_a Symbol
12
+ end
13
+
14
+ it 'has #type' do
15
+ expect( page.type ).to eq "Array"
16
+ end
17
+ end
18
+
19
+ describe 'Properties' do
20
+ it 'has a #properties getter returning a hash with symbol keys' do
21
+ expect( page.properties ).to be_a Hash
22
+ expect( page.properties.keys.sample ).to be_a Symbol
23
+ end
24
+
25
+ it 'has #items which contain resources' do
26
+ expect( page_with_more.items ).to be_a Array
27
+ expect( page_with_more.items.sample ).to be_a Contentful::Resource
28
+ end
29
+ end
30
+
31
+ describe 'Fields' do
32
+ it 'properly deals with nested locale fields' do
33
+ expect( page_with_more.items.first.fields[:name] ).to eq "London"
34
+ end
35
+ end
36
+
37
+ describe '#each' do
38
+ it 'is an Enumerator' do
39
+ expect( page.each ).to be_a Enumerator
40
+ end
41
+
42
+ it 'iterates over items' do
43
+ expect( page.each.to_a ).to eq page.items
44
+ end
45
+
46
+ it 'includes Enumerable' do
47
+ expect( page.map{ |r| r.type } ).to eq page.items.map{ |r| r.type }
48
+ end
49
+ end
50
+
51
+ describe '#next_sync_url' do
52
+ it 'will return the next_sync_url if there is one' do
53
+ expect( page.next_sync_url ).to be_a String
54
+ end
55
+
56
+ it 'will return nil if note last page, yet' do
57
+ expect( page_with_more.next_sync_url ).to be_nil
58
+ end
59
+ end
60
+
61
+ describe '#next_page_url' do
62
+ it 'will return the next_page_url if there is one' do
63
+ expect( page_with_more.next_page_url ).to be_a String
64
+ end
65
+
66
+ it 'will return nil if on last page' do
67
+ expect( page.next_page_url ).to be_nil
68
+ end
69
+ end
70
+
71
+ describe '#next_page' do
72
+ it 'requests the next page' do
73
+ next_page = vcr('sync_page_2'){
74
+ page_with_more.next_page
75
+ }
76
+ expect( next_page ).to be_a Contentful::SyncPage
77
+ end
78
+
79
+ it 'will return nil if last page' do
80
+ expect( page.next_page_url ).to be_nil
81
+ end
82
+ end
83
+
84
+ describe '#next_page?' do
85
+ it 'will return true if there is a next page' do
86
+ expect( page_with_more.next_page? ).to be_true
87
+ end
88
+
89
+ it 'will return false if last page' do
90
+ expect( page.next_page? ).to be_false
91
+ end
92
+ end
93
+
94
+ describe '#last_page?' do
95
+ it 'will return true if no more pages available' do
96
+ expect( page.last_page? ).to be_true
97
+ end
98
+
99
+ it 'will return false if more pages available' do
100
+ expect( page_with_more.last_page? ).to be_false
101
+ end
102
+ end
103
+
104
+ describe '#sync' do
105
+ it 'returns the sync that created the page' do
106
+ expect( page.sync ).to be_a Contentful::Sync
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Contentful::Sync do
5
+ let(:first_page) do
6
+ vcr('sync_page'){
7
+ create_client.sync(initial: true).first_page
8
+ }
9
+ end
10
+
11
+ let(:last_page) do
12
+ vcr('sync_page'){
13
+ vcr('sync_page_2'){
14
+ create_client.sync(initial: true).first_page.next_page
15
+ }
16
+ }
17
+ end
18
+
19
+
20
+ describe '#initialize' do
21
+ it 'takes an options hash on initialization' do
22
+ expect{
23
+ vcr('sync_deletion'){ create_client.sync(initial: true, type: 'Deletion').first_page }
24
+ }.not_to raise_exception
25
+ end
26
+
27
+ it 'takes a next_sync_url on initialization' do
28
+ expect{
29
+ vcr('sync_page_2'){ create_client.sync("https://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=w5ZGw6JFwqZmVcKsE8Kow4grw45QdybCr8Okw6AYwqbDksO3ehvDpUPCgcKsKXbCiAwPC8K2w4LDvsOkw6nCjhPDpcOQADElWsOoU8KGR3HCtsOAwqd6wp_Dulp8w6LDsF_CtsK7Kk05wrMvwrLClMOgG2_Dn2sGPg").first_page }
30
+ }.not_to raise_exception
31
+ end
32
+ end
33
+
34
+ describe '#first_page' do
35
+ it 'returns only the first page of a new sync' do
36
+ vcr('sync_page'){
37
+ expect( create_client.sync(initial: true).first_page ).to be_a Contentful::SyncPage
38
+ }
39
+ end
40
+ end
41
+
42
+ describe '#each_page' do
43
+ it 'iterates through sync pages' do
44
+ sync = create_client.sync(initial: true)
45
+ vcr('sync_page'){ vcr('sync_page_2'){
46
+ count = 0
47
+ sync.each_page do |page|
48
+ expect( page ).to be_a Contentful::SyncPage
49
+ count += 1
50
+ end
51
+ expect( count ).to eq 2
52
+ }}
53
+ end
54
+ end
55
+
56
+ describe '#next_sync_url' do
57
+ it 'is empty if there are still more pages to request in the current sync' do
58
+ expect( first_page.next_sync_url ).to be_nil
59
+ end
60
+
61
+ it 'returns the url to continue the sync next time' do
62
+ expect( last_page.next_sync_url ).to be_a String
63
+ end
64
+ end
65
+
66
+ describe '#completed?' do
67
+ it 'will return true if no more pages to request in the current sync' do
68
+ expect( first_page.next_sync_url ).to be_false
69
+ end
70
+
71
+ it 'will return true if not all pages requested, yet' do
72
+ expect( last_page.next_sync_url ).to be_true
73
+ end
74
+ end
75
+
76
+ describe '#each_item' do
77
+ it 'will directly iterate through all resources' do
78
+ sync = create_client.sync(initial: true)
79
+ vcr('sync_page'){ vcr('sync_page_2'){
80
+ sync.each_item do |item|
81
+ expect( item ).to be_a Contentful::Resource
82
+ end
83
+ }}
84
+ end
85
+ end
86
+ end
metadata CHANGED
@@ -1,145 +1,164 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Contentful GmbH (Jan Lelis)
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-04-22 00:00:00.000000000 Z
12
+ date: 2014-05-02 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: http
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - "~>"
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0.6'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - "~>"
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.6'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: multi_json
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - "~>"
35
+ - - ~>
32
36
  - !ruby/object:Gem::Version
33
37
  version: '1'
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - "~>"
43
+ - - ~>
39
44
  - !ruby/object:Gem::Version
40
45
  version: '1'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: bundler
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - "~>"
51
+ - - ~>
46
52
  - !ruby/object:Gem::Version
47
53
  version: '1.5'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - "~>"
59
+ - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: '1.5'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rake
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - "~>"
67
+ - - ~>
60
68
  - !ruby/object:Gem::Version
61
69
  version: '10'
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - "~>"
75
+ - - ~>
67
76
  - !ruby/object:Gem::Version
68
77
  version: '10'
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rubygems-tasks
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
- - - "~>"
83
+ - - ~>
74
84
  - !ruby/object:Gem::Version
75
85
  version: '0.2'
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
- - - "~>"
91
+ - - ~>
81
92
  - !ruby/object:Gem::Version
82
93
  version: '0.2'
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: rspec
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
- - - "~>"
99
+ - - ~>
88
100
  - !ruby/object:Gem::Version
89
101
  version: '2'
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
- - - "~>"
107
+ - - ~>
95
108
  - !ruby/object:Gem::Version
96
109
  version: '2'
97
110
  - !ruby/object:Gem::Dependency
98
111
  name: rr
99
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
100
114
  requirements:
101
- - - ">="
115
+ - - ! '>='
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
107
122
  requirements:
108
- - - ">="
123
+ - - ! '>='
109
124
  - !ruby/object:Gem::Version
110
125
  version: '0'
111
126
  - !ruby/object:Gem::Dependency
112
127
  name: vcr
113
128
  requirement: !ruby/object:Gem::Requirement
129
+ none: false
114
130
  requirements:
115
- - - ">="
131
+ - - ! '>='
116
132
  - !ruby/object:Gem::Version
117
133
  version: '0'
118
134
  type: :development
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
121
138
  requirements:
122
- - - ">="
139
+ - - ! '>='
123
140
  - !ruby/object:Gem::Version
124
141
  version: '0'
125
142
  - !ruby/object:Gem::Dependency
126
143
  name: webmock
127
144
  requirement: !ruby/object:Gem::Requirement
145
+ none: false
128
146
  requirements:
129
- - - "~>"
147
+ - - ~>
130
148
  - !ruby/object:Gem::Version
131
149
  version: '1'
132
- - - ">="
150
+ - - ! '>='
133
151
  - !ruby/object:Gem::Version
134
152
  version: 1.17.3
135
153
  type: :development
136
154
  prerelease: false
137
155
  version_requirements: !ruby/object:Gem::Requirement
156
+ none: false
138
157
  requirements:
139
- - - "~>"
158
+ - - ~>
140
159
  - !ruby/object:Gem::Version
141
160
  version: '1'
142
- - - ">="
161
+ - - ! '>='
143
162
  - !ruby/object:Gem::Version
144
163
  version: 1.17.3
145
164
  description: Ruby client for the https://www.contentful.com Content Delivery API
@@ -148,29 +167,27 @@ executables: []
148
167
  extensions: []
149
168
  extra_rdoc_files: []
150
169
  files:
151
- - ".gitignore"
152
- - ".rspec"
153
- - ".travis.yml"
154
- - CHANGELOG.md
155
- - Gemfile
156
- - Gemfile.lock
157
- - LICENSE.txt
158
- - README.md
159
- - Rakefile
160
- - contentful.gemspec
170
+ - .gitignore
171
+ - .rspec
172
+ - .travis.yml
161
173
  - coverage/.last_run.json
162
174
  - coverage/.resultset.json
175
+ - CHANGELOG.md
176
+ - contentful.gemspec
163
177
  - examples/custom_classes.rb
164
178
  - examples/dynamic_entries.rb
165
179
  - examples/example_queries.rb
166
180
  - examples/raise_errors.rb
167
181
  - examples/raw_mode.rb
168
182
  - examples/resource_mapping.rb
169
- - lib/contentful.rb
183
+ - Gemfile
184
+ - Gemfile.lock
170
185
  - lib/contentful/array.rb
171
186
  - lib/contentful/asset.rb
172
187
  - lib/contentful/client.rb
173
188
  - lib/contentful/content_type.rb
189
+ - lib/contentful/deleted_asset.rb
190
+ - lib/contentful/deleted_entry.rb
174
191
  - lib/contentful/dynamic_entry.rb
175
192
  - lib/contentful/entry.rb
176
193
  - lib/contentful/error.rb
@@ -180,15 +197,22 @@ files:
180
197
  - lib/contentful/locale.rb
181
198
  - lib/contentful/location.rb
182
199
  - lib/contentful/request.rb
183
- - lib/contentful/resource.rb
200
+ - lib/contentful/resource/array_like.rb
184
201
  - lib/contentful/resource/asset_fields.rb
185
202
  - lib/contentful/resource/fields.rb
186
203
  - lib/contentful/resource/system_properties.rb
204
+ - lib/contentful/resource.rb
187
205
  - lib/contentful/resource_builder.rb
188
206
  - lib/contentful/response.rb
189
207
  - lib/contentful/space.rb
190
208
  - lib/contentful/support.rb
209
+ - lib/contentful/sync.rb
210
+ - lib/contentful/sync_page.rb
191
211
  - lib/contentful/version.rb
212
+ - lib/contentful.rb
213
+ - LICENSE.txt
214
+ - Rakefile
215
+ - README.md
192
216
  - spec/array_spec.rb
193
217
  - spec/asset_spec.rb
194
218
  - spec/auto_includes_spec.rb
@@ -196,6 +220,8 @@ files:
196
220
  - spec/client_configuration_spec.rb
197
221
  - spec/coercions_spec.rb
198
222
  - spec/content_type_spec.rb
223
+ - spec/deleted_asset_spec.rb
224
+ - spec/deleted_entry_spec.rb
199
225
  - spec/dynamic_entry_spec.rb
200
226
  - spec/entry_spec.rb
201
227
  - spec/error_class_spec.rb
@@ -226,6 +252,11 @@ files:
226
252
  - spec/fixtures/vcr_cassettes/nyancat.yml
227
253
  - spec/fixtures/vcr_cassettes/reloaded_entry.yml
228
254
  - spec/fixtures/vcr_cassettes/space.yml
255
+ - spec/fixtures/vcr_cassettes/sync_deleted_asset.yml
256
+ - spec/fixtures/vcr_cassettes/sync_deleted_entry.yml
257
+ - spec/fixtures/vcr_cassettes/sync_deletion.yml
258
+ - spec/fixtures/vcr_cassettes/sync_page.yml
259
+ - spec/fixtures/vcr_cassettes/sync_page_2.yml
229
260
  - spec/fixtures/vcr_cassettes/unauthorized.yml
230
261
  - spec/link_spec.rb
231
262
  - spec/locale_spec.rb
@@ -239,29 +270,39 @@ files:
239
270
  - spec/support/client.rb
240
271
  - spec/support/json_responses.rb
241
272
  - spec/support/vcr.rb
273
+ - spec/sync_page_spec.rb
274
+ - spec/sync_spec.rb
275
+ - TAGS
242
276
  homepage: https://github.com/contentful/contentful.rb
243
277
  licenses:
244
278
  - MIT
245
- metadata: {}
246
279
  post_install_message:
247
280
  rdoc_options: []
248
281
  require_paths:
249
282
  - lib
250
283
  required_ruby_version: !ruby/object:Gem::Requirement
284
+ none: false
251
285
  requirements:
252
- - - ">="
286
+ - - ! '>='
253
287
  - !ruby/object:Gem::Version
254
288
  version: '0'
289
+ segments:
290
+ - 0
291
+ hash: -620049112391953740
255
292
  required_rubygems_version: !ruby/object:Gem::Requirement
293
+ none: false
256
294
  requirements:
257
- - - ">="
295
+ - - ! '>='
258
296
  - !ruby/object:Gem::Version
259
297
  version: '0'
298
+ segments:
299
+ - 0
300
+ hash: -620049112391953740
260
301
  requirements: []
261
302
  rubyforge_project:
262
- rubygems_version: 2.2.0
303
+ rubygems_version: 1.8.23.2
263
304
  signing_key:
264
- specification_version: 4
305
+ specification_version: 3
265
306
  summary: contentful
266
307
  test_files:
267
308
  - spec/array_spec.rb
@@ -271,6 +312,8 @@ test_files:
271
312
  - spec/client_configuration_spec.rb
272
313
  - spec/coercions_spec.rb
273
314
  - spec/content_type_spec.rb
315
+ - spec/deleted_asset_spec.rb
316
+ - spec/deleted_entry_spec.rb
274
317
  - spec/dynamic_entry_spec.rb
275
318
  - spec/entry_spec.rb
276
319
  - spec/error_class_spec.rb
@@ -301,6 +344,11 @@ test_files:
301
344
  - spec/fixtures/vcr_cassettes/nyancat.yml
302
345
  - spec/fixtures/vcr_cassettes/reloaded_entry.yml
303
346
  - spec/fixtures/vcr_cassettes/space.yml
347
+ - spec/fixtures/vcr_cassettes/sync_deleted_asset.yml
348
+ - spec/fixtures/vcr_cassettes/sync_deleted_entry.yml
349
+ - spec/fixtures/vcr_cassettes/sync_deletion.yml
350
+ - spec/fixtures/vcr_cassettes/sync_page.yml
351
+ - spec/fixtures/vcr_cassettes/sync_page_2.yml
304
352
  - spec/fixtures/vcr_cassettes/unauthorized.yml
305
353
  - spec/link_spec.rb
306
354
  - spec/locale_spec.rb
@@ -314,3 +362,5 @@ test_files:
314
362
  - spec/support/client.rb
315
363
  - spec/support/json_responses.rb
316
364
  - spec/support/vcr.rb
365
+ - spec/sync_page_spec.rb
366
+ - spec/sync_spec.rb