contentful 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG.md +6 -0
- data/README.md +10 -0
- data/contentful.gemspec +1 -1
- data/lib/contentful/client.rb +3 -2
- data/lib/contentful/response.rb +14 -3
- data/lib/contentful/version.rb +1 -1
- data/spec/support/json_responses.rb +1 -0
- metadata +6 -5
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -13,6 +13,8 @@ Add to your Gemfile and bundle:
|
|
13
13
|
gem 'contentful'
|
14
14
|
```
|
15
15
|
|
16
|
+
|
17
|
+
|
16
18
|
## Usage
|
17
19
|
|
18
20
|
```ruby
|
@@ -166,6 +168,9 @@ Defaults to `false`. If enabled, the API responses will not be parsed to resourc
|
|
166
168
|
|
167
169
|
See next paragraph for explanation
|
168
170
|
|
171
|
+
### :gzip_encoded
|
172
|
+
|
173
|
+
Enables gzip response content encoding, default to: true
|
169
174
|
|
170
175
|
## Advanced Usage
|
171
176
|
### Custom Resource Classes
|
@@ -262,6 +267,11 @@ first_entry = client.sync(initial: true, type: 'Entry').first_page.items.first
|
|
262
267
|
first_entry.fields('de-DE') # Returns German localizations
|
263
268
|
```
|
264
269
|
|
270
|
+
## Ratelimit
|
271
|
+
The library does not make assumptions on the rate limit but reacts to `HTTP 429` by returning an error object.
|
272
|
+
You should handle this within your code and either do the delay calculation naive (fixed amount of seconds) or more elaborated (exponential increase) depending by the structure of your code.
|
273
|
+
|
274
|
+
|
265
275
|
## License
|
266
276
|
|
267
277
|
Copyright (c) 2014 Contentful GmbH - Jan Lelis. See LICENSE.txt for further details.
|
data/contentful.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.summary = 'contentful'
|
9
9
|
gem.description = 'Ruby client for the https://www.contentful.com Content Delivery API'
|
10
10
|
gem.license = "MIT"
|
11
|
-
gem.authors = ["Contentful GmbH (Jan Lelis)"]
|
11
|
+
gem.authors = ["Contentful GmbH (Jan Lelis)",'Contentful GmbH (Andreas Tiefenthaler)']
|
12
12
|
gem.email = "rubygems@contentful.com"
|
13
13
|
gem.homepage = "https://github.com/contentful/contentful.rb"
|
14
14
|
|
data/lib/contentful/client.rb
CHANGED
@@ -21,7 +21,8 @@ module Contentful
|
|
21
21
|
resource_mapping: {},
|
22
22
|
entry_mapping: {},
|
23
23
|
default_locale: 'en-US',
|
24
|
-
raw_mode: false
|
24
|
+
raw_mode: false,
|
25
|
+
gzip_encoded: false
|
25
26
|
}
|
26
27
|
|
27
28
|
attr_reader :configuration, :dynamic_entry_cache
|
@@ -107,7 +108,7 @@ module Contentful
|
|
107
108
|
headers = { 'User-Agent' => "RubyContentfulGem/#{Contentful::VERSION}" }
|
108
109
|
headers['Authorization'] = "Bearer #{configuration[:access_token]}" if configuration[:authentication_mechanism] == :header
|
109
110
|
headers['Content-Type'] = "application/vnd.contentful.delivery.v#{configuration[:api_version].to_i}+json" if configuration[:api_version]
|
110
|
-
|
111
|
+
headers['Accept-Encoding'] = 'gzip' if configuration[:gzip_encoded]
|
111
112
|
headers
|
112
113
|
end
|
113
114
|
|
data/lib/contentful/response.rb
CHANGED
@@ -23,9 +23,9 @@ module Contentful
|
|
23
23
|
attr_reader :raw, :object, :status, :error_message, :request
|
24
24
|
|
25
25
|
def initialize(raw, request = nil)
|
26
|
-
@raw
|
26
|
+
@raw = raw
|
27
27
|
@request = request
|
28
|
-
@status
|
28
|
+
@status = :ok
|
29
29
|
|
30
30
|
if service_unavailable_response?
|
31
31
|
@status = :service_unavailable
|
@@ -49,7 +49,8 @@ module Contentful
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def parse_json!
|
52
|
-
|
52
|
+
body = unzip_response(raw)
|
53
|
+
@object = MultiJson.load(body)
|
53
54
|
true
|
54
55
|
rescue MultiJson::LoadError => e
|
55
56
|
@status = :unparsable_json
|
@@ -73,5 +74,15 @@ module Contentful
|
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
77
|
+
def unzip_response(response)
|
78
|
+
if response.headers['Content-Encoding'].eql?('gzip') then
|
79
|
+
sio = StringIO.new(response.to_s)
|
80
|
+
gz = Zlib::GzipReader.new(sio)
|
81
|
+
gz.read()
|
82
|
+
else
|
83
|
+
response.to_s
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
76
87
|
end
|
77
88
|
end
|
data/lib/contentful/version.rb
CHANGED
@@ -3,6 +3,7 @@ require 'multi_json'
|
|
3
3
|
def raw_fixture(which,status = 200, as_json = false)
|
4
4
|
object = Object.new
|
5
5
|
stub(object).status { status }
|
6
|
+
stub(object).headers { {} }
|
6
7
|
stub(object).to_s { File.read File.dirname(__FILE__) + "/../fixtures/json_responses/#{which}.json" }
|
7
8
|
|
8
9
|
object
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Contentful GmbH (Jan Lelis)
|
9
|
+
- Contentful GmbH (Andreas Tiefenthaler)
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-
|
13
|
+
date: 2014-09-04 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: http
|
@@ -288,7 +289,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
288
289
|
version: '0'
|
289
290
|
segments:
|
290
291
|
- 0
|
291
|
-
hash:
|
292
|
+
hash: 3440490191583500455
|
292
293
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
293
294
|
none: false
|
294
295
|
requirements:
|
@@ -297,10 +298,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
297
298
|
version: '0'
|
298
299
|
segments:
|
299
300
|
- 0
|
300
|
-
hash:
|
301
|
+
hash: 3440490191583500455
|
301
302
|
requirements: []
|
302
303
|
rubyforge_project:
|
303
|
-
rubygems_version: 1.8.23
|
304
|
+
rubygems_version: 1.8.23
|
304
305
|
signing_key:
|
305
306
|
specification_version: 3
|
306
307
|
summary: contentful
|