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 CHANGED
@@ -1,3 +1,5 @@
1
1
  pkg
2
2
  coverage
3
3
  Gemfile.lock
4
+ .idea
5
+ *.DS_Store
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.3.4
2
+ * add optional gzip compression
3
+
4
+ ### 0.3.3
5
+ * Fix: handle 503 errors from the api
6
+
1
7
  ### 0.3.2
2
8
  * add default property to locale, #23
3
9
 
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
 
@@ -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
 
@@ -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 = raw
26
+ @raw = raw
27
27
  @request = request
28
- @status = :ok
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
- @object = MultiJson.load(raw.to_s)
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
@@ -1,3 +1,3 @@
1
1
  module Contentful
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
@@ -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.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-08-13 00:00:00.000000000 Z
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: -1847885584219532891
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: -1847885584219532891
301
+ hash: 3440490191583500455
301
302
  requirements: []
302
303
  rubyforge_project:
303
- rubygems_version: 1.8.23.2
304
+ rubygems_version: 1.8.23
304
305
  signing_key:
305
306
  specification_version: 3
306
307
  summary: contentful