contentful-management 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,30 +1,35 @@
1
+ ### 0.2.0
2
+ * Fix: create entry with multiple locales, skip attributes for not localized fields in content types
3
+ * Fix: reload Assets
4
+ * add optional gzip envoding
5
+
1
6
  ### 0.1.0
2
- * Support for webhooks
3
- * add image url to asset
4
- * Cleaning code
5
- * Fix: remove implicit processing of assets.
6
- * Fix: Gem is modifying nil #17
7
- * Fix: rename asset.process_files to asset.process
7
+ * Support for webhooks
8
+ * add image url to asset
9
+ * Cleaning code
10
+ * Fix: remove implicit processing of assets.
11
+ * Fix: Gem is modifying nil #17
12
+ * Fix: rename asset.process_files to asset.process
8
13
 
9
14
 
10
15
  ### 0.0.3
11
- * Fix: next_page feature
12
- * Fix: create entry with specific locale
13
- * Fix: service unavailable error (503)
14
- * Fix: reload method on objects
15
- * Code cleanup
16
- * More documentation
16
+ * Fix: next_page feature
17
+ * Fix: create entry with specific locale
18
+ * Fix: service unavailable error (503)
19
+ * Fix: reload method on objects
20
+ * Code cleanup
21
+ * More documentation
17
22
 
18
23
  ### 0.0.2
19
- * Fix: Convert an Entry to a DynamicEntry after being created.
24
+ * Fix: Convert an Entry to a DynamicEntry after being created.
20
25
 
21
26
  ### 0.0.1
22
- * Fix: Headers not properly cleared between requests
23
- * Fix: Create entries with custom identifier
24
- * Code cleanup
25
- * Adding rdoc
26
- * Adding filter by content_type id
27
+ * Fix: Headers not properly cleared between requests
28
+ * Fix: Create entries with custom identifier
29
+ * Code cleanup
30
+ * Adding rdoc
31
+ * Adding filter by content_type id
27
32
 
28
33
 
29
34
  ### 0.0.1-pre
30
- * alpha pre-release
35
+ * alpha pre-release
@@ -22,7 +22,8 @@ module Contentful
22
22
  api_url: 'api.contentful.com',
23
23
  api_version: '1',
24
24
  secure: true,
25
- default_locale: 'en-US'
25
+ default_locale: 'en-US',
26
+ gzip_encoded: false
26
27
  }
27
28
 
28
29
  def initialize(access_token = nil, configuration = {})
@@ -59,6 +60,10 @@ module Contentful
59
60
  configuration[:api_version]
60
61
  end
61
62
 
63
+ def gzip_encoded
64
+ configuration[:gzip_encoded]
65
+ end
66
+
62
67
  def default_configuration
63
68
  DEFAULT_CONFIGURATION.dup
64
69
  end
@@ -145,6 +150,10 @@ module Contentful
145
150
  Hash['Content-Length', 0]
146
151
  end
147
152
 
153
+ def accept_encoding_header(encoding)
154
+ Hash['Accept-Encoding', encoding]
155
+ end
156
+
148
157
  # XXX: headers should be supplied differently, maybe through the request object.
149
158
  def request_headers
150
159
  headers = {}
@@ -155,6 +164,7 @@ module Contentful
155
164
  headers.merge! version_header(version) if version
156
165
  headers.merge! zero_length_header if zero_length
157
166
  headers.merge! content_type_header(content_type_id) if content_type_id
167
+ headers.merge! accept_encoding_header('gzip') if gzip_encoded
158
168
  headers
159
169
  end
160
170
 
@@ -39,12 +39,16 @@ module Contentful
39
39
  fields_for_query[field.id.to_sym]
40
40
  end
41
41
  define_method "#{ accessor_name }=" do |value|
42
- fields[field.id.to_sym] = value
42
+ if field.localized || default_locale == locale
43
+ fields[field.id.to_sym] = value
44
+ end
43
45
  end
44
46
  define_method "#{ accessor_name }_with_locales=" do |values|
