diff --git a/CHANGELOG.md b/CHANGELOG.md index 677f634..4d5c5b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased ### Fixed * Fix Custom Resource creation parameters [#69](https://github.com/contentful/contentful.rb/issues/69) +* `Sync API` now works with `:raw_mode` enabled [#68](https://github.com/contentful/contentful.rb/issues/68) ## 0.6.0 ### Fixed diff --git a/lib/contentful/sync.rb b/lib/contentful/sync.rb index 2f297ad..0f69eab 100644 --- a/lib/contentful/sync.rb +++ b/lib/contentful/sync.rb @@ -51,6 +51,10 @@ def get(options_or_url) page = Request.new(@client, '/sync', options_or_url).get end + if @client.configuration[:raw_mode] + return page + end + link_page_to_sync! page update_sync_state_from! page diff --git a/spec/fixtures/vcr_cassettes/sync_page_short.yml b/spec/fixtures/vcr_cassettes/sync_page_short.yml new file mode 100644 index 0000000..490aa7c --- /dev/null +++ b/spec/fixtures/vcr_cassettes/sync_page_short.yml @@ -0,0 +1,106 @@ +--- +http_interactions: +- request: + method: get + uri: https://cdn.contentful.com/spaces/cfexampleapi/sync?initial=true + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - RubyContentfulGem/0.1.3 + Authorization: + - Bearer b4c0n73n7fu1 + Content-Type: + - application/vnd.contentful.delivery.v1+json + Host: + - cdn.contentful.com + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 25 Apr 2014 13:31:17 GMT + Server: + - nginx/1.1.19 + Access-Control-Allow-Headers: + - 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 + Access-Control-Allow-Methods: + - GET,HEAD,OPTIONS + Access-Control-Allow-Origin: + - "*" + Access-Control-Max-Age: + - '86400' + Cache-Control: + - max-age=0 + Content-Type: + - application/vnd.contentful.delivery.v1+json + Etag: + - '"382e4781b902b58d2edf3f10067167c7"' + X-Contentful-Request-Id: + - f1c-737770542 + Content-Length: + - '300' + Accept-Ranges: + - bytes + Via: + - 1.1 varnish + Age: + - '0' + X-Served-By: + - cache-fra1229-FRA + X-Cache: + - MISS + X-Cache-Hits: + - '0' + Vary: + - Accept-Encoding + body: + encoding: UTF-8 + string: | + { + "sys": { + "type": "Array" + }, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK" + } + }, + "id": "5ETMRzkl9KM4omyMwKAOki", + "revision": 2, + "createdAt": "2014-02-21T13:42:57.752Z", + "updatedAt": "2014-04-16T12:44:02.691Z" + }, + "fields": { + "name": { + "en-US": "London" + }, + "center": { + "en-US": { + "lat": 51.508515, + "lon": -0.12548719999995228 + } + } + } + } + ], + "nextSyncUrl": "https://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=w5ZGw6JFwqZmVcKsE8Kow4grw45QdybCr8Okw6AYwqbDksO3ehvDpUPCgcKsKXbCiAwPC8K2w4LDvsOkw6nCjhPDpcOQADElWsOoU8KGR3HCtsOAwqd6wp_Dulp8w6LDsF_CtsK7Kk05wrMvwrLClMOgG2_Dn2sGPg" + } + http_version: + recorded_at: Fri, 25 Apr 2014 13:31:18 GMT +recorded_with: VCR 2.9.0 diff --git a/spec/sync_spec.rb b/spec/sync_spec.rb index 7a0e63e..f3c290d 100644 --- a/spec/sync_spec.rb +++ b/spec/sync_spec.rb @@ -97,4 +97,62 @@ } end end + + describe 'raw_mode' do + before do + @sync = create_client(raw_mode: true).sync(initial: true) + end + + it 'should not fail' do + vcr('sync_page_short') { + expect { @sync.first_page }.not_to raise_error + } + end + + it 'should return a raw Response' do + vcr('sync_page_short') { + expect(@sync.first_page).to be_a Contentful::Response + } + end + + it 'should return JSON' do + expected = { + "sys" => {"type" => "Array"}, + "items" => [ + { + "sys" => { + "space" => { + "sys" => { + "type" => "Link", + "linkType" => "Space", + "id" => "cfexampleapi"} + }, + "type" => "Entry", + "contentType" => { + "sys" => { + "type" => "Link", + "linkType" => "ContentType", + "id" => "1t9IbcfdCk6m04uISSsaIK" + } + }, + "id" => "5ETMRzkl9KM4omyMwKAOki", + "revision" => 2, + "createdAt" => "2014-02-21T13:42:57.752Z", + "updatedAt" => "2014-04-16T12:44:02.691Z" + }, + "fields" => { + "name" => {"en-US"=>"London"}, + "center" => { + "en-US" => {"lat"=>51.508515, "lon"=>-0.12548719999995228} + } + } + } + ], + "nextSyncUrl" => "https://cdn.contentful.com/spaces/cfexampleapi/sync?sync_token=w5ZGw6JFwqZmVcKsE8Kow4grw45QdybCr8Okw6AYwqbDksO3ehvDpUPCgcKsKXbCiAwPC8K2w4LDvsOkw6nCjhPDpcOQADElWsOoU8KGR3HCtsOAwqd6wp_Dulp8w6LDsF_CtsK7Kk05wrMvwrLClMOgG2_Dn2sGPg" + } + vcr('sync_page_short') { + expect(@sync.first_page.object).to eql expected + } + end + end end