contentful 0.8.0 → 0.9.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.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rubocop.yml +25 -0
- data/.rubocop_todo.yml +35 -0
- data/.travis.yml +5 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +12 -0
- data/Guardfile +18 -36
- data/README.md +34 -0
- data/Rakefile +5 -0
- data/contentful.gemspec +3 -0
- data/lib/contentful.rb +1 -0
- data/lib/contentful/array.rb +5 -2
- data/lib/contentful/asset.rb +15 -12
- data/lib/contentful/client.rb +90 -48
- data/lib/contentful/constants.rb +499 -497
- data/lib/contentful/dynamic_entry.rb +3 -0
- data/lib/contentful/entry.rb +40 -1
- data/lib/contentful/request.rb +3 -6
- data/lib/contentful/resource.rb +92 -69
- data/lib/contentful/resource/array_like.rb +10 -2
- data/lib/contentful/resource/asset_fields.rb +7 -0
- data/lib/contentful/resource/custom_resource.rb +29 -0
- data/lib/contentful/resource/fields.rb +20 -12
- data/lib/contentful/resource/system_properties.rb +7 -0
- data/lib/contentful/resource_builder.rb +24 -17
- data/lib/contentful/support.rb +5 -1
- data/lib/contentful/sync.rb +26 -15
- data/lib/contentful/sync_page.rb +12 -0
- data/lib/contentful/version.rb +3 -1
- data/spec/entry_spec.rb +116 -0
- data/spec/fixtures/vcr_cassettes/entry/custom_resource.yml +168 -0
- data/spec/fixtures/vcr_cassettes/entry/marshall.yml +317 -0
- data/spec/fixtures/vcr_cassettes/entry/raw.yml +237 -0
- metadata +113 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 646bf441930ec6ed1182365e92ec26213a7c1326
|
4
|
+
data.tar.gz: fc8535671280aed058b63ade0bb1539bfb61a6df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f16eec5e3b322607af9f58d26e64baef7f1d1d2fdc32ebbd5404618c02692ce8bd517b0b28f0877a535614784abfc906af2d7c2a8e810744b0106cd5a8ea81f
|
7
|
+
data.tar.gz: be5ccf489cb21a2e1e9f98eeb155cf30be2f655cdc850cef208498310f111dcf1eaaf56973db5c727fc1e6ef3a1f3316d563fa70ff996befb5e26a3f020747f7
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Encoding:
|
4
|
+
Enabled: false
|
5
|
+
|
6
|
+
Metrics/ClassLength:
|
7
|
+
CountComments: false
|
8
|
+
|
9
|
+
Metrics/MethodLength:
|
10
|
+
CountComments: false
|
11
|
+
|
12
|
+
AllCops:
|
13
|
+
Exclude:
|
14
|
+
- contentful.gemspec
|
15
|
+
- spec/**/*
|
16
|
+
- examples/**/*
|
17
|
+
- Guardfile
|
18
|
+
- Gemfile
|
19
|
+
- Rakefile
|
20
|
+
|
21
|
+
Metrics/ClassLength:
|
22
|
+
Max: 230
|
23
|
+
|
24
|
+
Style/MutableConstant:
|
25
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-02-02 13:30:13 -0300 using RuboCop version 0.36.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 6
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 38
|
12
|
+
|
13
|
+
# Offense count: 5
|
14
|
+
Metrics/CyclomaticComplexity:
|
15
|
+
Max: 8
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
19
|
+
# URISchemes: http, https
|
20
|
+
Metrics/LineLength:
|
21
|
+
Max: 142
|
22
|
+
|
23
|
+
# Offense count: 12
|
24
|
+
# Configuration parameters: CountComments.
|
25
|
+
Metrics/MethodLength:
|
26
|
+
Max: 27
|
27
|
+
|
28
|
+
# Offense count: 2
|
29
|
+
# Configuration parameters: CountComments.
|
30
|
+
Metrics/ModuleLength:
|
31
|
+
Max: 499
|
32
|
+
|
33
|
+
# Offense count: 4
|
34
|
+
Metrics/PerceivedComplexity:
|
35
|
+
Max: 8
|
data/.travis.yml
CHANGED
@@ -9,3 +9,8 @@ rvm:
|
|
9
9
|
notifications:
|
10
10
|
slack:
|
11
11
|
secure: Zr3mKCiTb0vaTD4MPtTG8BbyYyErFuoxioM25QyrqePKVkDFeZC1MtGmg5klQQrJiWTKZPa/zB8NAHYkoUxg9I+z15JK0hYfz9KRubEpCrXCaqTC9Vzq88kJ3LN8YsTyBF66izaBH2KLsOfaJRxwplFzZqgpg4GG2DUBPtrGtes=
|
12
|
+
before_install: gem install bundler -v 1.10.6
|
13
|
+
script: bundle exec rake rspec_rubocop
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: jruby
|
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
# Change Log
|
2
2
|
## Unreleased
|
3
3
|
|
4
|
+
## 0.9.0
|
5
|
+
### Added
|
6
|
+
* Added `Contentful::Resource::CustomResource` to automatically map fields to accessors [#79](https://github.com/contentful/contentful.rb/issues/79)
|
7
|
+
* Added `#raw` to `Contentful::Resource` for easier Marshalling
|
8
|
+
* Added documentation regarding locales
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
* Changed Documentation Format to YARD
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
* Fixed Marshalling for Custom Resource Classes [#80](https://github.com/contentful/contentful.rb/issues/80)
|
15
|
+
|
4
16
|
## 0.8.0
|
5
17
|
### Changed
|
6
18
|
* Unified Locale Handling [#73](https://github.com/contentful/contentful.rb/issues/73)
|
data/Guardfile
CHANGED
@@ -1,42 +1,24 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
group :green_red_refactor, halt_on_fail: true do
|
2
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
3
|
+
require "guard/rspec/dsl"
|
4
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
3
5
|
|
4
|
-
|
5
|
-
# directories %w(app lib config test spec features) \
|
6
|
-
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
6
|
+
# Feel free to open issues for suggestions and improvements
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# $ mv Guardfile config/
|
14
|
-
# $ ln -s config/Guardfile .
|
15
|
-
#
|
16
|
-
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
8
|
+
# RSpec files
|
9
|
+
rspec = dsl.rspec
|
10
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
11
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
12
|
+
watch(rspec.spec_files)
|
17
13
|
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
-
# installed the spring binstubs per the docs)
|
24
|
-
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
-
# * 'just' rspec: 'rspec'
|
14
|
+
# Ruby files
|
15
|
+
ruby = dsl.ruby
|
16
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
17
|
+
end
|
26
18
|
|
27
|
-
guard :
|
28
|
-
|
29
|
-
dsl = Guard::RSpec::Dsl.new(self)
|
19
|
+
guard :yard, cmd: "yard doc" do
|
20
|
+
end
|
30
21
|
|
31
|
-
|
32
|
-
|
33
|
-
# RSpec files
|
34
|
-
rspec = dsl.rspec
|
35
|
-
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
-
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
-
watch(rspec.spec_files)
|
38
|
-
|
39
|
-
# Ruby files
|
40
|
-
ruby = dsl.ruby
|
41
|
-
dsl.watch_spec_files_for(ruby.lib_files)
|
22
|
+
guard :rubocop, cmd: "rubocop" do
|
23
|
+
end
|
42
24
|
end
|
data/README.md
CHANGED
@@ -100,6 +100,27 @@ Dynamic entries will have getter classes for the fields and do type conversions
|
|
100
100
|
|
101
101
|
The `:auto` mode will fetch all content types on initialization. If you want to do it by hand later, you will need to set the option to `:manual` and call `client.update_dynamic_entry_cache!` to initialize all dynamic entries.
|
102
102
|
|
103
|
+
#### Using different locales
|
104
|
+
|
105
|
+
Entries can have multiple locales, by default, the client only fetches the entry with only its default locale.
|
106
|
+
If you want to fetch a different locale you can do the following:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
entries = client.entries(locale: 'de-DE')
|
110
|
+
```
|
111
|
+
|
112
|
+
Then all the fields will be fetched for the requested locale.
|
113
|
+
|
114
|
+
Contentful Delivery API also allows to fetch all locales, you can do so by doing:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
entries = client.entries(content_type: 'cat', locale: '*')
|
118
|
+
|
119
|
+
# assuming the entry has a field called name
|
120
|
+
my_spanish_name = entries.first.fields('es-AR')[:name]
|
121
|
+
```
|
122
|
+
|
123
|
+
When requesting multiple locales, the object accessor shortcuts only work for the default locale.
|
103
124
|
|
104
125
|
### Arrays
|
105
126
|
|
@@ -277,6 +298,19 @@ client = Contentful::Client.new(
|
|
277
298
|
client.entry('nyancat') # is instance of Cat
|
278
299
|
```
|
279
300
|
|
301
|
+
If you want to use the `property :field_name` syntax, you can do it the following way:
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
class Cat < Contentful::Entry
|
305
|
+
include Contentful::Resource::CustomResource
|
306
|
+
|
307
|
+
property :name
|
308
|
+
property :lives
|
309
|
+
property :bestFriend
|
310
|
+
# ...
|
311
|
+
end
|
312
|
+
```
|
313
|
+
|
280
314
|
## Synchronization
|
281
315
|
|
282
316
|
The client also includes a wrapper for the synchronization endpoint. You can initialize it with the options described in the [Delivery API Documentation](https://www.contentful.com/developers/documentation/content-delivery-api/#sync) or an URL you received from a previous sync:
|
data/Rakefile
CHANGED
data/contentful.gemspec
CHANGED
@@ -24,6 +24,9 @@ Gem::Specification.new do |gem|
|
|
24
24
|
|
25
25
|
gem.add_development_dependency 'guard'
|
26
26
|
gem.add_development_dependency 'guard-rspec'
|
27
|
+
gem.add_development_dependency 'guard-rubocop'
|
28
|
+
gem.add_development_dependency 'guard-yard'
|
29
|
+
gem.add_development_dependency 'rubocop'
|
27
30
|
gem.add_development_dependency 'rspec', '~> 2'
|
28
31
|
gem.add_development_dependency 'rr'
|
29
32
|
gem.add_development_dependency 'vcr'
|
data/lib/contentful.rb
CHANGED
data/lib/contentful/array.rb
CHANGED
@@ -3,9 +3,10 @@ require_relative 'resource/array_like'
|
|
3
3
|
|
4
4
|
module Contentful
|
5
5
|
# Resource Class for Arrays (e.g. search results)
|
6
|
-
# https://www.contentful.com/developers/documentation/content-delivery-api/#arrays
|
7
|
-
# It also provides an #each method and includes Ruby's Enumerable module (gives you methods like #min, #first, etc)
|
6
|
+
# @see _ https://www.contentful.com/developers/documentation/content-delivery-api/#arrays
|
7
|
+
# @note It also provides an #each method and includes Ruby's Enumerable module (gives you methods like #min, #first, etc)
|
8
8
|
class Array
|
9
|
+
# @private
|
9
10
|
DEFAULT_LIMIT = 100
|
10
11
|
|
11
12
|
include Contentful::Resource
|
@@ -18,6 +19,8 @@ module Contentful
|
|
18
19
|
property :items
|
19
20
|
|
20
21
|
# Simplifies pagination
|
22
|
+
#
|
23
|
+
# @return [Contentful::Array, false]
|
21
24
|
def next_page
|
22
25
|
if request
|
23
26
|
new_skip = (skip || 0) + (limit || DEFAULT_LIMIT)
|
data/lib/contentful/asset.rb
CHANGED
@@ -9,20 +9,23 @@ module Contentful
|
|
9
9
|
include Contentful::Resource::SystemProperties
|
10
10
|
include Contentful::Resource::AssetFields
|
11
11
|
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
12
|
+
# Generates a URL for the Contentful Image API
|
13
|
+
#
|
14
|
+
# @param [Hash] options
|
15
|
+
# @option options [Integer] :width
|
16
|
+
# @option options [Integer] :height
|
17
|
+
# @option options [String] :format
|
18
|
+
# @option options [String] :quality
|
19
|
+
# @see _ https://www.contentful.com/developers/documentation/content-delivery-api/#image-asset-resizing
|
20
|
+
#
|
21
|
+
# @return [String] Image API URL
|
19
22
|
def image_url(options = {})
|
20
23
|
query = {
|
21
|
-
w:
|
22
|
-
h:
|
23
|
-
fm:
|
24
|
-
q:
|
25
|
-
f:
|
24
|
+
w: options[:w] || options[:width],
|
25
|
+
h: options[:h] || options[:height],
|
26
|
+
fm: options[:fm] || options[:format],
|
27
|
+
q: options[:q] || options[:quality],
|
28
|
+
f: options[:f] || options[:focus],
|
26
29
|
fit: options[:fit]
|
27
30
|
}.reject { |_k, v| v.nil? }
|
28
31
|
|
data/lib/contentful/client.rb
CHANGED
@@ -11,6 +11,7 @@ module Contentful
|
|
11
11
|
# for querying resources from this space.
|
12
12
|
# See README for details
|
13
13
|
class Client
|
14
|
+
# Default configuration for Contentful::Client
|
14
15
|
DEFAULT_CONFIGURATION = {
|
15
16
|
secure: true,
|
16
17
|
raise_errors: true,
|
@@ -35,6 +36,7 @@ module Contentful
|
|
35
36
|
attr_reader :configuration, :dynamic_entry_cache, :logger, :proxy
|
36
37
|
|
37
38
|
# Wraps the actual HTTP request via proxy
|
39
|
+
# @private
|
38
40
|
def self.get_http(url, query, headers = {}, proxy = {})
|
39
41
|
if proxy[:host]
|
40
42
|
HTTP[headers].via(proxy[:host], proxy[:port], proxy[:username], proxy[:password]).get(url, params: query)
|
@@ -43,6 +45,25 @@ module Contentful
|
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
48
|
+
# @see _ https://github.com/contentful/contentful.rb#client-configuration-options
|
49
|
+
# @param [Hash] given_configuration
|
50
|
+
# @option given_configuration [String] :space Required
|
51
|
+
# @option given_configuration [String] :access_token Required
|
52
|
+
# @option given_configuration [String] :api_url Modifying this to 'preview.contentful.com' gives you access to our Preview API
|
53
|
+
# @option given_configuration [String] :api_version
|
54
|
+
# @option given_configuration [String] :default_locale
|
55
|
+
# @option given_configuration [String] :proxy_host
|
56
|
+
# @option given_configuration [String] :proxy_username
|
57
|
+
# @option given_configuration [String] :proxy_password
|
58
|
+
# @option given_configuration [Number] :proxy_port
|
59
|
+
# @option given_configuration [Boolean] :gzip_encoded
|
60
|
+
# @option given_configuration [Boolean] :raw_mode
|
61
|
+
# @option given_configuration [false, ::Logger] :logger
|
62
|
+
# @option given_configuration [::Logger::DEBUG, ::Logger::INFO, ::Logger::WARN, ::Logger::ERROR] :log_level
|
63
|
+
# @option given_configuration [Boolean] :raise_errors
|
64
|
+
# @option given_configuration [::Array<String>] :dynamic_entries
|
65
|
+
# @option given_configuration [::Hash<String, Contentful::Resource>] :resource_mapping
|
66
|
+
# @option given_configuration [::Hash<String, Contentful::Resource>] :entry_mapping
|
46
67
|
def initialize(given_configuration = {})
|
47
68
|
@configuration = default_configuration.merge(given_configuration)
|
48
69
|
normalize_configuration!
|
@@ -56,11 +77,13 @@ module Contentful
|
|
56
77
|
end
|
57
78
|
end
|
58
79
|
|
80
|
+
# @private
|
59
81
|
def setup_logger
|
60
82
|
@logger = configuration[:logger]
|
61
83
|
logger.level = configuration[:log_level] if logger
|
62
84
|
end
|
63
85
|
|
86
|
+
# @private
|
64
87
|
def proxy_params
|
65
88
|
{
|
66
89
|
host: configuration[:proxy_host],
|
@@ -71,65 +94,85 @@ module Contentful
|
|
71
94
|
end
|
72
95
|
|
73
96
|
# Returns the default configuration
|
97
|
+
# @private
|
74
98
|
def default_configuration
|
75
99
|
DEFAULT_CONFIGURATION.dup
|
76
100
|
end
|
77
101
|
|
78
102
|
# Gets the client's space
|
79
|
-
#
|
80
|
-
#
|
103
|
+
#
|
104
|
+
# @param [Hash] query
|
105
|
+
#
|
106
|
+
# @return [Contentful::Space]
|
81
107
|
def space(query = {})
|
82
108
|
Request.new(self, '', query).get
|
83
109
|
end
|
84
110
|
|
85
111
|
# Gets a specific content type
|
86
|
-
#
|
87
|
-
#
|
112
|
+
#
|
113
|
+
# @param [String] id
|
114
|
+
# @param [Hash] query
|
115
|
+
#
|
116
|
+
# @return [Contentful::ContentType]
|
88
117
|
def content_type(id, query = {})
|
89
118
|
Request.new(self, '/content_types', query, id).get
|
90
119
|
end
|
91
120
|
|
92
121
|
# Gets a collection of content types
|
93
|
-
#
|
94
|
-
#
|
122
|
+
#
|
123
|
+
# @param [Hash] query
|
124
|
+
#
|
125
|
+
# @return [Contentful::Array<Contentful::ContentType>]
|
95
126
|
def content_types(query = {})
|
96
127
|
Request.new(self, '/content_types', query).get
|
97
128
|
end
|
98
129
|
|
99
130
|
# Gets a specific entry
|
100
|
-
#
|
101
|
-
#
|
131
|
+
#
|
132
|
+
# @param [String] id
|
133
|
+
# @param [Hash] query
|
134
|
+
#
|
135
|
+
# @return [Contentful::Entry]
|
102
136
|
def entry(id, query = {})
|
103
137
|
Request.new(self, '/entries', query, id).get
|
104
138
|
end
|
105
139
|
|
106
140
|
# Gets a collection of entries
|
107
|
-
#
|
108
|
-
#
|
141
|
+
#
|
142
|
+
# @param [Hash] query
|
143
|
+
#
|
144
|
+
# @return [Contentful::Array<Contentful::Entry>]
|
109
145
|
def entries(query = {})
|
110
146
|
Request.new(self, '/entries', query).get
|
111
147
|
end
|
112
148
|
|
113
149
|
# Gets a specific asset
|
114
|
-
#
|
115
|
-
#
|
150
|
+
#
|
151
|
+
# @param [String] id
|
152
|
+
# @param [Hash] query
|
153
|
+
#
|
154
|
+
# @return [Contentful::Asset]
|
116
155
|
def asset(id, query = {})
|
117
156
|
Request.new(self, '/assets', query, id).get
|
118
157
|
end
|
119
158
|
|
120
159
|
# Gets a collection of assets
|
121
|
-
#
|
122
|
-
#
|
160
|
+
#
|
161
|
+
# @param [Hash] query
|
162
|
+
#
|
163
|
+
# @return [Contentful::Array<Contentful::Asset>]
|
123
164
|
def assets(query = {})
|
124
165
|
Request.new(self, '/assets', query).get
|
125
166
|
end
|
126
167
|
|
127
168
|
# Returns the base url for all of the client's requests
|
169
|
+
# @private
|
128
170
|
def base_url
|
129
171
|
"http#{configuration[:secure] ? 's' : ''}://#{configuration[:api_url]}/spaces/#{configuration[:space]}"
|
130
172
|
end
|
131
173
|
|
132
174
|
# Returns the headers used for the HTTP requests
|
175
|
+
# @private
|
133
176
|
def request_headers
|
134
177
|
headers = { 'User-Agent' => "RubyContentfulGem/#{Contentful::VERSION}" }
|
135
178
|
headers['Authorization'] = "Bearer #{configuration[:access_token]}" if configuration[:authentication_mechanism] == :header
|
@@ -139,6 +182,7 @@ module Contentful
|
|
139
182
|
end
|
140
183
|
|
141
184
|
# Patches a query hash with the client configurations for queries
|
185
|
+
# @private
|
142
186
|
def request_query(query)
|
143
187
|
if configuration[:authentication_mechanism] == :query_string
|
144
188
|
query['access_token'] = configuration[:access_token]
|
@@ -149,26 +193,28 @@ module Contentful
|
|
149
193
|
# Get a Contentful::Request object
|
150
194
|
# Set second parameter to false to deactivate Resource building and
|
151
195
|
# return Response objects instead
|
196
|
+
#
|
197
|
+
# @private
|
152
198
|
def get(request, build_resource = true)
|
153
199
|
url = request.absolute? ? request.url : base_url + request.url
|
154
200
|
logger.info(request: { url: url, query: request.query, header: request_headers }) if logger
|
155
201
|
response = Response.new(
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
202
|
+
self.class.get_http(
|
203
|
+
url,
|
204
|
+
request_query(request.query),
|
205
|
+
request_headers,
|
206
|
+
proxy_params
|
207
|
+
), request
|
162
208
|
)
|
163
209
|
|
164
210
|
return response if !build_resource || configuration[:raw_mode]
|
165
211
|
logger.debug(response: response) if logger
|
166
212
|
result = configuration[:resource_builder].new(
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
213
|
+
self,
|
214
|
+
response,
|
215
|
+
configuration[:resource_mapping],
|
216
|
+
configuration[:entry_mapping],
|
217
|
+
configuration[:default_locale]
|
172
218
|
).run
|
173
219
|
|
174
220
|
fail result if result.is_a?(Error) && configuration[:raise_errors]
|
@@ -177,6 +223,7 @@ module Contentful
|
|
177
223
|
|
178
224
|
# Use this method together with the client's :dynamic_entries configuration.
|
179
225
|
# See README for details.
|
226
|
+
# @private
|
180
227
|
def update_dynamic_entry_cache!
|
181
228
|
@dynamic_entry_cache = Hash[
|
182
229
|
content_types(limit: 1000).map do |ct|
|
@@ -190,13 +237,18 @@ module Contentful
|
|
190
237
|
|
191
238
|
# Use this method to manually register a dynamic entry
|
192
239
|
# See examples/dynamic_entries.rb
|
240
|
+
# @private
|
193
241
|
def register_dynamic_entry(key, klass)
|
194
242
|
@dynamic_entry_cache[key.to_sym] = klass
|
195
243
|
end
|
196
244
|
|
197
245
|
# Create a new synchronisation object
|
198
|
-
#
|
199
|
-
#
|
246
|
+
#
|
247
|
+
# @param [Hash, String] options Options or Sync URL
|
248
|
+
#
|
249
|
+
# @note You will need to call #each_page or #first_page on it
|
250
|
+
#
|
251
|
+
# @return [Contentful::Sync]
|
200
252
|
def sync(options = { initial: true })
|
201
253
|
Sync.new(self, options)
|
202
254
|
end
|
@@ -209,33 +261,23 @@ module Contentful
|
|
209
261
|
end
|
210
262
|
|
211
263
|
def validate_configuration!
|
212
|
-
if configuration[:space].empty?
|
213
|
-
fail ArgumentError, 'You will need to initialize a client with a :space'
|
214
|
-
end
|
264
|
+
fail ArgumentError, 'You will need to initialize a client with a :space' if configuration[:space].empty?
|
215
265
|
|
216
|
-
if configuration[:access_token].empty?
|
217
|
-
fail ArgumentError, 'You will need to initialize a client with an :access_token'
|
218
|
-
end
|
266
|
+
fail ArgumentError, 'You will need to initialize a client with an :access_token' if configuration[:access_token].empty?
|
219
267
|
|
220
|
-
if configuration[:api_url].empty?
|
221
|
-
fail ArgumentError, 'The client configuration needs to contain an :api_url'
|
222
|
-
end
|
268
|
+
fail ArgumentError, 'The client configuration needs to contain an :api_url' if configuration[:api_url].empty?
|
223
269
|
|
224
|
-
if configuration[:default_locale].empty?
|
225
|
-
fail ArgumentError, 'The client configuration needs to contain a :default_locale'
|
226
|
-
end
|
270
|
+
fail ArgumentError, 'The client configuration needs to contain a :default_locale' if configuration[:default_locale].empty?
|
227
271
|
|
228
|
-
unless configuration[:api_version].to_i >= 0
|
229
|
-
fail ArgumentError, 'The :api_version must be a positive number or nil'
|
230
|
-
end
|
272
|
+
fail ArgumentError, 'The :api_version must be a positive number or nil' unless configuration[:api_version].to_i >= 0
|
231
273
|
|
232
|
-
unless [:header, :query_string].include?
|
233
|
-
|
234
|
-
|
274
|
+
fail ArgumentError, 'The authentication mechanism must be :header or :query_string' unless [:header, :query_string].include?(
|
275
|
+
configuration[:authentication_mechanism]
|
276
|
+
)
|
235
277
|
|
236
|
-
unless [:auto, :manual].include?
|
237
|
-
|
238
|
-
|
278
|
+
fail ArgumentError, 'The :dynamic_entries mode must be :auto or :manual' unless [:auto, :manual].include?(
|
279
|
+
configuration[:dynamic_entries]
|
280
|
+
)
|
239
281
|
end
|
240
282
|
end
|
241
283
|
end
|