contentful-management 0.0.1.pre

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.
Files changed (188) hide show
  1. data/.gitignore +24 -0
  2. data/.reek +3 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +16 -0
  5. data/.travis.yml +9 -0
  6. data/CHANGELOG.md +2 -0
  7. data/Gemfile +13 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +408 -0
  10. data/Rakefile +37 -0
  11. data/bin/cma-console +8 -0
  12. data/contentful-management.gemspec +33 -0
  13. data/examples/blog.rb +82 -0
  14. data/examples/content_types.rb +45 -0
  15. data/examples/create_space.rb +35 -0
  16. data/lib/contentful/management.rb +12 -0
  17. data/lib/contentful/management/array.rb +35 -0
  18. data/lib/contentful/management/asset.rb +163 -0
  19. data/lib/contentful/management/client.rb +160 -0
  20. data/lib/contentful/management/content_type.rb +180 -0
  21. data/lib/contentful/management/dynamic_entry.rb +71 -0
  22. data/lib/contentful/management/entry.rb +213 -0
  23. data/lib/contentful/management/error.rb +62 -0
  24. data/lib/contentful/management/field.rb +34 -0
  25. data/lib/contentful/management/file.rb +15 -0
  26. data/lib/contentful/management/http_client.rb +22 -0
  27. data/lib/contentful/management/link.rb +23 -0
  28. data/lib/contentful/management/locale.rb +48 -0
  29. data/lib/contentful/management/location.rb +15 -0
  30. data/lib/contentful/management/request.rb +82 -0
  31. data/lib/contentful/management/resource.rb +166 -0
  32. data/lib/contentful/management/resource/array_like.rb +37 -0
  33. data/lib/contentful/management/resource/fields.rb +69 -0
  34. data/lib/contentful/management/resource/refresher.rb +21 -0
  35. data/lib/contentful/management/resource/system_properties.rb +56 -0
  36. data/lib/contentful/management/resource_builder.rb +269 -0
  37. data/lib/contentful/management/response.rb +72 -0
  38. data/lib/contentful/management/space.rb +159 -0
  39. data/lib/contentful/management/support.rb +24 -0
  40. data/lib/contentful/management/version.rb +6 -0
  41. data/spec/fixtures/vcr_cassettes/array_page_1.yml +1337 -0
  42. data/spec/fixtures/vcr_cassettes/asset/all.yml +611 -0
  43. data/spec/fixtures/vcr_cassettes/asset/archive.yml +228 -0
  44. data/spec/fixtures/vcr_cassettes/asset/archive_published.yml +177 -0
  45. data/spec/fixtures/vcr_cassettes/asset/archived_false.yml +228 -0
  46. data/spec/fixtures/vcr_cassettes/asset/archived_true.yml +228 -0
  47. data/spec/fixtures/vcr_cassettes/asset/create.yml +150 -0
  48. data/spec/fixtures/vcr_cassettes/asset/create_with_already_used_id.yml +56 -0
  49. data/spec/fixtures/vcr_cassettes/asset/create_with_custom_id.yml +150 -0
  50. data/spec/fixtures/vcr_cassettes/asset/destroy.yml +159 -0
  51. data/spec/fixtures/vcr_cassettes/asset/destroy_published.yml +175 -0
  52. data/spec/fixtures/vcr_cassettes/asset/find.yml +108 -0
  53. data/spec/fixtures/vcr_cassettes/asset/find_not_found.yml +64 -0
  54. data/spec/fixtures/vcr_cassettes/asset/image_url.yml +133 -0
  55. data/spec/fixtures/vcr_cassettes/asset/locale.yml +110 -0
  56. data/spec/fixtures/vcr_cassettes/asset/publish.yml +228 -0
  57. data/spec/fixtures/vcr_cassettes/asset/publish_already_published.yml +176 -0
  58. data/spec/fixtures/vcr_cassettes/asset/published_false.yml +228 -0
  59. data/spec/fixtures/vcr_cassettes/asset/published_true.yml +226 -0
  60. data/spec/fixtures/vcr_cassettes/asset/save_update.yml +242 -0
  61. data/spec/fixtures/vcr_cassettes/asset/set_locale.yml +110 -0
  62. data/spec/fixtures/vcr_cassettes/asset/unarchive.yml +228 -0
  63. data/spec/fixtures/vcr_cassettes/asset/unarchive_already_unarchive.yml +168 -0
  64. data/spec/fixtures/vcr_cassettes/asset/unarchive_already_unarchived.yml +168 -0
  65. data/spec/fixtures/vcr_cassettes/asset/unpublish.yml +228 -0
  66. data/spec/fixtures/vcr_cassettes/asset/unpublish_already_unpublished.yml +168 -0
  67. data/spec/fixtures/vcr_cassettes/asset/update_file.yml +207 -0
  68. data/spec/fixtures/vcr_cassettes/asset/update_to_specified_locale.yml +224 -0
  69. data/spec/fixtures/vcr_cassettes/asset/update_with_default_locale_without_file.yml +214 -0
  70. data/spec/fixtures/vcr_cassettes/content_type/activate.yml +246 -0
  71. data/spec/fixtures/vcr_cassettes/content_type/activate_with_invalid_version.yml +186 -0
  72. data/spec/fixtures/vcr_cassettes/content_type/activated_false.yml +246 -0
  73. data/spec/fixtures/vcr_cassettes/content_type/activated_true.yml +257 -0
  74. data/spec/fixtures/vcr_cassettes/content_type/all.yml +190 -0
  75. data/spec/fixtures/vcr_cassettes/content_type/create.yml +87 -0
  76. data/spec/fixtures/vcr_cassettes/content_type/create_content_type_with_id.yml +87 -0
  77. data/spec/fixtures/vcr_cassettes/content_type/create_with_Array_field.yml +94 -0
  78. data/spec/fixtures/vcr_cassettes/content_type/create_with_Boolean_field.yml +94 -0
  79. data/spec/fixtures/vcr_cassettes/content_type/create_with_Date_field.yml +94 -0
  80. data/spec/fixtures/vcr_cassettes/content_type/create_with_Integer_field.yml +94 -0
  81. data/spec/fixtures/vcr_cassettes/content_type/create_with_Link_field.yml +95 -0
  82. data/spec/fixtures/vcr_cassettes/content_type/create_with_Location_field.yml +94 -0
  83. data/spec/fixtures/vcr_cassettes/content_type/create_with_Number_field.yml +94 -0
  84. data/spec/fixtures/vcr_cassettes/content_type/create_with_Object_field.yml +94 -0
  85. data/spec/fixtures/vcr_cassettes/content_type/create_with_Symbol_field.yml +94 -0
  86. data/spec/fixtures/vcr_cassettes/content_type/create_with_Text_field.yml +94 -0
  87. data/spec/fixtures/vcr_cassettes/content_type/deactivate.yml +246 -0
  88. data/spec/fixtures/vcr_cassettes/content_type/deactivate_already_deactivated.yml +176 -0
  89. data/spec/fixtures/vcr_cassettes/content_type/deactivate_with_entries.yml +236 -0
  90. data/spec/fixtures/vcr_cassettes/content_type/deactivate_with_version_change.yml +248 -0
  91. data/spec/fixtures/vcr_cassettes/content_type/destroy.yml +148 -0
  92. data/spec/fixtures/vcr_cassettes/content_type/destroy_activated.yml +164 -0
  93. data/spec/fixtures/vcr_cassettes/content_type/entry/create.yml +1344 -0
  94. data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_camel_case_id_to_multiple_locales.yml +235 -0
  95. data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_entries.yml +398 -0
  96. data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_entries_for_multiple_locales.yml +3157 -0
  97. data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_multiple_locales.yml +230 -0
  98. data/spec/fixtures/vcr_cassettes/content_type/fields/add.yml +345 -0
  99. data/spec/fixtures/vcr_cassettes/content_type/fields/create.yml +353 -0
  100. data/spec/fixtures/vcr_cassettes/content_type/fields/create_array_with_params.yml +228 -0
  101. data/spec/fixtures/vcr_cassettes/content_type/fields/create_with_params.yml +221 -0
  102. data/spec/fixtures/vcr_cassettes/content_type/fields/destroy.yml +349 -0
  103. data/spec/fixtures/vcr_cassettes/content_type/fields/update_field.yml +358 -0
  104. data/spec/fixtures/vcr_cassettes/content_type/find.yml +180 -0
  105. data/spec/fixtures/vcr_cassettes/content_type/find_not_found.yml +64 -0
  106. data/spec/fixtures/vcr_cassettes/content_type/save_new.yml +876 -0
  107. data/spec/fixtures/vcr_cassettes/content_type/save_updated.yml +345 -0
  108. data/spec/fixtures/vcr_cassettes/content_type/save_with_added_field.yml +217 -0
  109. data/spec/fixtures/vcr_cassettes/content_type/update.yml +175 -0
  110. data/spec/fixtures/vcr_cassettes/content_type/update_change_field_name.yml +222 -0
  111. data/spec/fixtures/vcr_cassettes/content_type/update_remove_field.yml +231 -0
  112. data/spec/fixtures/vcr_cassettes/content_type/update_with_fields.yml +222 -0
  113. data/spec/fixtures/vcr_cassettes/content_type/update_with_one_new_field.yml +251 -0
  114. data/spec/fixtures/vcr_cassettes/entry/all.yml +139 -0
  115. data/spec/fixtures/vcr_cassettes/entry/archive.yml +222 -0
  116. data/spec/fixtures/vcr_cassettes/entry/archive_published.yml +187 -0
  117. data/spec/fixtures/vcr_cassettes/entry/archived_false.yml +178 -0
  118. data/spec/fixtures/vcr_cassettes/entry/archived_true.yml +248 -0
  119. data/spec/fixtures/vcr_cassettes/entry/create.yml +245 -0
  120. data/spec/fixtures/vcr_cassettes/entry/create_test.yml +150 -0
  121. data/spec/fixtures/vcr_cassettes/entry/create_with_asset.yml +403 -0
  122. data/spec/fixtures/vcr_cassettes/entry/create_with_assets.yml +419 -0
  123. data/spec/fixtures/vcr_cassettes/entry/create_with_entries.yml +418 -0
  124. data/spec/fixtures/vcr_cassettes/entry/create_with_entry.yml +493 -0
  125. data/spec/fixtures/vcr_cassettes/entry/create_with_location.yml +259 -0
  126. data/spec/fixtures/vcr_cassettes/entry/create_with_symbols.yml +271 -0
  127. data/spec/fixtures/vcr_cassettes/entry/destory_published.yml +172 -0
  128. data/spec/fixtures/vcr_cassettes/entry/destroy.yml +156 -0
  129. data/spec/fixtures/vcr_cassettes/entry/find.yml +129 -0
  130. data/spec/fixtures/vcr_cassettes/entry/find_not_found.yml +64 -0
  131. data/spec/fixtures/vcr_cassettes/entry/publish.yml +248 -0
  132. data/spec/fixtures/vcr_cassettes/entry/publish_already_published.yml +186 -0
  133. data/spec/fixtures/vcr_cassettes/entry/published_false.yml +248 -0
  134. data/spec/fixtures/vcr_cassettes/entry/published_true.yml +257 -0
  135. data/spec/fixtures/vcr_cassettes/entry/save_update.yml +211 -0
  136. data/spec/fixtures/vcr_cassettes/entry/unarchive.yml +248 -0
  137. data/spec/fixtures/vcr_cassettes/entry/unarchive_already_unarchived.yml +178 -0
  138. data/spec/fixtures/vcr_cassettes/entry/unpublish.yml +248 -0
  139. data/spec/fixtures/vcr_cassettes/entry/unpublish_already_unpublished.yml +178 -0
  140. data/spec/fixtures/vcr_cassettes/entry/update.yml +626 -0
  141. data/spec/fixtures/vcr_cassettes/entry/update_unlocalized_field.yml +308 -0
  142. data/spec/fixtures/vcr_cassettes/entry/update_with_custom_locale.yml +332 -0
  143. data/spec/fixtures/vcr_cassettes/get_request.yml +37 -0
  144. data/spec/fixtures/vcr_cassettes/locale/all_for_space.yml +321 -0
  145. data/spec/fixtures/vcr_cassettes/locale/create_for_space.yml +95 -0
  146. data/spec/fixtures/vcr_cassettes/locale/find.yml +95 -0
  147. data/spec/fixtures/vcr_cassettes/locale/find_for_space_not_found.yml +67 -0
  148. data/spec/fixtures/vcr_cassettes/space/all.yml +1201 -0
  149. data/spec/fixtures/vcr_cassettes/space/asset/all.yml +475 -0
  150. data/spec/fixtures/vcr_cassettes/space/asset/assets.yml +826 -0
  151. data/spec/fixtures/vcr_cassettes/space/asset/create.yml +508 -0
  152. data/spec/fixtures/vcr_cassettes/space/asset/create_with_multiple_locales.yml +1062 -0
  153. data/spec/fixtures/vcr_cassettes/space/asset/find.yml +634 -0
  154. data/spec/fixtures/vcr_cassettes/space/content_type/all.yml +470 -0
  155. data/spec/fixtures/vcr_cassettes/space/content_type/content_types.yml +341 -0
  156. data/spec/fixtures/vcr_cassettes/space/content_type/create.yml +425 -0
  157. data/spec/fixtures/vcr_cassettes/space/content_type/find.yml +493 -0
  158. data/spec/fixtures/vcr_cassettes/space/create.yml +85 -0
  159. data/spec/fixtures/vcr_cassettes/space/create_when_limit_has_been_reached.yml +67 -0
  160. data/spec/fixtures/vcr_cassettes/space/create_with_unknown_organization.yml +65 -0
  161. data/spec/fixtures/vcr_cassettes/space/create_without_organization.yml +83 -0
  162. data/spec/fixtures/vcr_cassettes/space/destory.yml +196 -0
  163. data/spec/fixtures/vcr_cassettes/space/entry/all.yml +634 -0
  164. data/spec/fixtures/vcr_cassettes/space/entry/entries.yml +498 -0
  165. data/spec/fixtures/vcr_cassettes/space/entry/find.yml +624 -0
  166. data/spec/fixtures/vcr_cassettes/space/find.yml +270 -0
  167. data/spec/fixtures/vcr_cassettes/space/find_not_found.yml +67 -0
  168. data/spec/fixtures/vcr_cassettes/space/locale/all.yml +690 -0
  169. data/spec/fixtures/vcr_cassettes/space/locale/create.yml +572 -0
  170. data/spec/fixtures/vcr_cassettes/space/locale/create_with_the_same_code.yml +585 -0
  171. data/spec/fixtures/vcr_cassettes/space/locale/find.yml +572 -0
  172. data/spec/fixtures/vcr_cassettes/space/locale/find_not_found.yml +580 -0
  173. data/spec/fixtures/vcr_cassettes/space/locale/locales.yml +480 -0
  174. data/spec/fixtures/vcr_cassettes/space/locale/update.yml +700 -0
  175. data/spec/fixtures/vcr_cassettes/space/save_new_space.yml +67 -0
  176. data/spec/fixtures/vcr_cassettes/space/save_update_space.yml +352 -0
  177. data/spec/fixtures/vcr_cassettes/space/update.yml +350 -0
  178. data/spec/fixtures/vcr_cassettes/space/update_with_the_same_data.yml +350 -0
  179. data/spec/lib/contentful/management/array_spec.rb +59 -0
  180. data/spec/lib/contentful/management/asset_spec.rb +321 -0
  181. data/spec/lib/contentful/management/client_spec.rb +80 -0
  182. data/spec/lib/contentful/management/content_type_spec.rb +455 -0
  183. data/spec/lib/contentful/management/entry_spec.rb +308 -0
  184. data/spec/lib/contentful/management/locale_spec.rb +53 -0
  185. data/spec/lib/contentful/management/space_spec.rb +317 -0
  186. data/spec/spec_helper.rb +10 -0
  187. data/spec/support/vcr.rb +17 -0
  188. metadata +554 -0