45
47
  values.each do |locale, value|
46
- @fields[locale] = {} if @fields[locale].nil?
47
- @fields[locale][field.id.to_sym] = value
48
+ if field.localized || default_locale == locale
49
+ @fields[locale] = {} if @fields[locale].nil?
50
+ @fields[locale][field.id.to_sym] = value
51
+ end
48
52
  end
49
53
  end
50
54
  end
@@ -156,7 +156,7 @@ module Contentful
156
156
  fields_names.each_with_object({}) do |field_name, results|
157
157
  results[field_name] = raw_fields.each_with_object({}) do |(locale, fields), field_results|
158
158
  # field_results[locale] = fields[field_name]
159
- field_results[locale] = parse_update_attribute(fields[field_name])
159
+ field_results[locale] = parse_update_attribute(fields[field_name]) unless fields[field_name].nil?
160
160
  end
161
161
  end
162
162
  end
@@ -16,7 +16,7 @@ module Contentful
16
16
  resource
17
17
  else
18
18
  @properties = resource.instance_variable_get(:@properties)
19
- @fields = resource.instance_variable_get(:@fields) if self.is_a?(Contentful::Management::Entry)
19
+ @fields = resource.instance_variable_get(:@fields)
20
20
  @sys = resource.instance_variable_get(:@sys).merge(locale: locale)
21
21
  self
22
22
  end
@@ -51,7 +51,8 @@ module Contentful
51
51
  end
52
52
 
53
53
  def parse_json!
54
- @object = MultiJson.load(raw.to_s)
54
+ body = unzip_response(raw)
55
+ @object = MultiJson.load(body)
55
56
  true
56
57
  rescue MultiJson::LoadError => error
57
58
  @status = :unparsable_json
@@ -74,6 +75,16 @@ module Contentful
74
75
  @error_message = 'No contentful system properties found in object'
75
76
  end
76
77
  end
78
+
79
+ def unzip_response(response)
80
+ if response.headers['Content-Encoding'].eql?('gzip') then
81
+ sio = StringIO.new(response.to_s)
82
+ gz = Zlib::GzipReader.new(sio)
83
+ gz.read()
84
+ else
85
+ response.to_s
86
+ end
87
+ end
77
88
  end
78
89
  end
79
90
  end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module Contentful
3
3
  module Management
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
6
6
  end
