contentful 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7db63bec4505f15a7698a8a0a122429abbb5c06c
4
- data.tar.gz: cd8c4030d47bfb4b63929e3dcf70f9cbb2326860
3
+ metadata.gz: 8ed4d3309966895ce684008c996e75049713e264
4
+ data.tar.gz: 40123f61c8a46803a3c4ad2e880c4d5aeb7dcffc
5
5
  SHA512:
6
- metadata.gz: 1af685dcbe8e195a48c27d0c5c3ff7b4b3f4faed20dd636d899cec8c71e9c3f1790116fbb00bc65be89f917ee99806a87636458a1db1ffa3921d32fd710c9611
7
- data.tar.gz: 55b018b32477efa92e8878f58ffb17bcf1eaa97618e4b3634f2e443f16eb7c39f11bd1cd5c5d9a9a00a901b69ca76bd058ab76a3dd2def95e51ff30b40694d99
6
+ metadata.gz: 176f36cc905b504589f0a382435a441b1138fe7d91dc96c867fd512b54470bbf8da95d5e2a9b9c5d5f08f3a26b3d27571c2dec5ca10be38afef61cbf2aedd215
7
+ data.tar.gz: 89203b3ace82cc92b9e6b3f6d689b100e433c82a0b50ebc7b2713e05c0197c331b3dd35ff250be58c444f25d408fd53f5a44dd9167d18783dbff61ea88a2279a
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.2.1
3
4
  - 2.1.2
4
5
  - 2.1.1
5
6
  - 2.1
6
7
  - 2.0.0
7
8
  - 1.9.3
8
- # - jruby-19mode
data/CHANGELOG.md CHANGED
@@ -1,8 +1,19 @@
1
1
  # Change Log
2
2
  ## Unreleased