@@ -0,0 +1,350 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/yr5m0jky5hsh
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContenfulManagementGem/0.0.1
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
+ - Thu, 31 Jul 2014 07:04:33 GMT
29
+ Content-Type:
30
+ - application/vnd.contentful.management.v1+json
31
+ Content-Length:
32
+ - '453'
33
+ Connection:
34
+ - keep-alive
35
+ Status:
36
+ - 200 OK
37
+ X-Contentful-Request-Id:
38
+ - 85f-1334431262
39
+ Etag:
40
+ - '"cbeabcb3476920c3f3a426f8cf41795d"'
41
+ Accept-Ranges:
42
+ - bytes
43
+ Cache-Control:
44
+ - max-age=0
45
+ Access-Control-Allow-Origin:
46
+ - "*"
47
+ Access-Control-Allow-Headers:
48
+ - 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
49
+ Access-Control-Allow-Methods:
50
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
51
+ "^access-Control-Expose-Headers":
52
+ - Etag
53
+ Access-Control-Max-Age:
54
+ - '1728000'
55
+ body:
56
+ encoding: UTF-8
57
+ string: |
58
+ {
59
+ "sys":{
60
+ "type":"Space",
61
+ "id":"yr5m0jky5hsh",
62
+ "version":8,
63
+ "createdBy":{
64
+ "sys":{
65
+ "type":"Link",
66
+ "linkType":"User",
67
+ "id":"0fn5fOWn4WsKFyYla1gI5h"
68
+ }
69
+ },
70
+ "createdAt":"2014-07-30T07:46:19Z",
71
+ "updatedBy":{
72
+ "sys":{
73
+ "type":"Link",
74
+ "linkType":"User",
75
+ "id":"1E7acJL8I5XUXAMHQt9Grs"
76
+ }
77
+ },
78
+ "updatedAt":"2014-07-31T07:04:29Z"
79
+ },
80
+ "name":"NewNameSpace"}
81
+ http_version:
82
+ recorded_at: Thu, 31 Jul 2014 07:04:34 GMT
83
+ - request:
84
+ method: get
85
+ uri: https://api.contentful.com/spaces/yr5m0jky5hsh/content_types
86
+ body:
87
+ encoding: US-ASCII
88
+ string: ''
89
+ headers:
90
+ User-Agent:
91
+ - RubyContenfulManagementGem/0.0.1
92
+ Authorization:
93
+ - Bearer <ACCESS_TOKEN>
94
+ Content-Type:
95
+ - application/vnd.contentful.management.v1+json
96
+ Content-Length:
97
+ - '0'
98
+ Host:
99
+ - api.contentful.com
100
+ response:
101
+ status:
102
+ code: 200
103
+ message: OK
104
+ headers:
105
+ Server:
106
+ - nginx
107
+ Date:
108
+ - Thu, 31 Jul 2014 07:04:34 GMT
109
+ Content-Type:
110
+ - application/vnd.contentful.management.v1+json
111
+ Content-Length:
112
+ - '3054'
113
+ Connection:
114
+ - keep-alive
115
+ X-Powered-By:
116
+ - Express
117
+ Cf-Space-Id:
118
+ - yr5m0jky5hsh
119
+ Etag:
120
+ - '"4c43b6e34924f7e65971295370191384"'
121
+ Access-Control-Allow-Origin:
122
+ - "*"
123
+ Access-Control-Allow-Headers:
124
+ - 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
125
+ Access-Control-Allow-Methods:
126
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
127
+ "^access-Control-Expose-Headers":
128
+ - Etag
129
+ Access-Control-Max-Age:
130
+ - '1728000'
131
+ body:
132
+ encoding: UTF-8
133
+ string: |
134
+ {
135
+ "sys": {
136
+ "type": "Array"
137
+ },
138
+ "total": 1,
139
+ "skip": 0,
140
+ "limit": 100,
141
+ "items": [
142
+ {
143
+ "fields": [
144
+ {
145
+ "name": "name",
146
+ "id": "name",
147
+ "type": "Text",
148
+ "uiid": "3fflnrplhc0",
149
+ "localized": true
150
+ },
151
+ {
152
+ "name": "age",
153
+ "id": "age",
154
+ "uiid": "2t5blkc7u2o",
155
+ "type": "Integer",
156
+ "localized": true
157
+ },
158
+ {
159
+ "name": "city",
160
+ "id": "city",
161
+ "type": "Location",
162
+ "uiid": "4fzl5jkm1a8",
163
+ "localized": false
164
+ },
165
+ {
166
+ "name": "assets",
167
+ "id": "assets",
168
+ "uiid": "3aqrgdyesxs",
169
+ "type": "Array",
170
+ "items": {
171
+ "type": "Link",
172
+ "linkType": "Asset"
173
+ },
174
+ "localized": true
175
+ },
176
+ {
177
+ "name": "entries",
178
+ "id": "entries",
179
+ "type": "Array",
180
+ "uiid": "3xi486kbchs",
181
+ "items": {
182
+ "type": "Link",
183
+ "linkType": "Entry"
184
+ }
185
+ },
186
+ {
187
+ "name": "entry",
188
+ "id": "entry",
189
+ "type": "Link",
190
+ "uiid": "3uxjdd1n5ds",
191
+ "linkType": "Entry"
192
+ },
193
+ {
194
+ "name": "asset",
195
+ "id": "asset",
196
+ "type": "Link",
197
+ "uiid": "40ilp8h1xc0",
198
+ "linkType": "Asset"
199
+ },
200
+ {
201
+ "name": "bool",
202
+ "id": "bool",
203
+ "type": "Boolean",
204
+ "uiid": "2i1bgmn2dj4",
205
+ "localized": true
206
+ },
207
+ {
208
+ "name": "symbols",
209
+ "id": "symbols",
210
+ "type": "Array",
211
+ "uiid": "38rbncxmzuo",
212
+ "items": {
213
+ "type": "Symbol"
214
+ }
215
+ },
216
+ {
217
+ "name": "birthday",
218
+ "id": "birthday",
219
+ "type": "Date",
220
+ "uiid": "41bdwbk06bk"
221
+ }
222
+ ],
223
+ "name": "Author",
224
+ "sys": {
225
+ "id": "5DSpuKrl04eMAGQoQckeIq",
226
+ "type": "ContentType",
227
+ "createdAt": "2014-07-30T12:35:01.110Z",
228
+ "createdBy": {
229
+ "sys": {
230
+ "type": "Link",
231
+ "linkType": "User",
232
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
233
+ }
234
+ },
235
+ "space": {
236
+ "sys": {
237
+ "type": "Link",
238
+ "linkType": "Space",
239
+ "id": "yr5m0jky5hsh"
240
+ }
241
+ },
242
+ "firstPublishedAt": "2014-07-30T12:37:42.035Z",
243
+ "publishedCounter": 6,
244
+ "publishedAt": "2014-07-30T14:58:40.786Z",
245
+ "publishedBy": {
246
+ "sys": {
247
+ "type": "Link",
248
+ "linkType": "User",
249
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
250
+ }
251
+ },
252
+ "publishedVersion": 177,
253
+ "version": 178,
254
+ "updatedAt": "2014-07-30T14:58:40.796Z",
255
+ "updatedBy": {
256
+ "sys": {
257
+ "type": "Link",
258
+ "linkType": "User",
259
+ "id": "1E7acJL8I5XUXAMHQt9Grs"
260
+ }
261
+ }
262
+ },
263
+ "description": null,
264
+ "displayField": "name"
265
+ }
266
+ ]
267
+ }
268
+ http_version:
269
+ recorded_at: Thu, 31 Jul 2014 07:04:35 GMT
270
+ - request:
271
+ method: put
272
+ uri: https://api.contentful.com/spaces/yr5m0jky5hsh
273
+ body:
274
+ encoding: UTF-8
275
+ string: '{"name":"NewNameSpace"}'
276
+ headers:
277
+ User-Agent:
278
+ - RubyContenfulManagementGem/0.0.1
279
+ Authorization:
280
+ - Bearer <ACCESS_TOKEN>
281
+ Content-Type:
282
+ - application/vnd.contentful.management.v1+json
283
+ X-Contentful-Version:
284
+ - '8'
285
+ Host:
286
+ - api.contentful.com
287
+ response:
288
+ status:
289
+ code: 200
290
+ message: OK
291
+ headers:
292
+ Server:
293
+ - nginx
294
+ Date:
295
+ - Thu, 31 Jul 2014 07:04:35 GMT
296
+ Content-Type:
297
+ - application/vnd.contentful.management.v1+json
298
+ Content-Length:
299
+ - '453'
300
+ Connection:
301
+ - keep-alive
302
+ Status:
303
+ - 200 OK
304
+ X-Contentful-Request-Id:
305
+ - 85f-1334431267
306
+ Etag:
307
+ - '"cbeabcb3476920c3f3a426f8cf41795d"'
308
+ Accept-Ranges:
309
+ - bytes
310
+ Cache-Control:
311
+ - max-age=0
312
+ Access-Control-Allow-Origin:
313
+ - "*"
314
+ Access-Control-Allow-Headers:
315
+ - 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
316
+ Access-Control-Allow-Methods:
317
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
318
+ "^access-Control-Expose-Headers":
319
+ - Etag
320
+ Access-Control-Max-Age:
321
+ - '1728000'
322
+ body:
323
+ encoding: UTF-8
324
+ string: |
325
+ {
326
+ "sys":{
327
+ "type":"Space",
328
+ "id":"yr5m0jky5hsh",
329
+ "version":8,
330
+ "createdBy":{
331
+ "sys":{
332
+ "type":"Link",
333
+ "linkType":"User",
334
+ "id":"0fn5fOWn4WsKFyYla1gI5h"
335
+ }
336
+ },
337
+ "createdAt":"2014-07-30T07:46:19Z",
338
+ "updatedBy":{
339
+ "sys":{
340
+ "type":"Link",
341
+ "linkType":"User",
342
+ "id":"1E7acJL8I5XUXAMHQt9Grs"
343
+ }
344
+ },
345
+ "updatedAt":"2014-07-31T07:04:29Z"
346
+ },
347
+ "name":"NewNameSpace"}
348
+ http_version:
349
+ recorded_at: Thu, 31 Jul 2014 07:04:35 GMT
350
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'contentful/management/space'
3
+ require 'contentful/management/client'
4
+
5
+ describe Contentful::Management::Array do
6
+ let(:token) { '<ACCESS_TOKEN>' }
7
+ let(:space_id) { 'yr5m0jky5hsh' }
8
+ let!(:client) { Contentful::Management::Client.new(token) }
9
+ let(:array) { vcr('space/all') { Contentful::Management::Space.all } }
10
+
11
+ describe 'SystemProperties' do
12
+ it 'has a #sys getter returning a hash with symbol keys' do
13
+ expect(array.sys).to be_a Hash
14
+ expect(array.sys.keys.sample).to be_a Symbol
15
+ end
16
+
17
+ it 'has #type' do
18
+ expect(array.type).to eq 'Array'
19
+ end
20
+ end
21
+
22
+ describe 'Properties' do
23
+ it 'has a #properties getter returning a hash with symbol keys' do
24
+ expect(array.properties).to be_a Hash
25
+ expect(array.properties.keys.sample).to be_a Symbol
26
+ end
27
+
28
+ it 'has #total' do
29
+ expect(array.total).to eq 6
30
+ end
31
+
32
+ it 'has #skip' do
33
+ expect(array.skip).to eq 0
34
+ end
35
+
36
+ it 'has #limit' do
37
+ expect(array.limit).to eq 25
38
+ end
39
+
40
+ it 'has #items which contain resources' do
41
+ expect(array.items).to be_a Array
42
+ expect(array.items.sample).to be_a Contentful::Management::Resource
43
+ end
44
+ end
45
+
46
+ describe '#each' do
47
+ it 'is an Enumerator' do
48
+ expect(array.each).to be_a Enumerator
49
+ end
50
+
51
+ it 'iterates over items' do
52
+ expect(array.each.to_a).to eq array.items
53
+ end
54
+
55
+ it 'includes Enumerable' do
56
+ expect(array.map { |r| r.type }).to eq array.items.map { |r| r.type }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,321 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'contentful/management/space'
4
+ require 'contentful/management/client'
5
+ require 'contentful/management/asset'
6
+
7
+ module Contentful
8
+ module Management
9
+ describe Asset do
10
+ let(:token) { '<ACCESS_TOKEN>' }
11
+ let(:space_id) { 'yr5m0jky5hsh' }
12
+
13
+ let(:asset_id) { '3PYa73pXXiAmKqm8eu4qOS' }
14
+ let(:asset_id_2) { '5FDqplZoruAUGmiSa02asE' }
15
+
16
+ let!(:client) { Client.new(token) }
17
+
18
+ subject { Contentful::Management::Asset }
19
+
20
+ describe '.all' do
21
+ it 'returns a Contentful::Array' do
22
+ vcr('asset/all') { expect(subject.all(space_id)).to be_kind_of Contentful::Management::Array }
23
+ end
24
+ it 'builds a Contentful::Management::Asset object' do
25
+ vcr('asset/all') { expect(subject.all(space_id).first).to be_kind_of Contentful::Management::Asset }
26
+ end
27
+ end
28
+
29
+ describe '#find' do
30
+ it 'returns a Contentful::Management::Asset' do
31
+ vcr('asset/find') { expect(subject.find(space_id, asset_id)).to be_kind_of Contentful::Management::Asset }
32
+ end
33
+ it 'returns the asset for a given key' do
34
+ vcr('asset/find') do
35
+ asset = subject.find(space_id, asset_id)
36
+ expect(asset.id).to eql asset_id
37
+ end
38
+ end
39
+ it 'returns an error when content_type does not exists' do
40
+ vcr('asset/find_not_found') do
41
+ result = subject.find(space_id, 'not_exist')
42
+ expect(result).to be_kind_of Contentful::Management::NotFound
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#destroy' do
48
+ it 'returns Contentful::BadRequest error when content type is published' do
49
+ vcr('asset/destroy_published') do
50
+ result = subject.find(space_id, 'r7o2iuDeSc4UmioOuoKq6').destroy
51
+ expect(result).to be_kind_of Contentful::Management::BadRequest
52
+ expect(result.message).to eq 'Cannot deleted published'
53
+ end
54
+ end
55
+ it 'returns true when asset is not published' do
56
+ vcr('asset/destroy') do
57
+ result = subject.find(space_id, 'r7o2iuDeSc4UmioOuoKq6').destroy
58
+ expect(result).to eq true
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '#unpublish' do
64
+ it 'unpublish' do
65
+ vcr('asset/unpublish') do
66
+ asset = subject.find(space_id, asset_id_2)
67
+ initial_version = asset.sys[:version]
68
+ asset.unpublish
69
+ expect(asset).to be_kind_of Contentful::Management::Asset
70
+ expect(asset.sys[:version]).to eql initial_version + 1
71
+ end
72
+ end
73
+
74
+ it 'returns BadRequest error when already unpublished' do
75
+ vcr('asset/unpublish_already_unpublished') do
76
+ result = subject.find(space_id, asset_id_2).unpublish
77
+ expect(result).to be_kind_of Contentful::Management::BadRequest
78
+ expect(result.message).to eq 'Not published'
79
+ end
80
+ end
81
+ end
82
+
83
+ describe '#publish' do
84
+ it 'returns Contentful::Management::Asset' do
85
+ vcr('asset/publish') do
86
+ asset = subject.find(space_id, asset_id_2)
87
+ initial_version = asset.sys[:version]
88
+ asset.publish
89
+ expect(asset).to be_kind_of Contentful::Management::Asset
90
+ expect(asset.sys[:version]).to eql initial_version + 1
91
+ end
92
+ end
93
+ it 'returns BadRequest error when already published' do
94
+ vcr('asset/publish_already_published') do
95
+ asset = subject.find(space_id, asset_id_2)
96
+ asset.sys[:version] = -1
97
+ result = asset.publish
98
+ expect(result).to be_kind_of Contentful::Management::BadRequest
99
+ end
100
+ end
101
+ end
102
+
103
+ describe '#published?' do
104
+ it 'returns true if asset is published' do
105
+ vcr('asset/published_true') do
106
+ asset = subject.find(space_id, asset_id)
107
+ asset.publish
108
+ expect(asset.published?).to be_truthy
109
+ end
110
+ end
111
+ it 'returns false if asset is not published' do
112
+ vcr('asset/published_false') do
113
+ asset = subject.find(space_id, asset_id)
114
+ asset.unpublish
115
+ expect(asset.published?).to be_falsey
116
+ end
117
+ end
118
+ end
119
+
120
+ describe '#unarchive' do
121
+ it 'unarchive the asset' do
122
+ vcr('asset/unarchive') do
123
+ asset = subject.find(space_id, asset_id_2)
124
+ initial_version = asset.sys[:version]
125
+ asset.unarchive
126
+ expect(asset).to be_kind_of Contentful::Management::Asset
127
+ expect(asset.sys[:version]).to eql initial_version + 1
128
+ end
129
+ end
130
+
131
+ it 'returns BadRequest error when already unpublished' do
132
+ vcr('asset/unarchive_already_unarchived') do
133
+ result = subject.find(space_id, asset_id_2).unarchive
134
+ expect(result).to be_kind_of Contentful::Management::BadRequest
135
+ end
136
+ end
137
+ end
138
+
139
+ describe '#archive' do
140
+ it 'returns error when archive published asset' do
141
+ vcr('asset/archive_published') do
142
+ asset = subject.find(space_id, asset_id_2).archive
143
+ expect(asset).to be_kind_of Contentful::Management::BadRequest
144
+ end
145
+ end
146
+
147
+ it ' archive unpublished asset' do
148
+ vcr('asset/archive') do
149
+ asset = subject.find(space_id, asset_id_2)
150
+ initial_version = asset.sys[:version]
151
+ asset.archive
152
+ expect(asset).to be_kind_of Contentful::Management::Asset
153
+ expect(asset.sys[:version]).to eql initial_version + 1
154
+ end
155
+ end
156
+
157
+ it 'returns BadRequest error when already unpublished' do
158
+ vcr('asset/unarchive_already_unarchive') do
159
+ result = subject.find(space_id, asset_id_2).unarchive
160
+ expect(result).to be_kind_of Contentful::Management::BadRequest
161
+ end
162
+ end
163
+ end
164
+
165
+ describe '#archived?' do
166
+ it 'returns true if asset is archive' do
167
+ vcr('asset/archived_true') do
168
+ asset = subject.find(space_id, asset_id_2)
169
+ asset.archive
170
+ expect(asset.archived?).to be_truthy
171
+ end
172
+ end
173
+ it 'returns false if asset is not archive' do
174
+ vcr('asset/archived_false') do
175
+ asset = subject.find(space_id, asset_id_2)
176
+ asset.unarchive
177
+ expect(asset.archived?).to be_falsey
178
+ end
179
+ end
180
+ end
181
+
182
+ describe '#locale' do
183
+ it 'returns default locale' do
184
+ vcr('asset/locale') do
185
+ asset = subject.find(space_id, asset_id_2)
186
+ expect(asset.locale).to eq asset.default_locale
187
+ expect(asset.title).to eq 'titlebyCreateAPI'
188
+ expect(asset.description).to eq 'descByAPI'
189
+ end
190
+ end
191
+
192
+ it 'set locale to given asset' do
193
+ vcr('asset/set_locale') do
194
+ asset = subject.find(space_id, asset_id_2)
195
+ asset.locale = 'pl-Pl'
196
+ expect(asset.sys[:locale]).to eq 'pl-Pl'
197
+ end
198
+ end
199
+ end
200
+
201
+ describe '.create' do
202
+ it 'creates asset ' do
203
+ vcr('asset/create') do
204
+
205
+ file1 = Contentful::Management::File.new
206
+ file1.properties[:contentType] = 'image/jpeg'
207
+ file1.properties[:fileName] = 'pic1.jpg'
208
+ file1.properties[:upload] = 'https://upload.wikimedia.org/wikipedia/commons/c/c7/Gasometer_Berlin_Sch%C3%B6neberg_2011.jpg'
209
+
210
+ asset = Contentful::Management::Asset.create(space_id, title: 'titlebyCreateAPI', description: 'descByAPI', file: file1)
211
+ expect(asset).to be_kind_of Contentful::Management::Asset
212
+ expect(asset.title).to eq 'titlebyCreateAPI'
213
+ expect(asset.description).to eq 'descByAPI'
214
+ end
215
+ end
216
+
217
+ it 'creates asset with custom ID' do
218
+ vcr('asset/create_with_custom_id') do
219
+ file = Contentful::Management::File.new
220
+
221
+ file.properties[:contentType] = 'image/jpeg'
222
+ file.properties[:fileName] = 'codequest.jpg'
223
+ file.properties[:upload] = 'http://static.goldenline.pl/firm_logo/082/firm_225106_22f37f_small.jpg'
224
+
225
+ asset = Contentful::Management::Asset.create(space_id, id: 'codequest_id_test_custom', title: 'titlebyCreateAPI_custom_id', description: 'descByAPI_custom_id', file: file)
226
+ expect(asset).to be_kind_of Contentful::Management::Asset
227
+ expect(asset.id).to eq 'codequest_id_test_custom'
228
+ expect(asset.title).to eq 'titlebyCreateAPI_custom_id'
229
+ expect(asset.description).to eq 'descByAPI_custom_id'
230
+ end
231
+ end
232
+ it 'creates asset with duplicated custom ID' do
233
+ vcr('asset/create_with_already_used_id') do
234
+ file = Contentful::Management::File.new
235
+
236
+ file.properties[:contentType] = 'image/jpeg'
237
+ file.properties[:fileName] = 'codequest.jpg'
238
+ file.properties[:upload] = 'http://static.goldenline.pl/firm_logo/082/firm_225106_22f37f_small.jpg'
239
+
240
+ asset = Contentful::Management::Asset.create(space_id, id: 'codequest_id_test_custom_id', title: 'titlebyCreateAPI_custom_id', description: 'descByAPI_custom_id', file: file)
241
+ expect(asset).to be_kind_of Contentful::Management::BadRequest
242
+ end
243
+ end
244
+ end
245
+
246
+ describe '#update' do
247
+ it 'updates asset with default locale without file' do
248
+ vcr('asset/update_with_default_locale_without_file') do
249
+ asset = subject.find(space_id, '4DmT2j54pWY8ocimkEU6qS')
250
+ asset.update(title: 'Title new', description: 'Description new')
251
+ expect(asset).to be_kind_of Contentful::Management::Asset
252
+ expect(asset.title).to eq 'Title new'
253
+ expect(asset.description).to eq 'Description new'
254
+ end
255
+ end
256
+
257
+ it 'updates asset with default locale with file' do
258
+ vcr('asset/update_file') do
259
+
260
+ file = Contentful::Management::File.new
261
+ file.properties[:contentType] = 'image/jpeg'
262
+ file.properties[:fileName] = 'codequest.jpg'
263
+ file.properties[:upload] = 'http://static.goldenline.pl/firm_logo/082/firm_225106_22f37f_small.jpg'
264
+
265
+ asset = subject.find(space_id, '4DmT2j54pWY8ocimkEU6qS')
266
+ asset.update(file: file)
267
+ expect(asset).to be_kind_of Contentful::Management::Asset
268
+ expect(asset.file.properties[:fileName]).to eq 'codequest.jpg'
269
+ end
270
+ end
271
+
272
+ it 'updates asset to specified locale' do
273
+ vcr('asset/update_to_specified_locale') do
274
+ file = Contentful::Management::File.new
275
+ file.properties[:contentType] = 'image/jpeg'
276
+ file.properties[:fileName] = 'codequest.jpg'
277
+ file.properties[:upload] = 'http://static.goldenline.pl/firm_logo/082/firm_225106_22f37f_small.jpg'
278
+
279
+ asset = subject.find(space_id, 'codequest_id_test_custom_id')
280
+ asset.locale = 'pl'
281
+
282
+ asset.update(title: 'updateTitlePl', description: 'updateDescPl', file: file)
283
+ expect(asset).to be_kind_of Contentful::Management::Asset
284
+ asset.locale = 'pl'
285
+ expect(asset.title).to eq 'updateTitlePl'
286
+ expect(asset.description).to eq 'updateDescPl'
287
+ expect(asset.file.properties[:fileName]).to eq 'codequest.jpg'
288
+ end
289
+ end
290
+ end
291
+ describe '#save' do
292
+ it 'updated' do
293
+ vcr('asset/save_update') do
294
+ asset = Contentful::Management::Asset.find(space_id, '35Kt2tInIsoauo8sC82q04')
295
+ asset.fields[:description] = 'Firmowe logo.'
296
+ asset.save
297
+ expect(asset).to be_kind_of Contentful::Management::Asset
298
+ expect(asset.fields[:description]).to eq 'Firmowe logo.'
299
+ end
300
+ end
301
+ end
302
+ describe '#image_url' do
303
+ it 'empty_query' do
304
+ vcr('asset/image_url') do
305
+ asset = Contentful::Management::Asset.find(space_id, '35Kt2tInIsoauo8sC82q04')
306
+ asset.image_url
307
+ expect(asset).to be_kind_of Contentful::Management::Asset
308
+ end
309
+ end
310
+ it 'with_params' do
311
+ vcr('asset/image_url') do
312
+ asset = Contentful::Management::Asset.find(space_id, '35Kt2tInIsoauo8sC82q04')
313
+ asset.image_url(w: 111, h: 11)
314
+ expect(asset).to be_kind_of Contentful::Management::Asset
315
+ end
316
+ end
317
+ end
318
+
319
+ end
320
+ end
321
+ end