@@ -0,0 +1,235 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/bfsvtul0c41g/assets/8R4vbQXKbCkcSu26Wy2U0
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContenfulManagementGem/0.0.2
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Content-Length:
17
+ - '0'
18
+ Host:
19
+ - api.contentful.com
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - nginx
27
+ Date:
28
+ - Tue, 19 Aug 2014 10:10:30 GMT
29
+ Content-Type:
30
+ - application/vnd.contentful.management.v1+json
31
+ Content-Length:
32
+ - '1403'
33
+ Connection:
34
+ - keep-alive
35
+ X-Powered-By:
36
+ - Express
37
+ Cf-Space-Id:
38
+ - bfsvtul0c41g
39
+ Etag:
40
+ - '"2be36cc687cc0a25a0e36182b95f3ba7"'
41
+ Access-Control-Allow-Origin:
42
+ - "*"
43
+ Access-Control-Allow-Headers:
44
+ - 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
45
+ Access-Control-Allow-Methods:
46
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
47
+ "^access-Control-Expose-Headers":
48
+ - Etag
49
+ Access-Control-Max-Age:
50
+ - '1728000'
51
+ body:
52
+ encoding: UTF-8
53
+ string: |
54
+ {
55
+ "fields": {
56
+ "title": {
57
+ "en-US": "test"
58
+ },
59
+ "description": {
60
+ "en-US": "testowy"
61
+ },
62
+ "file": {
63
+ "en-US": {
64
+ "fileName": "Mowing_your_Lawn_-_Advice_and_Tips",
65
+ "contentType": "image/jpeg",
66
+ "details": {
67
+ "image": {
68
+ "width": 801,
69
+ "height": 1000
70
+ },
71
+ "size": 105202
72
+ },
73
+ "url": "//images.contentful.com/bfsvtul0c41g/8R4vbQXKbCkcSu26Wy2U0/4ca4dabb0305045fa5c3c786bf5d7592/mow.jpg"
74
+ }
75
+ }
76
+ },
77
+ "sys": {
78
+ "id": "8R4vbQXKbCkcSu26Wy2U0",
79
+ "type": "Asset",
80
+ "createdAt": "2014-08-19T07:25:10.104Z",
81
+ "createdBy": {
82
+ "sys": {
83
+ "type": "Link",
84
+ "linkType": "User",
85
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
86
+ }
87
+ },
88
+ "space": {
89
+ "sys": {
90
+ "type": "Link",
91
+ "linkType": "Space",
92
+ "id": "bfsvtul0c41g"
93
+ }
94
+ },
95
+ "firstPublishedAt": "2014-08-19T07:25:32.234Z",
96
+ "publishedCounter": 1,
97
+ "publishedAt": "2014-08-19T07:25:32.234Z",
98
+ "publishedBy": {
99
+ "sys": {
100
+ "type": "Link",
101
+ "linkType": "User",
102
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
103
+ }
104
+ },
105
+ "publishedVersion": 11,
106
+ "version": 14,
107
+ "updatedAt": "2014-08-19T10:09:26.237Z",
108
+ "updatedBy": {
109
+ "sys": {
110
+ "type": "Link",
111
+ "linkType": "User",
112
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
113
+ }
114
+ }
115
+ }
116
+ }
117
+ http_version:
118
+ recorded_at: Tue, 19 Aug 2014 10:10:26 GMT
119
+ - request:
120
+ method: get
121
+ uri: https://api.contentful.com/spaces/bfsvtul0c41g/assets/8R4vbQXKbCkcSu26Wy2U0
122
+ body:
123
+ encoding: US-ASCII
124
+ string: ''
125
+ headers:
126
+ User-Agent:
127
+ - RubyContenfulManagementGem/0.0.2
128
+ Authorization:
129
+ - Bearer <ACCESS_TOKEN>
130
+ Content-Type:
131
+ - application/vnd.contentful.management.v1+json
132
+ Content-Length:
133
+ - '0'
134
+ Host:
135
+ - api.contentful.com
136
+ response:
137
+ status:
138
+ code: 200
139
+ message: OK
140
+ headers:
141
+ Server:
142
+ - nginx
143
+ Date:
144
+ - Tue, 19 Aug 2014 10:10:34 GMT
145
+ Content-Type:
146
+ - application/vnd.contentful.management.v1+json
147
+ Content-Length:
148
+ - '1403'
149
+ Connection:
150
+ - keep-alive
151
+ X-Powered-By:
152
+ - Express
153
+ Cf-Space-Id:
154
+ - bfsvtul0c41g
155
+ Etag:
156
+ - '"2be36cc687cc0a25a0e36182b95f3ba7"'
157
+ Access-Control-Allow-Origin:
158
+ - "*"
159
+ Access-Control-Allow-Headers:
160
+ - 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
161
+ Access-Control-Allow-Methods:
162
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
163
+ "^access-Control-Expose-Headers":
164
+ - Etag
165
+ Access-Control-Max-Age:
166
+ - '1728000'
167
+ body:
168
+ encoding: UTF-8
169
+ string: |
170
+ {
171
+ "fields": {
172
+ "title": {
173
+ "en-US": "test"
174
+ },
175
+ "description": {
176
+ "en-US": "testowy"
177
+ },
178
+ "file": {
179
+ "en-US": {
180
+ "fileName": "Mowing_your_Lawn_-_Advice_and_Tips",
181
+ "contentType": "image/jpeg",
182
+ "details": {
183
+ "image": {
184
+ "width": 801,
185
+ "height": 1000
186
+ },
187
+ "size": 105202
188
+ },
189
+ "url": "//images.contentful.com/bfsvtul0c41g/8R4vbQXKbCkcSu26Wy2U0/4ca4dabb0305045fa5c3c786bf5d7592/mow.jpg"
190
+ }
191
+ }
192
+ },
193
+ "sys": {
194
+ "id": "8R4vbQXKbCkcSu26Wy2U0",
195
+ "type": "Asset",
196
+ "createdAt": "2014-08-19T07:25:10.104Z",
197
+ "createdBy": {
198
+ "sys": {
199
+ "type": "Link",
200
+ "linkType": "User",
201
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
202
+ }
203
+ },
204
+ "space": {
205
+ "sys": {
206
+ "type": "Link",
207
+ "linkType": "Space",
208
+ "id": "bfsvtul0c41g"
209
+ }
210
+ },
211
+ "firstPublishedAt": "2014-08-19T07:25:32.234Z",
212
+ "publishedCounter": 1,
213
+ "publishedAt": "2014-08-19T07:25:32.234Z",
214
+ "publishedBy": {
215
+ "sys": {
216
+ "type": "Link",
217
+ "linkType": "User",
218
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
219
+ }
220
+ },
221
+ "publishedVersion": 11,
222
+ "version": 14,
223
+ "updatedAt": "2014-08-19T10:09:26.237Z",
224
+ "updatedBy": {
225
+ "sys": {
226
+ "type": "Link",
227
+ "linkType": "User",
228
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
229
+ }
230
+ }
231
+ }
232
+ }
233
+ http_version:
234
+ recorded_at: Tue, 19 Aug 2014 10:10:30 GMT
235
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,217 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/v2umtz8ths9v/content_types/category_content_type
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContenfulManagementGem/0.1.0
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Content-Length:
17
+ - '0'
18
+ Host:
19
+ - api.contentful.com
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ "^access-Control-Expose-Headers":
26
+ - Etag
27
+ Access-Control-Allow-Headers:
28
+ - 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
29
+ Access-Control-Allow-Methods:
30
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Max-Age:
34
+ - '1728000'
35
+ Cf-Space-Id:
36
+ - v2umtz8ths9v
37
+ Content-Type:
38
+ - application/vnd.contentful.management.v1+json
39
+ Date:
40
+ - Tue, 02 Sep 2014 08:15:34 GMT
41
+ Etag:
42
+ - '"391c3aafd988f750695ae5676d7130d6"'
43
+ Server:
44
+ - nginx
45
+ X-Powered-By:
46
+ - Express
47
+ Content-Length:
48
+ - '1254'
49
+ Connection:
50
+ - keep-alive
51
+ body:
52
+ encoding: UTF-8
53
+ string: |
54
+ {
55
+ "displayField": "name",
56
+ "name": "Category",
57
+ "description": "",
58
+ "fields": [
59
+ {
60
+ "id": "name",
61
+ "name": "Name",
62
+ "type": "Text",
63
+ "localized": true,
64
+ "uiid": "3ic0t3qi51c"
65
+ },
66
+ {
67
+ "id": "description",
68
+ "name": "Description",
69
+ "type": "Text",
70
+ "localized": false,
71
+ "uiid": "38xiq8fobnk"
72
+ }
73
+ ],
74
+ "sys": {
75
+ "id": "category_content_type",
76
+ "type": "ContentType",
77
+ "createdAt": "2014-08-21T13:32:20.955Z",
78
+ "createdBy": {
79
+ "sys": {
80
+ "type": "Link",
81
+ "linkType": "User",
82
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
83
+ }
84
+ },
85
+ "space": {
86
+ "sys": {
87
+ "type": "Link",
88
+ "linkType": "Space",
89
+ "id": "v2umtz8ths9v"
90
+ }
91
+ },
92
+ "firstPublishedAt": "2014-08-21T13:32:27.109Z",
93
+ "publishedCounter": 6,
94
+ "publishedAt": "2014-09-02T07:13:04.738Z",
95
+ "publishedBy": {
96
+ "sys": {
97
+ "type": "Link",
98
+ "linkType": "User",
99
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
100
+ }
101
+ },
102
+ "publishedVersion": 17,
103
+ "version": 18,
104
+ "updatedAt": "2014-09-02T07:13:04.749Z",
105
+ "updatedBy": {
106
+ "sys": {
107
+ "type": "Link",
108
+ "linkType": "User",
109
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
110
+ }
111
+ }
112
+ }
113
+ }
114
+ http_version:
115
+ recorded_at: Tue, 02 Sep 2014 08:16:05 GMT
116
+ - request:
117
+ method: post
118
+ uri: https://api.contentful.com/spaces/v2umtz8ths9v/entries/
119
+ body:
120
+ encoding: UTF-8
121
+ string: '{"fields":{"name":{"en-US":"Contentful EN","de-DE":"Contentful DE","pl-PL":"Contentful
122
+ PL"},"description":{"en-US":"Description EN"}}}'
123
+ headers:
124
+ User-Agent:
125
+ - RubyContenfulManagementGem/0.1.0
126
+ Authorization:
127
+ - Bearer <ACCESS_TOKEN>
128
+ Content-Type:
129
+ - application/vnd.contentful.management.v1+json
130
+ X-Contentful-Content-Type:
131
+ - category_content_type
132
+ Host:
133
+ - api.contentful.com
134
+ response:
135
+ status:
136
+ code: 201
137
+ message: Created
138
+ headers:
139
+ "^access-Control-Expose-Headers":
140
+ - Etag
141
+ Access-Control-Allow-Headers:
142
+ - 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
143
+ Access-Control-Allow-Methods:
144
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
145
+ Access-Control-Allow-Origin:
146
+ - "*"
147
+ Access-Control-Max-Age:
148
+ - '1728000'
149
+ Cf-Space-Id:
150
+ - v2umtz8ths9v
151
+ Content-Type:
152
+ - application/vnd.contentful.management.v1+json
153
+ Date:
154
+ - Tue, 02 Sep 2014 08:15:35 GMT
155
+ Etag:
156
+ - '"31fdedb609685a76a992f08ab55226a6"'
157
+ Server:
158
+ - nginx
159
+ X-Powered-By:
160
+ - Express
161
+ Content-Length:
162
+ - '932'
163
+ Connection:
164
+ - keep-alive
165
+ body:
166
+ encoding: UTF-8
167
+ string: |
168
+ {
169
+ "fields": {
170
+ "name": {
171
+ "en-US": "Contentful EN",
172
+ "de-DE": "Contentful DE",
173
+ "pl-PL": "Contentful PL"
174
+ },
175
+ "description": {
176
+ "en-US": "Description EN"
177
+ }
178
+ },
179
+ "sys": {
180
+ "id": "3SxjTVeUF2AEKg6kQQS4MG",
181
+ "type": "Entry",
182
+ "version": 1,
183
+ "createdAt": "2014-09-02T08:15:35.205Z",
184
+ "createdBy": {
185
+ "sys": {
186
+ "type": "Link",
187
+ "linkType": "User",
188
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
189
+ }
190
+ },
191
+ "space": {
192
+ "sys": {
193
+ "type": "Link",
194
+ "linkType": "Space",
195
+ "id": "v2umtz8ths9v"
196
+ }
197
+ },
198
+ "contentType": {
199
+ "sys": {
200
+ "type": "Link",
201
+ "linkType": "ContentType",
202
+ "id": "category_content_type"
203
+ }
204
+ },
205
+ "updatedAt": "2014-09-02T08:15:35.205Z",
206
+ "updatedBy": {
207
+ "sys": {
208
+ "type": "Link",
209
+ "linkType": "User",
210
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
211
+ }
212
+ }
213
+ }
214
+ }
215
+ http_version:
216
+ recorded_at: Tue, 02 Sep 2014 08:16:06 GMT
217
+ recorded_with: VCR 2.9.2