3
+
4
+ ## 0.6.0
5
+ ### Fixed
6
+ * Parse nested locales in `AssetFields` [#66](https://github.com/contentful/contentful.rb/pull/66)
7
+
8
+ ### Other
9
+ * Update http.rb dependency to v0.8.0
10
+ * Fix typo in service unavailable error message [#61](https://github.com/contentful/contentful.rb/pull/61)
11
+ * Enable gzip encoding by default [#62](https://github.com/contentful/contentful.rb/pull/62)
12
+
13
+ ## 0.5.0
3
14
  ### Fixed
4
- * Better handling of 503 responses from the API [#48](https://github.com/contentful/contentful-management.rb/pull/48)
5
- * Better handling of 429 responses from the API [#51](https://github.com/contentful/contentful-management.rb/pull/51)
15
+ * Better handling of 503 responses from the API [#50](https://github.com/contentful/contentful.rb/pull/50)
16
+ * Better handling of 429 responses from the API [#51](https://github.com/contentful/contentful.rb/pull/51)
6
17
 
7
18
  ### Added
8
19
  * `focus` and `fit` to image handling parameters [#44](https://github.com/contentful/contentful.rb/pull/44)
data/README.md CHANGED
@@ -45,8 +45,10 @@ client.entry 'nyancat'
45
45
  You can pass the usual filter options to the query:
46
46
 
47
47
  ```ruby
48
+ client.entries(content_type: 'cat') # query for a content-type by its ID (not name)
48
49
  client.entries('sys.id[ne]' => 'nyancat') # query for all entries except 'nyancat'
49
50
  client.entries(include: 1) # include one level of linked resources
51
+ client.entries(content_type: 'cat', include: 1) # you can also combine multiple parameters
50
52
  ```
51
53
 
52
54
  The results are returned as Contentful::Resource objects. Multiple results will be returned as Contentful::Array. The properties of a resource can be accessed through Ruby methods.
@@ -326,10 +328,17 @@ first_entry.fields('de-DE') # Returns German localizations
326
328
  ```
327
329
 
328
330
  ## Rate-limit
329
- The library does not make assumptions on the rate limit but reacts to `HTTP 429` by returning an error object.
331
+ The library does not make assumptions on the rate limit but reacts to `HTTP 429` by raising or returning an error (see [Client Configuration Options](#client-configuration-options)).
330
332
  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.
331
333
 
332
334
 
335
+ ## Workarounds
336
+
337
+ - When an entry has related entries that are unpublished, they still end up in the resource as unresolved links. We consider this correct, because it is in line with the API responses and our other SDKs. However, you can use the workaround from [issue #60](/../../issues/60) if you happen to want this working differently.
338
+
339
+ - While this library doesn't directly allow parsing Contentful webhook responses, you can check out [this code snippet](https://gist.github.com/neonichu/17a987aeeb256d4bf6f3) for a way to do it.
340
+
341
+
333
342
  ## License
334
343
 
335
344
  Copyright (c) 2014 Contentful GmbH - Jan Lelis. See LICENSE.txt for further details.
data/contentful.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.test_files = gem.files.grep(%r{^spec/})
16
16
  gem.require_paths = ['lib']
17
17
 
18
- gem.add_dependency 'http', '~> 0.6'
18
+ gem.add_dependency 'http', '~> 0.8'
19
19
  gem.add_dependency 'multi_json', '~> 1'
20
20
 
21
21
  gem.add_development_dependency 'bundler', '~> 1.5'
@@ -23,7 +23,7 @@ module Contentful
23
23
  entry_mapping: {},
24
24
  default_locale: 'en-US',
25
25
  raw_mode: false,
26
- gzip_encoded: false,
26
+ gzip_encoded: true,
27
27
  logger: false,
28
28
  log_level: Logger::INFO,
29
29
  proxy_host: nil,
@@ -69,6 +69,23 @@ module Contentful
69
69
 
70
70
  private
71
71
 
72
+ def initialize_fields_for_localized_resource(object)
73
+ @fields = {}
74
+
75
+ if nested_locale_fields?
76
+ object['fields'].each do |field_name, nested_child_object|
77
+ nested_child_object.each do |object_locale, real_child_object|
78
+ @fields[object_locale] ||= {}
79
+ @fields[object_locale].merge! extract_from_object(
80
+ { field_name => real_child_object }, :fields
81
+ )
82
+ end
83
+ end
84
+ else
85
+ @fields[locale] = extract_from_object object['fields'], :fields
86
+ end
87
+ end
88
+
72
89
  def extract_from_object(object, namespace, keys = nil)
73
90
  if object
74
91
  keys ||= object.keys
@@ -12,14 +12,15 @@ module Contentful
12
12
  file: File
13
13
  }
14
14
 
15
- def fields
16
- @fields[locale]
15
+ # Returns all fields of the asset
16
+ def fields(wanted_locale = default_locale)
17
+ @fields[locale || wanted_locale]
17
18
  end
18
19
 
19
20
  def initialize(object, *)
20
21
  super
21
- @fields = {}
22
- @fields[locale] = extract_from_object object['fields'], :fields
22
+
23
+ initialize_fields_for_localized_resource(object)
23
24
  end
24
25
 
25
26
  def inspect(info = nil)
@@ -26,20 +26,7 @@ module Contentful
26
26
  private
27
27
 
28
28
  def extract_fields_from_object!(object)
29
- @fields = {}
30
-
31
- if nested_locale_fields?
32
- object['fields'].each do |field_name, nested_child_object|
33
- nested_child_object.each do |object_locale, real_child_object|
34
- @fields[object_locale] ||= {}
35
- @fields[object_locale].merge! extract_from_object(
36
- { field_name => real_child_object }, :fields
37
- )
38
- end
39
- end
40
- else
41
- @fields[locale] = extract_from_object object['fields'], :fields
42
- end
29
+ initialize_fields_for_localized_resource(object)
43
30
  end
44
31
 
45
32
  module ClassMethods
@@ -62,7 +62,7 @@ module Contentful
62
62
 
63
63
  def service_unavailable_error
64
64
  @status = :error
65
- @error_message = 'Service Unavailable, contenful.com API seems to be down'
65
+ @error_message = 'Service unavailable, contentful.com API seems to be down (503)'
66
66
  @object = Error[@raw.status].new(self)
67
67
  end
68
68
 
@@ -1,3 +1,3 @@
1
1
  module Contentful
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -17,7 +17,7 @@ describe 'Error Requests' do
17
17
  skip
18
18
  end
19
19
 
20
- it 'will return 401 (Unauthorized) if wrong credentials given' do
20
+ it 'will return 401 (Unauthorized) if wrong credentials are given' do
21
21
  client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')
22
22
 
23
23
  expect_vcr('unauthorized'){
@@ -29,14 +29,14 @@ describe 'Error Requests' do
29
29
  skip
30
30
  end
31
31
 
32
- it 'will return a 429 if the ratelimit is hit' do
32
+ it 'will return a 429 if the ratelimit is reached' do
33
33
  client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')
34
34
  expect_vcr('ratelimit') {
35
35
  client.entry('nyancat')
36
36
  }.to raise_error(Contentful::RateLimitExceeded)
37
37
  end
38
38
 
39
- it 'will return 503 (ServiceUnavailable) if connection time out' do
39
+ it 'will return 503 (ServiceUnavailable) when the service is unavailable' do
40
40
  client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')
41
41
 
42
42
  expect_vcr('unavailable'){
data/spec/sync_spec.rb CHANGED
@@ -81,4 +81,20 @@ describe Contentful::Sync do
81
81
  }}
82
82
  end
83
83
  end
84
+
85
+ describe 'Resource parsing' do
86
+ it 'will correctly parse the `file` field of an asset' do
87
+ sync = create_client.sync(initial: true)
88
+ vcr('sync_page') {
89
+ asset = sync.first_page.items.select { |item| item.is_a?(Contentful::Asset) }.first
90
+
91
+ expect(asset.file.properties[:fileName]).to eq 'doge.jpg'
92
+ expect(asset.file.properties[:contentType]).to eq 'image/jpeg'
93
+ expect(asset.file.properties[:details]['image']['width']).to eq 5800
94
+ expect(asset.file.properties[:details]['image']['height']).to eq 4350
95
+ expect(asset.file.properties[:details]['size']).to eq 522943
96
+ expect(asset.file.properties[:url]).to eq '//images.contentful.com/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg'
97
+ }
98
+ end
99
+ end
84
100
  end
metadata CHANGED
@@ -1,130 +1,129 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contentful GmbH (Jan Lelis)
8
8
  - Contentful GmbH (Andreas Tiefenthaler)
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-28 00:00:00.000000000 Z
12
+ date: 2015-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: http
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: '0.6'
21
- type: :runtime
19
+ version: '0.8'
20
+ name: http
22
21
  prerelease: false
22
+ type: :runtime
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0.6'
27
+ version: '0.8'
28
28
  - !ruby/object:Gem::Dependency
29
- name: multi_json
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - "~>"
33
32
  - !ruby/object:Gem::Version
34
33
  version: '1'
35
- type: :runtime
34
+ name: multi_json
36
35
  prerelease: false
36
+ type: :runtime
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '1'
42
42
  - !ruby/object:Gem::Dependency
43
- name: bundler
44
43
  requirement: !ruby/object:Gem::Requirement
45
44
  requirements:
46
45
  - - "~>"
47
46
  - !ruby/object:Gem::Version
48
47
  version: '1.5'
49
- type: :development
48
+ name: bundler
50
49
  prerelease: false
50
+ type: :development
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '1.5'
56
56
  - !ruby/object:Gem::Dependency
57
- name: rake
58
57
  requirement: !ruby/object:Gem::Requirement
59
58
  requirements:
60
59
  - - "~>"
61
60
  - !ruby/object:Gem::Version
62
61
  version: '10'
63
- type: :development
62
+ name: rake
64
63
  prerelease: false
64
+ type: :development
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '10'
70
70
  - !ruby/object:Gem::Dependency
71
- name: rubygems-tasks
72
71
  requirement: !ruby/object:Gem::Requirement
73
72
  requirements:
74
73
  - - "~>"
75
74
  - !ruby/object:Gem::Version
76
75
  version: '0.2'
77
- type: :development
76
+ name: rubygems-tasks
78
77
  prerelease: false
78
+ type: :development
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0.2'
84
84
  - !ruby/object:Gem::Dependency
85
- name: rspec
86
85
  requirement: !ruby/object:Gem::Requirement
87
86
  requirements:
88
87
  - - "~>"
89
88
  - !ruby/object:Gem::Version
90
89
  version: '2'
91
- type: :development
90
+ name: rspec
92
91
  prerelease: false
92
+ type: :development
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
97
  version: '2'
98
98
  - !ruby/object:Gem::Dependency
99
- name: rr
100
99
  requirement: !ruby/object:Gem::Requirement
101
100
  requirements:
102
101
  - - ">="
103
102
  - !ruby/object:Gem::Version
104
103
  version: '0'
105
- type: :development
104
+ name: rr
106
105
  prerelease: false
106
+ type: :development
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
- name: vcr
114
113
  requirement: !ruby/object:Gem::Requirement
115
114
  requirements:
116
115
  - - ">="
117
116
  - !ruby/object:Gem::Version
118
117
  version: '0'
119
- type: :development
118
+ name: vcr
120
119
  prerelease: false
120
+ type: :development
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: webmock
128
127
  requirement: !ruby/object:Gem::Requirement
129
128
  requirements:
130
129
  - - "~>"
@@ -133,8 +132,9 @@ dependencies:
133
132
  - - ">="
134
133
  - !ruby/object:Gem::Version
135
134
  version: 1.17.3
136
- type: :development
135
+ name: webmock
137
136
  prerelease: false
137
+ type: :development
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - "~>"
@@ -262,7 +262,7 @@ homepage: https://github.com/contentful/contentful.rb
262
262
  licenses:
263
263
  - MIT
264
264
  metadata: {}
265
- post_install_message:
265
+ post_install_message:
266
266
  rdoc_options: []
267
267
  require_paths:
268
268
  - lib
@@ -277,9 +277,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
277
  - !ruby/object:Gem::Version
278
278
  version: '0'
279
279
  requirements: []
280
- rubyforge_project:
281
- rubygems_version: 2.2.2
282
- signing_key:
280
+ rubyforge_project:
281
+ rubygems_version: 2.4.8
282
+ signing_key:
283
283
  specification_version: 4
284
284
  summary: contentful
285
285
  test_files: