diff --git a/contentful_middleman.gemspec b/contentful_middleman.gemspec index 584ea5d..a4f6186 100644 --- a/contentful_middleman.gemspec +++ b/contentful_middleman.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| s.add_dependency("middleman-core", ["~> 3.3"]) # Additional dependencies - s.add_dependency("contentful", '~> 0.7') + s.add_dependency("contentful", '~> 0.8') s.add_dependency("contentful-webhook-listener", '~> 0.1') s.add_development_dependency 'rubygems-tasks', '~> 0.2' diff --git a/lib/contentful_middleman/import_task.rb b/lib/contentful_middleman/import_task.rb index aab80ce..4599284 100644 --- a/lib/contentful_middleman/import_task.rb +++ b/lib/contentful_middleman/import_task.rb @@ -32,7 +32,7 @@ def local_data_files content_type_name = @content_type_names.fetch(entry.content_type.id).to_s context = ContentfulMiddleman::Context.new - content_type_mapper = content_type_mapper_class.new(entries) + content_type_mapper = content_type_mapper_class.new(entries, @contentful.options) content_type_mapper.map(context, entry) LocalData::File.new(context.to_yaml, File.join(@space_name, content_type_name, entry.id)) diff --git a/lib/contentful_middleman/instance.rb b/lib/contentful_middleman/instance.rb index a6cd6f9..7f6b9d7 100644 --- a/lib/contentful_middleman/instance.rb +++ b/lib/contentful_middleman/instance.rb @@ -34,6 +34,10 @@ def content_types_ids_to_names end end + def options + @extension.options + end + private def all_entries(cda_query) @@ -67,9 +71,5 @@ def client_options client_options[:api_url] = API_PREVIEW_URL if options.use_preview_api client_options end - - def options - @extension.options - end end end diff --git a/lib/contentful_middleman/mappers/base.rb b/lib/contentful_middleman/mappers/base.rb index 7580fe0..f41fb95 100644 --- a/lib/contentful_middleman/mappers/base.rb +++ b/lib/contentful_middleman/mappers/base.rb @@ -5,8 +5,9 @@ module Mapper class Base attr_reader :entries - def initialize(entries) + def initialize(entries, options) @entries = entries + @options = options @children = {} end @@ -24,6 +25,10 @@ def map(context, entry) private + def has_multiple_locales? + @options.cda_query.fetch(:locale, nil) == '*' + end + def map_field(context, field_name, field_value) value_mapping = map_value(field_value) context.set(field_name, value_mapping) @@ -56,7 +61,10 @@ def map_asset(asset) def map_entry_full(entry, context) context.id = entry.id - entry.fields.each {|k, v| map_field context, k, v} + + fields = has_multiple_locales? ? entry.fields_with_locales : entry.fields + + fields.each {|k, v| map_field context, k, v} end def map_entry(entry) diff --git a/spec/contentful_middleman/helpers_spec.rb b/spec/contentful_middleman/helpers_spec.rb index 5f30b16..e56f862 100644 --- a/spec/contentful_middleman/helpers_spec.rb +++ b/spec/contentful_middleman/helpers_spec.rb @@ -8,6 +8,21 @@ class InstanceDouble end describe ContentfulMiddleman::Helpers do + let(:entry) do + { + value_field: { + 'es' => 'foo', + 'en-US' => 'bar' + }, + array_field: [ + { + 'es' => 'foobar', + 'en-US' => 'baz' + } + ] + } + end + subject { HelpersMock.new } before(:each) do @@ -28,5 +43,57 @@ class InstanceDouble expect(subject.contentful_instances.size).to eq(2) end end + + describe 'localization helpers' do + describe '#localize_value' do + it 'returns value if not a hash independently of locale' do + expect(subject.localize_value('foo', 'es')).to eq('foo') + end + + describe 'value is a hash' do + it 'returns fallback_locale value if locale not found' do + expect(subject.localize_value({'en-US' => 'foo'}, 'es')).to eq('foo') + expect(subject.localize_value({'de-DE' => 'bar'}, 'es', 'de-DE')).to eq('bar') + end + + it 'returns localized value if locale found' do + expect(subject.localize_value({'es' => 'foobar'}, 'es')).to eq('foobar') + end + + it 'fails if locale or fallback_locale not found' do + expect { subject.localize_value({'de-DE' => 'baz'}, 'es') }.to raise_error KeyError + end + end + end + + describe '#localize_array' do + it 'calls #localize_value for every element in the array' do + expect(subject).to receive(:localize_value).with({'es' => 'foo'}, 'es', 'en-US') + + subject.localize_array([{'es' => 'foo'}], 'es') + end + end + + describe '#localize' do + it 'calls #localize_value for a value field' do + expect(subject).to receive(:localize_value).with({'es' => 'foo', 'en-US' => 'bar'}, 'es', 'en-US').and_call_original + + expect(subject.localize(entry, :value_field, 'es')).to eq('foo') + end + + it 'calls #localize_array for an array field' do + expect(subject).to receive(:localize_array).with([{'es' => 'foobar', 'en-US' => 'baz'}], 'es', 'en-US').and_call_original + + expect(subject.localize(entry, :array_field, 'es')).to eq(['foobar']) + end + end + + it '#localize_entry' do + expect(subject.localize_entry(entry, 'es')).to eq({ + value_field: 'foo', + array_field: ['foobar'] + }) + end + end end end diff --git a/spec/contentful_middleman/instance_spec.rb b/spec/contentful_middleman/instance_spec.rb index 0152707..3abba99 100644 --- a/spec/contentful_middleman/instance_spec.rb +++ b/spec/contentful_middleman/instance_spec.rb @@ -1,26 +1,5 @@ require 'spec_helper' -class OptionsDouble - DEFAULT_OPTIONS = { - space: {id: 'cfexampleapi', name: 'cats'}, - access_token: 'b4c0n73n7fu1', - cda_query: {}, - content_types: {}, - use_preview_api: false, - all_entries: false, - rebuild_on_webhook: false, - webhook_timeout: 300 - } - - def initialize(options = DEFAULT_OPTIONS) - options.each do |field, value| - define_singleton_method(field.to_sym) do - value - end - end - end -end - class ExtensionDouble attr_reader :options def initialize(options = OptionsDouble.new) diff --git a/spec/contentful_middleman/mappers/base_spec.rb b/spec/contentful_middleman/mappers/base_spec.rb index e635992..0763ea2 100644 --- a/spec/contentful_middleman/mappers/base_spec.rb +++ b/spec/contentful_middleman/mappers/base_spec.rb @@ -12,27 +12,71 @@ client.entries } end - subject { described_class.new entries } + + let(:entries_localized) do + vcr('mappers/entries_localized') { + client = Contentful::Client.new( + access_token: 'b4c0n73n7fu1', + space: 'cfexampleapi', + dynamic_entries: :auto + ) + + client.entries(locale: '*', include: 1) + } + end + + let(:options) { OptionsDouble.new } + subject { described_class.new entries, options } describe 'instance methods' do let(:context) { ContentfulMiddleman::Context.new } - it '#map' do - expect(context.hashize).to eq({}) + describe '#map' do + it 'maps entries without multiple locales' do + expect(context.hashize).to eq({}) + + expected = { + :id=>"6KntaYXaHSyIw8M6eo26OK", + :name=>"Doge", + :image=> { + :title=>"Doge", + :url=> "//images.contentful.com/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg" + }, + :description=>"such json\nwow" + } + + subject.map(context, entries.first) + + expect(context.hashize).to eq(expected) + end + + it 'maps entries with multiple locales' do + subject = described_class.new entries, OptionsDouble.new(cda_query: {locale: '*'}) + expect(context.hashize).to eq({}) - expected = { - :id=>"6KntaYXaHSyIw8M6eo26OK", - :name=>"Doge", - :image=> { - :title=>"Doge", - :url=> "//images.contentful.com/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg" - }, - :description=>"such json\nwow" - } + expected = { + :id=>"6KntaYXaHSyIw8M6eo26OK", + :name=> { + :'en-US'=>"Doge" + }, + :image=>{ + :'en-US'=>{ + "sys"=>{ + "type"=>"Link", + "linkType"=>"Asset", + "id"=>"1x0xpXu4pSGS4OukSyWGUK" + } + } + }, + :description=>{ + :'en-US'=>"such json\nwow" + } + } - subject.map(context, entries.first) + subject.map(context, entries_localized.first) - expect(context.hashize).to eq(expected) + expect(context.hashize).to eq(expected) + end end end diff --git a/spec/fixtures/vcr_fixtures/mappers/entries.yml b/spec/fixtures/vcr_fixtures/mappers/entries.yml index 74e3772..c63dfa8 100644 --- a/spec/fixtures/vcr_fixtures/mappers/entries.yml +++ b/spec/fixtures/vcr_fixtures/mappers/entries.yml @@ -13,8 +13,6 @@ http_interactions: - Bearer b4c0n73n7fu1 Content-Type: - application/vnd.contentful.delivery.v1+json - Accept-Encoding: - - gzip Connection: - close Host: @@ -36,20 +34,20 @@ http_interactions: - '86400' Cache-Control: - max-age=0 - Content-Encoding: - - gzip Content-Type: - application/vnd.contentful.delivery.v1+json + Etag: + - '"a74bc0b64b4ed0d8864f88c464ca92ec"' Server: - nginx X-Contentful-Request-Id: - - 90a-2086569206 + - c40-589309641 Content-Length: - - '914' + - '5619' Accept-Ranges: - bytes Date: - - Mon, 30 Nov 2015 14:45:42 GMT + - Wed, 02 Dec 2015 18:20:27 GMT Via: - 1.1 varnish Age: @@ -57,7 +55,7 @@ http_interactions: Connection: - close X-Served-By: - - cache-jfk1028-JFK + - cache-jfk1031-JFK X-Cache: - MISS X-Cache-Hits: @@ -65,31 +63,262 @@ http_interactions: Vary: - Accept-Encoding body: - encoding: ASCII-8BIT - string: !binary |- - H4sIAAAAAAAAA91YS3ObMBC+51e4nGuGV7DhljiPMk3b6dg9NJ0cZCM7Gp4B - OY2b8X+vEAgkLGKSTDtjc7H1Wq1W3+5+q+eTwUDJN7niDp7JX9LAmxSSlnKW - ZWCjkL7tx2IOTjAISf8pbeUBSklDo40QRQiTlq5pZQfCMCok/qISS7lk3hLB - 0G/6+TG6cwwiuvPX4reQzD4F+UU/HRf6ma4z+ITFkQw+rFEGi3U4W8NaGD1M - +TG9hL0nMMYwk+2+kIyw/W+SBcAoiXvqUKlwx3SpTz5BeFPLEK6FKpmnYFFY - SNCcv7zaYLViKA4Epeh1xcGsuuQplcjblEworb1YwicQpSEEKSpgwL6tzJY1 - aiYJsV+MqfxGbCVSx443Xyz9SWBHmrX2ptMceJ/5eRl8RHlhSIImbvkigwBD - /6xAmWJoujXUjKGhz3TTtQzXNFVNc255OevU77GgOkmNCcVHeRqCzVUB1Bpx - dFY1pzeWuxDbjfHeWBY8ICTIC9EfCvQlCHMO6d0oA42zHB/IbDOwHvxL5ABv - 7H3/cQ1+Xq+sb28AmTnU7KFhznTH1WzXcFRnZL8IMvmCXZDBfJGhlMYLAucv - MPn9oXH6o4JgR7AtncPn7CBgmvnIRdeEXq5CvaGvr7yoKIrAqpV4mIre7hCX - eXqoICjYGbWFmH2W5xA3EZnF491scpGsOFyJqDsHWbAPdUy344sRPmcZkvC4 - rGO8kHVK/x7NDMO1bFc3VcsZ7wsIDslUM91yTcPVdXVsjm7ZzZX3dgh5pReB - Kn06RAHMBT5Rc5ub3SGG95JqCq7wDi9i7JNnSeSS2WbTTTRPwr2MRuBYFSNK - wqRFDVkcmOwOtfZ7x+lkhEui3hzm+CpDMPblF3BOxgeyCd1h5x23wLPMyxhn - tJQovy4OXlp5jjJ875PSQ5oTzqWj7AQXhPSJ6153gp4qhmjZjXIyNAjhslWP - MA09Qo9X7QLjdUoKdiF0AczD/nUOc9PH7gOQoX97gJ5WPtS0O+HptZTO1YmV - p0AVFVSblN2u7A6+/iNFMuedb0y7hjo+NfqlXdMlmdcaqWPbPMC02yrnGreX - xP6D4dJHTRD+e8SSEKc97Odmz4NQq7ioHz7KzF08kMjTTedjw6d1BJp3MfkL - y/EWGvfC6cVSw+xfaliqbpIQxi1oP3CR2qQsNU5dXXMNWx3rpDZhbw/0tyg4 - 7k62J38BK6i++/MVAAA= + encoding: UTF-8 + string: | + { + "sys": { + "type": "Array" + }, + "total": 5, + "skip": 0, + "limit": 1000, + "items": [ + { + "fields": [ + { + "name": "Name", + "id": "name", + "type": "Text", + "required": true + }, + { + "name": "Center", + "id": "center", + "type": "Location", + "required": true + } + ], + "name": "City", + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK", + "revision": 1, + "createdAt": "2014-02-21T13:42:33.009Z", + "updatedAt": "2014-02-21T13:42:33.009Z" + }, + "displayField": "name" + }, + { + "fields": [ + { + "id": "name", + "name": "Name", + "type": "Text", + "required": true, + "localized": false + } + ], + "name": "Cat", + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "ContentType", + "id": "63k4qdEi9aI8IQUGaYGg4O", + "revision": 1, + "createdAt": "2013-06-23T19:06:29.976Z", + "updatedAt": "2013-06-23T19:06:29.976Z" + }, + "description": "Meow!", + "displayField": "name" + }, + { + "fields": [ + { + "id": "name", + "name": "Name", + "type": "Text", + "required": true, + "localized": false + }, + { + "id": "description", + "name": "Description", + "type": "Text", + "required": false, + "localized": false + }, + { + "id": "image", + "name": "Image", + "required": false, + "localized": false, + "type": "Link", + "linkType": "Asset" + } + ], + "name": "Dog", + "description": "Bark!", + "displayField": "name", + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "ContentType", + "id": "dog", + "revision": 2, + "createdAt": "2013-06-27T22:46:13.498Z", + "updatedAt": "2013-09-02T14:32:11.837Z" + } + }, + { + "fields": [ + { + "id": "name", + "name": "Name", + "type": "Text", + "required": true, + "localized": true + }, + { + "id": "likes", + "name": "Likes", + "type": "Array", + "required": false, + "localized": false, + "items": { + "type": "Symbol" + } + }, + { + "id": "color", + "name": "Color", + "type": "Symbol", + "required": false, + "localized": false + }, + { + "id": "bestFriend", + "name": "Best Friend", + "type": "Link", + "required": false, + "localized": false, + "linkType": "Entry" + }, + { + "id": "birthday", + "name": "Birthday", + "type": "Date", + "required": false, + "localized": false + }, + { + "id": "lifes", + "name": "Lifes left", + "type": "Integer", + "required": false, + "localized": false, + "disabled": true + }, + { + "id": "lives", + "name": "Lives left", + "type": "Integer", + "required": false, + "localized": false + }, + { + "id": "image", + "name": "Image", + "required": false, + "localized": false, + "type": "Link", + "linkType": "Asset" + } + ], + "name": "Cat", + "displayField": "name", + "description": "Meow.", + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "ContentType", + "id": "cat", + "revision": 2, + "createdAt": "2013-06-27T22:46:12.852Z", + "updatedAt": "2013-09-02T13:14:47.863Z" + } + }, + { + "fields": [ + { + "id": "name", + "name": "Name", + "type": "Text", + "required": true, + "localized": false + }, + { + "id": "description", + "name": "Description", + "type": "Text", + "required": false, + "localized": false + }, + { + "id": "likes", + "name": "Likes", + "type": "Array", + "required": false, + "localized": false, + "items": { + "type": "Symbol" + } + }, + { + "id": "image", + "name": "Image", + "required": false, + "localized": false, + "type": "Array", + "items": { + "type": "Link", + "linkType": "Asset" + }, + "disabled": true + } + ], + "name": "Human", + "displayField": "name", + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "ContentType", + "id": "human", + "revision": 3, + "createdAt": "2013-06-27T22:46:14.133Z", + "updatedAt": "2013-09-02T15:10:26.818Z" + } + } + ] + } http_version: - recorded_at: Mon, 30 Nov 2015 14:45:42 GMT + recorded_at: Wed, 02 Dec 2015 18:20:27 GMT - request: method: get uri: https://cdn.contentful.com/spaces/cfexampleapi/entries @@ -103,8 +332,6 @@ http_interactions: - Bearer b4c0n73n7fu1 Content-Type: - application/vnd.contentful.delivery.v1+json - Accept-Encoding: - - gzip Connection: - close Host: @@ -126,20 +353,20 @@ http_interactions: - '86400' Cache-Control: - max-age=0 - Content-Encoding: - - gzip Content-Type: - application/vnd.contentful.delivery.v1+json + Etag: + - '"474a1d8a1e34ebf8e98f420724e24f17"' Server: - nginx X-Contentful-Request-Id: - - c40-587974619 + - c40-589333551 Content-Length: - - '2170' + - '12570' Accept-Ranges: - bytes Date: - - Mon, 30 Nov 2015 14:45:43 GMT + - Wed, 02 Dec 2015 18:20:28 GMT Via: - 1.1 varnish Age: @@ -147,7 +374,7 @@ http_interactions: Connection: - close X-Served-By: - - cache-jfk1025-JFK + - cache-jfk1030-JFK X-Cache: - MISS X-Cache-Hits: @@ -155,57 +382,532 @@ http_interactions: Vary: - Accept-Encoding body: - encoding: ASCII-8BIT - string: !binary |- - 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 - /wFjCUFyGjEAAA== + encoding: UTF-8 + string: | + { + "sys": { + "type": "Array" + }, + "total": 11, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "dog" + } + }, + "id": "6KntaYXaHSyIw8M6eo26OK", + "revision": 2, + "createdAt": "2013-11-06T09:45:27.475Z", + "updatedAt": "2013-11-18T09:13:37.808Z", + "locale": "en-US" + }, + "fields": { + "name": "Doge", + "image": { + "sys": { + "type": "Link", + "linkType": "Asset", + "id": "1x0xpXu4pSGS4OukSyWGUK" + } + }, + "description": "such json\nwow" + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK" + } + }, + "id": "4MU1s3potiUEM2G4okYOqw", + "revision": 1, + "createdAt": "2014-02-21T13:42:45.926Z", + "updatedAt": "2014-02-21T13:42:45.926Z", + "locale": "en-US" + }, + "fields": { + "name": "Berlin", + "center": { + "lat": 52.52000659999999, + "lon": 13.404953999999975 + } + } + }, + { + "fields": { + "name": "Happy Cat", + "bestFriend": { + "sys": { + "type": "Link", + "linkType": "Entry", + "id": "nyancat" + } + }, + "likes": [ + "cheezburger" + ], + "color": "gray", + "birthday": "2003-10-28T23:00:00+00:00", + "lives": 1, + "image": { + "sys": { + "type": "Link", + "linkType": "Asset", + "id": "happycat" + } + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "cat" + } + }, + "id": "happycat", + "revision": 8, + "createdAt": "2013-06-27T22:46:20.171Z", + "updatedAt": "2013-11-18T15:58:02.018Z", + "locale": "en-US" + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "63k4qdEi9aI8IQUGaYGg4O" + } + }, + "id": "CVebBDcQsSsu6yKKIayy", + "revision": 1, + "createdAt": "2013-06-23T19:06:46.224Z", + "updatedAt": "2013-06-23T19:06:46.224Z", + "locale": "en-US" + }, + "fields": { + "name": "Nyancat" + } + }, + { + "fields": { + "name": "Garfield", + "likes": [ + "lasagna" + ], + "color": "orange", + "lifes": null, + "lives": 9, + "birthday": "1979-06-18T23:00:00+00:00" + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "cat" + } + }, + "id": "garfield", + "revision": 2, + "createdAt": "2013-06-27T22:46:20.821Z", + "updatedAt": "2013-08-27T10:09:07.929Z", + "locale": "en-US" + } + }, + { + "fields": { + "name": "Nyan Cat", + "likes": [ + "rainbows", + "fish" + ], + "color": "rainbow", + "bestFriend": { + "sys": { + "type": "Link", + "linkType": "Entry", + "id": "happycat" + } + }, + "birthday": "2011-04-04T22:00:00+00:00", + "lives": 1337, + "image": { + "sys": { + "type": "Link", + "linkType": "Asset", + "id": "nyancat" + } + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "cat" + } + }, + "id": "nyancat", + "revision": 5, + "createdAt": "2013-06-27T22:46:19.513Z", + "updatedAt": "2013-09-04T09:19:39.027Z", + "locale": "en-US" + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK" + } + }, + "id": "7qVBlCjpWE86Oseo40gAEY", + "revision": 2, + "createdAt": "2014-02-21T13:43:38.258Z", + "updatedAt": "2014-04-15T08:22:22.010Z", + "locale": "en-US" + }, + "fields": { + "name": "San Francisco", + "center": { + "lat": 37.7749295, + "lon": -122.41941550000001 + } + } + }, + { + "fields": { + "name": "Finn", + "description": "Fearless adventurer! Defender of pancakes.", + "likes": [ + "adventure" + ] + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "human" + } + }, + "id": "finn", + "revision": 6, + "createdAt": "2013-06-27T22:46:21.450Z", + "updatedAt": "2013-09-09T16:15:01.297Z", + "locale": "en-US" + } + }, + { + "fields": { + "name": "Jake", + "description": "Bacon pancakes, makin' bacon pancakes!", + "image": { + "sys": { + "type": "Link", + "linkType": "Asset", + "id": "jake" + } + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "dog" + } + }, + "id": "jake", + "revision": 5, + "createdAt": "2013-06-27T22:46:22.096Z", + "updatedAt": "2013-12-18T13:10:26.212Z", + "locale": "en-US" + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK" + } + }, + "id": "ge1xHyH3QOWucKWCCAgIG", + "revision": 1, + "createdAt": "2014-02-21T13:43:23.210Z", + "updatedAt": "2014-02-21T13:43:23.210Z", + "locale": "en-US" + }, + "fields": { + "name": "Paris", + "center": { + "lat": 48.856614, + "lon": 2.3522219000000177 + } + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK" + } + }, + "id": "5ETMRzkl9KM4omyMwKAOki", + "revision": 3, + "createdAt": "2014-02-21T13:42:57.752Z", + "updatedAt": "2014-08-23T14:42:35.207Z", + "locale": "en-US" + }, + "fields": { + "name": "London", + "center": { + "lat": 51.508515, + "lon": -0.12548719999995228 + } + } + } + ], + "includes": { + "Asset": [ + { + "fields": { + "title": "Jake", + "file": { + "fileName": "jake.png", + "contentType": "image/png", + "details": { + "image": { + "width": 100, + "height": 161 + }, + "size": 20480 + }, + "url": "//images.contentful.com/cfexampleapi/4hlteQAXS8iS0YCMU6QMWg/2a4d826144f014109364ccf5c891d2dd/jake.png" + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Asset", + "id": "jake", + "revision": 2, + "createdAt": "2013-09-02T14:56:34.260Z", + "updatedAt": "2013-09-02T15:22:39.466Z", + "locale": "en-US" + } + }, + { + "fields": { + "title": "Nyan Cat", + "file": { + "fileName": "Nyan_cat_250px_frame.png", + "contentType": "image/png", + "details": { + "image": { + "width": 250, + "height": 250 + }, + "size": 12273 + }, + "url": "//images.contentful.com/cfexampleapi/4gp6taAwW4CmSgumq2ekUm/9da0cd1936871b8d72343e895a00d611/Nyan_cat_250px_frame.png" + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Asset", + "id": "nyancat", + "revision": 1, + "createdAt": "2013-09-02T14:56:34.240Z", + "updatedAt": "2013-09-02T14:56:34.240Z", + "locale": "en-US" + } + }, + { + "fields": { + "file": { + "fileName": "happycatw.jpg", + "contentType": "image/jpeg", + "details": { + "image": { + "width": 273, + "height": 397 + }, + "size": 59939 + }, + "url": "//images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg" + }, + "title": "Happy Cat" + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Asset", + "id": "happycat", + "revision": 2, + "createdAt": "2013-09-02T14:56:34.267Z", + "updatedAt": "2013-09-02T15:11:24.361Z", + "locale": "en-US" + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Asset", + "id": "1x0xpXu4pSGS4OukSyWGUK", + "revision": 6, + "createdAt": "2013-11-06T09:45:10.000Z", + "updatedAt": "2013-12-18T13:27:14.917Z", + "locale": "en-US" + }, + "fields": { + "title": "Doge", + "file": { + "fileName": "doge.jpg", + "contentType": "image/jpeg", + "details": { + "image": { + "width": 5800, + "height": 4350 + }, + "size": 522943 + }, + "url": "//images.contentful.com/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg" + }, + "description": "nice picture" + } + } + ] + } + } http_version: - recorded_at: Mon, 30 Nov 2015 14:45:43 GMT + recorded_at: Wed, 02 Dec 2015 18:20:28 GMT recorded_with: VCR 2.9.3 diff --git a/spec/fixtures/vcr_fixtures/mappers/entries_localized.yml b/spec/fixtures/vcr_fixtures/mappers/entries_localized.yml new file mode 100644 index 0000000..ed4fcba --- /dev/null +++ b/spec/fixtures/vcr_fixtures/mappers/entries_localized.yml @@ -0,0 +1,996 @@ +--- +http_interactions: +- request: + method: get + uri: https://cdn.contentful.com/spaces/cfexampleapi/content_types?limit=1000 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - RubyContentfulGem/0.7.0 + Authorization: + - Bearer b4c0n73n7fu1 + Content-Type: + - application/vnd.contentful.delivery.v1+json + Connection: + - close + Host: + - cdn.contentful.com + response: + status: + code: 200 + message: OK + headers: + 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,X-Contentful-Skip-Transformation + Access-Control-Allow-Methods: + - GET,HEAD,OPTIONS + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Etag + Access-Control-Max-Age: + - '86400' + Cache-Control: + - max-age=0 + Content-Type: + - application/vnd.contentful.delivery.v1+json + Etag: + - '"a74bc0b64b4ed0d8864f88c464ca92ec"' + Server: + - nginx + X-Contentful-Request-Id: + - 405-1389484612 + Content-Length: + - '5619' + Accept-Ranges: + - bytes + Date: + - Wed, 02 Dec 2015 18:20:29 GMT + Via: + - 1.1 varnish + Age: + - '0' + Connection: + - close + X-Served-By: + - cache-iad2122-IAD + X-Cache: + - MISS + X-Cache-Hits: + - '0' + Vary: + - Accept-Encoding + body: + encoding: UTF-8 + string: | + { + "sys": { + "type": "Array" + }, + "total": 5, + "skip": 0, + "limit": 1000, + "items": [ + { + "fields": [ + { + "name": "Name", + "id": "name", + "type": "Text", + "required": true + }, + { + "name": "Center", + "id": "center", + "type": "Location", + "required": true + } + ], + "name": "City", + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK", + "revision": 1, + "createdAt": "2014-02-21T13:42:33.009Z", + "updatedAt": "2014-02-21T13:42:33.009Z" + }, + "displayField": "name" + }, + { + "fields": [ + { + "id": "name", + "name": "Name", + "type": "Text", + "required": true, + "localized": false + } + ], + "name": "Cat", + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "ContentType", + "id": "63k4qdEi9aI8IQUGaYGg4O", + "revision": 1, + "createdAt": "2013-06-23T19:06:29.976Z", + "updatedAt": "2013-06-23T19:06:29.976Z" + }, + "description": "Meow!", + "displayField": "name" + }, + { + "fields": [ + { + "id": "name", + "name": "Name", + "type": "Text", + "required": true, + "localized": false + }, + { + "id": "description", + "name": "Description", + "type": "Text", + "required": false, + "localized": false + }, + { + "id": "image", + "name": "Image", + "required": false, + "localized": false, + "type": "Link", + "linkType": "Asset" + } + ], + "name": "Dog", + "description": "Bark!", + "displayField": "name", + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "ContentType", + "id": "dog", + "revision": 2, + "createdAt": "2013-06-27T22:46:13.498Z", + "updatedAt": "2013-09-02T14:32:11.837Z" + } + }, + { + "fields": [ + { + "id": "name", + "name": "Name", + "type": "Text", + "required": true, + "localized": true + }, + { + "id": "likes", + "name": "Likes", + "type": "Array", + "required": false, + "localized": false, + "items": { + "type": "Symbol" + } + }, + { + "id": "color", + "name": "Color", + "type": "Symbol", + "required": false, + "localized": false + }, + { + "id": "bestFriend", + "name": "Best Friend", + "type": "Link", + "required": false, + "localized": false, + "linkType": "Entry" + }, + { + "id": "birthday", + "name": "Birthday", + "type": "Date", + "required": false, + "localized": false + }, + { + "id": "lifes", + "name": "Lifes left", + "type": "Integer", + "required": false, + "localized": false, + "disabled": true + }, + { + "id": "lives", + "name": "Lives left", + "type": "Integer", + "required": false, + "localized": false + }, + { + "id": "image", + "name": "Image", + "required": false, + "localized": false, + "type": "Link", + "linkType": "Asset" + } + ], + "name": "Cat", + "displayField": "name", + "description": "Meow.", + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "ContentType", + "id": "cat", + "revision": 2, + "createdAt": "2013-06-27T22:46:12.852Z", + "updatedAt": "2013-09-02T13:14:47.863Z" + } + }, + { + "fields": [ + { + "id": "name", + "name": "Name", + "type": "Text", + "required": true, + "localized": false + }, + { + "id": "description", + "name": "Description", + "type": "Text", + "required": false, + "localized": false + }, + { + "id": "likes", + "name": "Likes", + "type": "Array", + "required": false, + "localized": false, + "items": { + "type": "Symbol" + } + }, + { + "id": "image", + "name": "Image", + "required": false, + "localized": false, + "type": "Array", + "items": { + "type": "Link", + "linkType": "Asset" + }, + "disabled": true + } + ], + "name": "Human", + "displayField": "name", + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "ContentType", + "id": "human", + "revision": 3, + "createdAt": "2013-06-27T22:46:14.133Z", + "updatedAt": "2013-09-02T15:10:26.818Z" + } + } + ] + } + http_version: + recorded_at: Wed, 02 Dec 2015 18:20:29 GMT +- request: + method: get + uri: https://cdn.contentful.com/spaces/cfexampleapi/entries?include=1&locale=* + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - RubyContentfulGem/0.7.0 + Authorization: + - Bearer b4c0n73n7fu1 + Content-Type: + - application/vnd.contentful.delivery.v1+json + Connection: + - close + Host: + - cdn.contentful.com + response: + status: + code: 200 + message: OK + headers: + 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,X-Contentful-Skip-Transformation + Access-Control-Allow-Methods: + - GET,HEAD,OPTIONS + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Etag + Access-Control-Max-Age: + - '86400' + Cache-Control: + - max-age=0 + Content-Type: + - application/vnd.contentful.delivery.v1+json + Etag: + - '"eac96ae01d702c27f00720b82d4f85f6"' + Server: + - nginx + X-Contentful-Request-Id: + - c40-589333571 + Content-Length: + - '13968' + Accept-Ranges: + - bytes + Date: + - Wed, 02 Dec 2015 18:20:29 GMT + Via: + - 1.1 varnish + Age: + - '0' + Connection: + - close + X-Served-By: + - cache-iad2145-IAD + X-Cache: + - MISS + X-Cache-Hits: + - '0' + Vary: + - Accept-Encoding + body: + encoding: UTF-8 + string: | + { + "sys": { + "type": "Array" + }, + "total": 11, + "skip": 0, + "limit": 100, + "items": [ + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "dog" + } + }, + "id": "6KntaYXaHSyIw8M6eo26OK", + "revision": 2, + "createdAt": "2013-11-06T09:45:27.475Z", + "updatedAt": "2013-11-18T09:13:37.808Z" + }, + "fields": { + "name": { + "en-US": "Doge" + }, + "image": { + "en-US": { + "sys": { + "type": "Link", + "linkType": "Asset", + "id": "1x0xpXu4pSGS4OukSyWGUK" + } + } + }, + "description": { + "en-US": "such json\nwow" + } + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK" + } + }, + "id": "4MU1s3potiUEM2G4okYOqw", + "revision": 1, + "createdAt": "2014-02-21T13:42:45.926Z", + "updatedAt": "2014-02-21T13:42:45.926Z" + }, + "fields": { + "name": { + "en-US": "Berlin" + }, + "center": { + "en-US": { + "lat": 52.52000659999999, + "lon": 13.404953999999975 + } + } + } + }, + { + "fields": { + "name": { + "en-US": "Happy Cat", + "tlh": "Quch vIghro'" + }, + "bestFriend": { + "en-US": { + "sys": { + "type": "Link", + "linkType": "Entry", + "id": "nyancat" + } + } + }, + "likes": { + "en-US": [ + "cheezburger" + ] + }, + "color": { + "en-US": "gray" + }, + "birthday": { + "en-US": "2003-10-28T23:00:00+00:00" + }, + "lives": { + "en-US": 1 + }, + "image": { + "en-US": { + "sys": { + "type": "Link", + "linkType": "Asset", + "id": "happycat" + } + } + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "cat" + } + }, + "id": "happycat", + "revision": 8, + "createdAt": "2013-06-27T22:46:20.171Z", + "updatedAt": "2013-11-18T15:58:02.018Z" + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "63k4qdEi9aI8IQUGaYGg4O" + } + }, + "id": "CVebBDcQsSsu6yKKIayy", + "revision": 1, + "createdAt": "2013-06-23T19:06:46.224Z", + "updatedAt": "2013-06-23T19:06:46.224Z" + }, + "fields": { + "name": { + "en-US": "Nyancat" + } + } + }, + { + "fields": { + "name": { + "en-US": "Garfield", + "tlh": "Garfield" + }, + "likes": { + "en-US": [ + "lasagna" + ] + }, + "color": { + "en-US": "orange" + }, + "lifes": { + "en-US": null + }, + "lives": { + "en-US": 9 + }, + "birthday": { + "en-US": "1979-06-18T23:00:00+00:00" + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "cat" + } + }, + "id": "garfield", + "revision": 2, + "createdAt": "2013-06-27T22:46:20.821Z", + "updatedAt": "2013-08-27T10:09:07.929Z" + } + }, + { + "fields": { + "name": { + "en-US": "Nyan Cat", + "tlh": "Nyan vIghro'" + }, + "likes": { + "en-US": [ + "rainbows", + "fish" + ] + }, + "color": { + "en-US": "rainbow" + }, + "bestFriend": { + "en-US": { + "sys": { + "type": "Link", + "linkType": "Entry", + "id": "happycat" + } + } + }, + "birthday": { + "en-US": "2011-04-04T22:00:00+00:00" + }, + "lives": { + "en-US": 1337 + }, + "image": { + "en-US": { + "sys": { + "type": "Link", + "linkType": "Asset", + "id": "nyancat" + } + } + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "cat" + } + }, + "id": "nyancat", + "revision": 5, + "createdAt": "2013-06-27T22:46:19.513Z", + "updatedAt": "2013-09-04T09:19:39.027Z" + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK" + } + }, + "id": "7qVBlCjpWE86Oseo40gAEY", + "revision": 2, + "createdAt": "2014-02-21T13:43:38.258Z", + "updatedAt": "2014-04-15T08:22:22.010Z" + }, + "fields": { + "name": { + "en-US": "San Francisco" + }, + "center": { + "en-US": { + "lat": 37.7749295, + "lon": -122.41941550000001 + } + } + } + }, + { + "fields": { + "name": { + "en-US": "Finn" + }, + "description": { + "en-US": "Fearless adventurer! Defender of pancakes." + }, + "likes": { + "en-US": [ + "adventure" + ] + }, + "image": {} + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "human" + } + }, + "id": "finn", + "revision": 6, + "createdAt": "2013-06-27T22:46:21.450Z", + "updatedAt": "2013-09-09T16:15:01.297Z" + } + }, + { + "fields": { + "name": { + "en-US": "Jake" + }, + "description": { + "en-US": "Bacon pancakes, makin' bacon pancakes!" + }, + "image": { + "en-US": { + "sys": { + "type": "Link", + "linkType": "Asset", + "id": "jake" + } + } + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "dog" + } + }, + "id": "jake", + "revision": 5, + "createdAt": "2013-06-27T22:46:22.096Z", + "updatedAt": "2013-12-18T13:10:26.212Z" + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK" + } + }, + "id": "ge1xHyH3QOWucKWCCAgIG", + "revision": 1, + "createdAt": "2014-02-21T13:43:23.210Z", + "updatedAt": "2014-02-21T13:43:23.210Z" + }, + "fields": { + "name": { + "en-US": "Paris" + }, + "center": { + "en-US": { + "lat": 48.856614, + "lon": 2.3522219000000177 + } + } + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Entry", + "contentType": { + "sys": { + "type": "Link", + "linkType": "ContentType", + "id": "1t9IbcfdCk6m04uISSsaIK" + } + }, + "id": "5ETMRzkl9KM4omyMwKAOki", + "revision": 3, + "createdAt": "2014-02-21T13:42:57.752Z", + "updatedAt": "2014-08-23T14:42:35.207Z" + }, + "fields": { + "name": { + "en-US": "London" + }, + "center": { + "en-US": { + "lat": 51.508515, + "lon": -0.12548719999995228 + } + } + } + } + ], + "includes": { + "Asset": [ + { + "fields": { + "title": { + "en-US": "Jake" + }, + "file": { + "en-US": { + "fileName": "jake.png", + "contentType": "image/png", + "details": { + "image": { + "width": 100, + "height": 161 + }, + "size": 20480 + }, + "url": "//images.contentful.com/cfexampleapi/4hlteQAXS8iS0YCMU6QMWg/2a4d826144f014109364ccf5c891d2dd/jake.png" + } + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Asset", + "id": "jake", + "revision": 2, + "createdAt": "2013-09-02T14:56:34.260Z", + "updatedAt": "2013-09-02T15:22:39.466Z" + } + }, + { + "fields": { + "title": { + "en-US": "Nyan Cat" + }, + "file": { + "en-US": { + "fileName": "Nyan_cat_250px_frame.png", + "contentType": "image/png", + "details": { + "image": { + "width": 250, + "height": 250 + }, + "size": 12273 + }, + "url": "//images.contentful.com/cfexampleapi/4gp6taAwW4CmSgumq2ekUm/9da0cd1936871b8d72343e895a00d611/Nyan_cat_250px_frame.png" + } + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Asset", + "id": "nyancat", + "revision": 1, + "createdAt": "2013-09-02T14:56:34.240Z", + "updatedAt": "2013-09-02T14:56:34.240Z" + } + }, + { + "fields": { + "file": { + "en-US": { + "fileName": "happycatw.jpg", + "contentType": "image/jpeg", + "details": { + "image": { + "width": 273, + "height": 397 + }, + "size": 59939 + }, + "url": "//images.contentful.com/cfexampleapi/3MZPnjZTIskAIIkuuosCss/382a48dfa2cb16c47aa2c72f7b23bf09/happycatw.jpg" + } + }, + "title": { + "en-US": "Happy Cat" + } + }, + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Asset", + "id": "happycat", + "revision": 2, + "createdAt": "2013-09-02T14:56:34.267Z", + "updatedAt": "2013-09-02T15:11:24.361Z" + } + }, + { + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "type": "Asset", + "id": "1x0xpXu4pSGS4OukSyWGUK", + "revision": 6, + "createdAt": "2013-11-06T09:45:10.000Z", + "updatedAt": "2013-12-18T13:27:14.917Z" + }, + "fields": { + "title": { + "en-US": "Doge" + }, + "file": { + "en-US": { + "fileName": "doge.jpg", + "contentType": "image/jpeg", + "details": { + "image": { + "width": 5800, + "height": 4350 + }, + "size": 522943 + }, + "url": "//images.contentful.com/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg" + } + }, + "description": { + "en-US": "nice picture" + } + } + } + ] + } + } + http_version: + recorded_at: Wed, 02 Dec 2015 18:20:29 GMT +recorded_with: VCR 2.9.3 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 87d343d..cb170ea 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -37,3 +37,24 @@ class RequestDouble class ResponseDouble attr_accessor :body, :status, :content_type end + +class OptionsDouble + DEFAULT_OPTIONS = { + space: {id: 'cfexampleapi', name: 'cats'}, + access_token: 'b4c0n73n7fu1', + cda_query: {}, + content_types: {}, + use_preview_api: false, + all_entries: false, + rebuild_on_webhook: false, + webhook_timeout: 300 + } + + def initialize(options = DEFAULT_OPTIONS) + options.each do |field, value| + define_singleton_method(field.to_sym) do + value + end + end + end +end