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.
- data/.gitignore +24 -0
- data/.reek +3 -0
- data/.rspec +3 -0
- data/.rubocop.yml +16 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +408 -0
- data/Rakefile +37 -0
- data/bin/cma-console +8 -0
- data/contentful-management.gemspec +33 -0
- data/examples/blog.rb +82 -0
- data/examples/content_types.rb +45 -0
- data/examples/create_space.rb +35 -0
- data/lib/contentful/management.rb +12 -0
- data/lib/contentful/management/array.rb +35 -0
- data/lib/contentful/management/asset.rb +163 -0
- data/lib/contentful/management/client.rb +160 -0
- data/lib/contentful/management/content_type.rb +180 -0
- data/lib/contentful/management/dynamic_entry.rb +71 -0
- data/lib/contentful/management/entry.rb +213 -0
- data/lib/contentful/management/error.rb +62 -0
- data/lib/contentful/management/field.rb +34 -0
- data/lib/contentful/management/file.rb +15 -0
- data/lib/contentful/management/http_client.rb +22 -0
- data/lib/contentful/management/link.rb +23 -0
- data/lib/contentful/management/locale.rb +48 -0
- data/lib/contentful/management/location.rb +15 -0
- data/lib/contentful/management/request.rb +82 -0
- data/lib/contentful/management/resource.rb +166 -0
- data/lib/contentful/management/resource/array_like.rb +37 -0
- data/lib/contentful/management/resource/fields.rb +69 -0
- data/lib/contentful/management/resource/refresher.rb +21 -0
- data/lib/contentful/management/resource/system_properties.rb +56 -0
- data/lib/contentful/management/resource_builder.rb +269 -0
- data/lib/contentful/management/response.rb +72 -0
- data/lib/contentful/management/space.rb +159 -0
- data/lib/contentful/management/support.rb +24 -0
- data/lib/contentful/management/version.rb +6 -0
- data/spec/fixtures/vcr_cassettes/array_page_1.yml +1337 -0
- data/spec/fixtures/vcr_cassettes/asset/all.yml +611 -0
- data/spec/fixtures/vcr_cassettes/asset/archive.yml +228 -0
- data/spec/fixtures/vcr_cassettes/asset/archive_published.yml +177 -0
- data/spec/fixtures/vcr_cassettes/asset/archived_false.yml +228 -0
- data/spec/fixtures/vcr_cassettes/asset/archived_true.yml +228 -0
- data/spec/fixtures/vcr_cassettes/asset/create.yml +150 -0
- data/spec/fixtures/vcr_cassettes/asset/create_with_already_used_id.yml +56 -0
- data/spec/fixtures/vcr_cassettes/asset/create_with_custom_id.yml +150 -0
- data/spec/fixtures/vcr_cassettes/asset/destroy.yml +159 -0
- data/spec/fixtures/vcr_cassettes/asset/destroy_published.yml +175 -0
- data/spec/fixtures/vcr_cassettes/asset/find.yml +108 -0
- data/spec/fixtures/vcr_cassettes/asset/find_not_found.yml +64 -0
- data/spec/fixtures/vcr_cassettes/asset/image_url.yml +133 -0
- data/spec/fixtures/vcr_cassettes/asset/locale.yml +110 -0
- data/spec/fixtures/vcr_cassettes/asset/publish.yml +228 -0
- data/spec/fixtures/vcr_cassettes/asset/publish_already_published.yml +176 -0
- data/spec/fixtures/vcr_cassettes/asset/published_false.yml +228 -0
- data/spec/fixtures/vcr_cassettes/asset/published_true.yml +226 -0
- data/spec/fixtures/vcr_cassettes/asset/save_update.yml +242 -0
- data/spec/fixtures/vcr_cassettes/asset/set_locale.yml +110 -0
- data/spec/fixtures/vcr_cassettes/asset/unarchive.yml +228 -0
- data/spec/fixtures/vcr_cassettes/asset/unarchive_already_unarchive.yml +168 -0
- data/spec/fixtures/vcr_cassettes/asset/unarchive_already_unarchived.yml +168 -0
- data/spec/fixtures/vcr_cassettes/asset/unpublish.yml +228 -0
- data/spec/fixtures/vcr_cassettes/asset/unpublish_already_unpublished.yml +168 -0
- data/spec/fixtures/vcr_cassettes/asset/update_file.yml +207 -0
- data/spec/fixtures/vcr_cassettes/asset/update_to_specified_locale.yml +224 -0
- data/spec/fixtures/vcr_cassettes/asset/update_with_default_locale_without_file.yml +214 -0
- data/spec/fixtures/vcr_cassettes/content_type/activate.yml +246 -0
- data/spec/fixtures/vcr_cassettes/content_type/activate_with_invalid_version.yml +186 -0
- data/spec/fixtures/vcr_cassettes/content_type/activated_false.yml +246 -0
- data/spec/fixtures/vcr_cassettes/content_type/activated_true.yml +257 -0
- data/spec/fixtures/vcr_cassettes/content_type/all.yml +190 -0
- data/spec/fixtures/vcr_cassettes/content_type/create.yml +87 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_content_type_with_id.yml +87 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Array_field.yml +94 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Boolean_field.yml +94 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Date_field.yml +94 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Integer_field.yml +94 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Link_field.yml +95 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Location_field.yml +94 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Number_field.yml +94 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Object_field.yml +94 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Symbol_field.yml +94 -0
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Text_field.yml +94 -0
- data/spec/fixtures/vcr_cassettes/content_type/deactivate.yml +246 -0
- data/spec/fixtures/vcr_cassettes/content_type/deactivate_already_deactivated.yml +176 -0
- data/spec/fixtures/vcr_cassettes/content_type/deactivate_with_entries.yml +236 -0
- data/spec/fixtures/vcr_cassettes/content_type/deactivate_with_version_change.yml +248 -0
- data/spec/fixtures/vcr_cassettes/content_type/destroy.yml +148 -0
- data/spec/fixtures/vcr_cassettes/content_type/destroy_activated.yml +164 -0
- data/spec/fixtures/vcr_cassettes/content_type/entry/create.yml +1344 -0
- data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_camel_case_id_to_multiple_locales.yml +235 -0
- data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_entries.yml +398 -0
- data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_entries_for_multiple_locales.yml +3157 -0
- data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_multiple_locales.yml +230 -0
- data/spec/fixtures/vcr_cassettes/content_type/fields/add.yml +345 -0
- data/spec/fixtures/vcr_cassettes/content_type/fields/create.yml +353 -0
- data/spec/fixtures/vcr_cassettes/content_type/fields/create_array_with_params.yml +228 -0
- data/spec/fixtures/vcr_cassettes/content_type/fields/create_with_params.yml +221 -0
- data/spec/fixtures/vcr_cassettes/content_type/fields/destroy.yml +349 -0
- data/spec/fixtures/vcr_cassettes/content_type/fields/update_field.yml +358 -0
- data/spec/fixtures/vcr_cassettes/content_type/find.yml +180 -0
- data/spec/fixtures/vcr_cassettes/content_type/find_not_found.yml +64 -0
- data/spec/fixtures/vcr_cassettes/content_type/save_new.yml +876 -0
- data/spec/fixtures/vcr_cassettes/content_type/save_updated.yml +345 -0
- data/spec/fixtures/vcr_cassettes/content_type/save_with_added_field.yml +217 -0
- data/spec/fixtures/vcr_cassettes/content_type/update.yml +175 -0
- data/spec/fixtures/vcr_cassettes/content_type/update_change_field_name.yml +222 -0
- data/spec/fixtures/vcr_cassettes/content_type/update_remove_field.yml +231 -0
- data/spec/fixtures/vcr_cassettes/content_type/update_with_fields.yml +222 -0
- data/spec/fixtures/vcr_cassettes/content_type/update_with_one_new_field.yml +251 -0
- data/spec/fixtures/vcr_cassettes/entry/all.yml +139 -0
- data/spec/fixtures/vcr_cassettes/entry/archive.yml +222 -0
- data/spec/fixtures/vcr_cassettes/entry/archive_published.yml +187 -0
- data/spec/fixtures/vcr_cassettes/entry/archived_false.yml +178 -0
- data/spec/fixtures/vcr_cassettes/entry/archived_true.yml +248 -0
- data/spec/fixtures/vcr_cassettes/entry/create.yml +245 -0
- data/spec/fixtures/vcr_cassettes/entry/create_test.yml +150 -0
- data/spec/fixtures/vcr_cassettes/entry/create_with_asset.yml +403 -0
- data/spec/fixtures/vcr_cassettes/entry/create_with_assets.yml +419 -0
- data/spec/fixtures/vcr_cassettes/entry/create_with_entries.yml +418 -0
- data/spec/fixtures/vcr_cassettes/entry/create_with_entry.yml +493 -0
- data/spec/fixtures/vcr_cassettes/entry/create_with_location.yml +259 -0
- data/spec/fixtures/vcr_cassettes/entry/create_with_symbols.yml +271 -0
- data/spec/fixtures/vcr_cassettes/entry/destory_published.yml +172 -0
- data/spec/fixtures/vcr_cassettes/entry/destroy.yml +156 -0
- data/spec/fixtures/vcr_cassettes/entry/find.yml +129 -0
- data/spec/fixtures/vcr_cassettes/entry/find_not_found.yml +64 -0
- data/spec/fixtures/vcr_cassettes/entry/publish.yml +248 -0
- data/spec/fixtures/vcr_cassettes/entry/publish_already_published.yml +186 -0
- data/spec/fixtures/vcr_cassettes/entry/published_false.yml +248 -0
- data/spec/fixtures/vcr_cassettes/entry/published_true.yml +257 -0
- data/spec/fixtures/vcr_cassettes/entry/save_update.yml +211 -0
- data/spec/fixtures/vcr_cassettes/entry/unarchive.yml +248 -0
- data/spec/fixtures/vcr_cassettes/entry/unarchive_already_unarchived.yml +178 -0
- data/spec/fixtures/vcr_cassettes/entry/unpublish.yml +248 -0
- data/spec/fixtures/vcr_cassettes/entry/unpublish_already_unpublished.yml +178 -0
- data/spec/fixtures/vcr_cassettes/entry/update.yml +626 -0
- data/spec/fixtures/vcr_cassettes/entry/update_unlocalized_field.yml +308 -0
- data/spec/fixtures/vcr_cassettes/entry/update_with_custom_locale.yml +332 -0
- data/spec/fixtures/vcr_cassettes/get_request.yml +37 -0
- data/spec/fixtures/vcr_cassettes/locale/all_for_space.yml +321 -0
- data/spec/fixtures/vcr_cassettes/locale/create_for_space.yml +95 -0
- data/spec/fixtures/vcr_cassettes/locale/find.yml +95 -0
- data/spec/fixtures/vcr_cassettes/locale/find_for_space_not_found.yml +67 -0
- data/spec/fixtures/vcr_cassettes/space/all.yml +1201 -0
- data/spec/fixtures/vcr_cassettes/space/asset/all.yml +475 -0
- data/spec/fixtures/vcr_cassettes/space/asset/assets.yml +826 -0
- data/spec/fixtures/vcr_cassettes/space/asset/create.yml +508 -0
- data/spec/fixtures/vcr_cassettes/space/asset/create_with_multiple_locales.yml +1062 -0
- data/spec/fixtures/vcr_cassettes/space/asset/find.yml +634 -0
- data/spec/fixtures/vcr_cassettes/space/content_type/all.yml +470 -0
- data/spec/fixtures/vcr_cassettes/space/content_type/content_types.yml +341 -0
- data/spec/fixtures/vcr_cassettes/space/content_type/create.yml +425 -0
- data/spec/fixtures/vcr_cassettes/space/content_type/find.yml +493 -0
- data/spec/fixtures/vcr_cassettes/space/create.yml +85 -0
- data/spec/fixtures/vcr_cassettes/space/create_when_limit_has_been_reached.yml +67 -0
- data/spec/fixtures/vcr_cassettes/space/create_with_unknown_organization.yml +65 -0
- data/spec/fixtures/vcr_cassettes/space/create_without_organization.yml +83 -0
- data/spec/fixtures/vcr_cassettes/space/destory.yml +196 -0
- data/spec/fixtures/vcr_cassettes/space/entry/all.yml +634 -0
- data/spec/fixtures/vcr_cassettes/space/entry/entries.yml +498 -0
- data/spec/fixtures/vcr_cassettes/space/entry/find.yml +624 -0
- data/spec/fixtures/vcr_cassettes/space/find.yml +270 -0
- data/spec/fixtures/vcr_cassettes/space/find_not_found.yml +67 -0
- data/spec/fixtures/vcr_cassettes/space/locale/all.yml +690 -0
- data/spec/fixtures/vcr_cassettes/space/locale/create.yml +572 -0
- data/spec/fixtures/vcr_cassettes/space/locale/create_with_the_same_code.yml +585 -0
- data/spec/fixtures/vcr_cassettes/space/locale/find.yml +572 -0
- data/spec/fixtures/vcr_cassettes/space/locale/find_not_found.yml +580 -0
- data/spec/fixtures/vcr_cassettes/space/locale/locales.yml +480 -0
- data/spec/fixtures/vcr_cassettes/space/locale/update.yml +700 -0
- data/spec/fixtures/vcr_cassettes/space/save_new_space.yml +67 -0
- data/spec/fixtures/vcr_cassettes/space/save_update_space.yml +352 -0
- data/spec/fixtures/vcr_cassettes/space/update.yml +350 -0
- data/spec/fixtures/vcr_cassettes/space/update_with_the_same_data.yml +350 -0
- data/spec/lib/contentful/management/array_spec.rb +59 -0
- data/spec/lib/contentful/management/asset_spec.rb +321 -0
- data/spec/lib/contentful/management/client_spec.rb +80 -0
- data/spec/lib/contentful/management/content_type_spec.rb +455 -0
- data/spec/lib/contentful/management/entry_spec.rb +308 -0
- data/spec/lib/contentful/management/locale_spec.rb +53 -0
- data/spec/lib/contentful/management/space_spec.rb +317 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/vcr.rb +17 -0
- metadata +554 -0
data/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.o
|
|
21
|
+
*.a
|
|
22
|
+
mkmf.log
|
|
23
|
+
.idea
|
|
24
|
+
.idea/**/*
|
data/.reek
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Andreas Tiefenthaler
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
# Contentful::Management
|
|
2
|
+
|
|
3
|
+
Ruby client for the Contentful Content Management API.
|
|
4
|
+
|
|
5
|
+
Contentful is a content management platform for web applications, mobile apps and connected devices. It allows you to create, edit & manage content in the cloud and publish it anywhere via powerful API. Contentful offers tools for managing editorial teams and enabling cooperation between organizations.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
gem 'contentful-management'
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Client
|
|
16
|
+
|
|
17
|
+
At the beginning the API client instance should be created for each thread that is going to be used in your application:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
client = Contentful::Management::Client.new('access_token')
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The access token can easily be created through the [management api documentation](https://www.contentful.com/developers/documentation/content-management-api/#getting-started).
|
|
24
|
+
|
|
25
|
+
### Spaces
|
|
26
|
+
|
|
27
|
+
Retrieving all spaces:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
spaces = Contentful::Management::Space.all
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Retrieving one space by id:
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
blog_space = Contentful::Management::Space.find('blog_space_id')
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Destroying a space:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
blog_space.destroy
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Creating a space:
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
blog_space = Contentful::Management::Space.new
|
|
49
|
+
blog_space.name = 'Blog Space'
|
|
50
|
+
blog_space.save
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
or
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
blog_space = Contentful::Management::Space.create(name: 'Blog Space')
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
or in the context of the organization (if you have multiple organizations within your account):
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
blog_space = Contentful::Management::Space.create(name: 'Blog Space', organization_id: 'organization_id')
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Updating a space:
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
blog_space.update(name: 'New Blog Space')
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
or
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
blog_space.name = 'New Blog Space'
|
|
75
|
+
blog_space.save
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Content Types
|
|
79
|
+
|
|
80
|
+
Retrieving all content types from a space:
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
blog_post_content_types = blog_space.content_types
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
or
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
blog_post_content_types = blog_space.content_types.all
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Retrieving one content type by id from a space:
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
blog_post_content_type = blog_space.content_types.find(id)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Creating a field for a content type:
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
title_field = Contentful::Management::Field.new
|
|
102
|
+
title_field.id = 'blog_post_title'
|
|
103
|
+
title_field.name = 'Post Title'
|
|
104
|
+
title_field.type = 'Text'
|
|
105
|
+
blog_post_content_type.fields.add(field)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
or
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
blog_post_content_type.fields.create(id: 'title_field_id', name: 'Post Title', type: 'Text')
|
|
112
|
+
```
|
|
113
|
+
- if the field_id exists, the related field will be updated.
|
|
114
|
+
|
|
115
|
+
or the field of an array type:
|
|
116
|
+
```ruby
|
|
117
|
+
items = Contentful::Management::Field.new
|
|
118
|
+
items.type = 'Link'
|
|
119
|
+
items.link_type = 'Entry'
|
|
120
|
+
blog_post_content_type.fields.create(id: 'my_array_field', name: 'My Array Field', type: 'Array', items: items)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Deleting a field from the content type:
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
blog_post_content_type.fields.destroy(title_field_id)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Creating a content type:
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
blog_space.content_types.create(name: 'Post', fields: [title_field, body_field])
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
or
|
|
136
|
+
|
|
137
|
+
```ruby
|
|
138
|
+
blog_post_content_type = blog_space.content_types.new
|
|
139
|
+
blog_post_content_type.name = 'Post'
|
|
140
|
+
blog_post_content_type.fields = [title_field, body_field]
|
|
141
|
+
blog_post_content_type.save
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Destroying a content type:
|
|
145
|
+
|
|
146
|
+
```ruby
|
|
147
|
+
blog_post_content_type.destroy
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Activating or deactivating a content type:
|
|
151
|
+
|
|
152
|
+
```ruby
|
|
153
|
+
blog_post_content_type.activate
|
|
154
|
+
blog_post_content_type.deactivate
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Checking if a content type is active:
|
|
158
|
+
|
|
159
|
+
```ruby
|
|
160
|
+
blog_post_content_type.active?
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Updating a content type:
|
|
164
|
+
|
|
165
|
+
```ruby
|
|
166
|
+
blog_post_content_type.update(name: 'Post', description: 'Post Description', fields: [title_field])
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Locales
|
|
170
|
+
|
|
171
|
+
Retrieving all locales from the space:
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
blog_post_locales = blog_space.locales
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
or
|
|
178
|
+
|
|
179
|
+
```ruby
|
|
180
|
+
blog_post_locales = blog_space.locales.all
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Retrieving one locale by the locale-id from the space:
|
|
184
|
+
|
|
185
|
+
```ruby
|
|
186
|
+
blog_post_locale = blog_space.locales.find(locale_id)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Creating a locale
|
|
190
|
+
```ruby
|
|
191
|
+
blog_space.locales.create(name: 'German', code: 'de-DE')
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Updating a locale
|
|
195
|
+
```ruby
|
|
196
|
+
blog_post_locale.update(name: 'German', code: 'de-DE')
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Assets
|
|
200
|
+
|
|
201
|
+
Retrieving all assets from the space:
|
|
202
|
+
|
|
203
|
+
```ruby
|
|
204
|
+
blog_post_assets = blog_space.assets
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
or
|
|
208
|
+
|
|
209
|
+
```ruby
|
|
210
|
+
blog_post_assets = blog_space.assets.all
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Retrieving an asset by id:
|
|
214
|
+
|
|
215
|
+
```ruby
|
|
216
|
+
blog_post_asset = blog_space.assets.find('asset_id')
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Creating a file:
|
|
220
|
+
|
|
221
|
+
```ruby
|
|
222
|
+
image_file = Contentful::Management::File.new
|
|
223
|
+
image_file.properties[:contentType] = 'image/jpeg'
|
|
224
|
+
image_file.properties[:fileName] = 'example.jpg'
|
|
225
|
+
image_file.properties[:upload] = 'http://www.example.com/example.jpg'
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Creating an asset:
|
|
229
|
+
|
|
230
|
+
```ruby
|
|
231
|
+
my_image_asset = blog_space.assets.create(title: 'My Image', description: 'My Image Description', file: image_file)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
or an asset with multiple locales
|
|
235
|
+
|
|
236
|
+
```ruby
|
|
237
|
+
my_image_localized_asset = space.assets.new
|
|
238
|
+
my_image_localized_asset.title_with_locales= {'en-US' => 'title', 'pl' => 'pl title'}
|
|
239
|
+
my_image_localized_asset.description_with_locales= {'en-US' => 'description', 'pl' => 'pl description'}
|
|
240
|
+
en_file = Contentful::Management::File.new
|
|
241
|
+
en_file.properties[:contentType] = 'image/jpeg'
|
|
242
|
+
en_file.properties[:fileName] = 'pic1.jpg'
|
|
243
|
+
en_file.properties[:upload] = 'http://www.example.com/pic1.jpg'
|
|
244
|
+
pl_file = Contentful::Management::File.new
|
|
245
|
+
pl_file.properties[:contentType] = 'image/jpeg'
|
|
246
|
+
pl_file.properties[:fileName] = 'pic2.jpg'
|
|
247
|
+
pl_file.properties[:upload] = 'http://www.example.com/pic2.jpg'
|
|
248
|
+
asset.file_with_locales= {'en-US' => en_file, 'pl' => pl_file}
|
|
249
|
+
asset.save
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Updating an asset:
|
|
253
|
+
|
|
254
|
+
- default locale
|
|
255
|
+
|
|
256
|
+
```ruby
|
|
257
|
+
my_image_asset.update(title: 'My Image', description: 'My Image Description', file: image_file)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
- another locale (we can switch locales for the object, so then all fields are in context of selected locale)
|
|
261
|
+
|
|
262
|
+
```ruby
|
|
263
|
+
my_image_asset.locale = 'nl'
|
|
264
|
+
my_image_asset.update(title: 'NL Title', description: 'NL Description', file: nl_image)
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
- field with multiple locales
|
|
268
|
+
|
|
269
|
+
```ruby
|
|
270
|
+
my_image_asset.title_with_locales = {'en-US' => 'US Title', 'nl' => 'NL Title'}
|
|
271
|
+
my_image_asset.save
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Destroying an asset:
|
|
275
|
+
|
|
276
|
+
```ruby
|
|
277
|
+
my_image_asset.destroy
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Archiving or unarchiving an asset:
|
|
281
|
+
|
|
282
|
+
```ruby
|
|
283
|
+
my_image_asset.archive
|
|
284
|
+
my_image_asset.unarchive
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Checking if an asset is archived:
|
|
288
|
+
|
|
289
|
+
```ruby
|
|
290
|
+
my_image_asset.archived?
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Publishing or unpublishing an asset:
|
|
294
|
+
|
|
295
|
+
```ruby
|
|
296
|
+
my_image_asset.publish
|
|
297
|
+
my_image_asset.unpublish
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Checking if an asset is published:
|
|
301
|
+
|
|
302
|
+
```ruby
|
|
303
|
+
my_image_asset.published?
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Entries
|
|
307
|
+
|
|
308
|
+
Retrieving all entries from the space:
|
|
309
|
+
|
|
310
|
+
```ruby
|
|
311
|
+
entries = blog_space.entries
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
or
|
|
315
|
+
|
|
316
|
+
```ruby
|
|
317
|
+
entries = blog_space.entries.all
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Retrieving an entry by id:
|
|
321
|
+
|
|
322
|
+
```ruby
|
|
323
|
+
entry = blog_space.entries.find('entry_id')
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Creating a location:
|
|
327
|
+
|
|
328
|
+
```ruby
|
|
329
|
+
location = Location.new
|
|
330
|
+
location.lat = 22.44
|
|
331
|
+
location.lon = 33.33
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Creating an entry:
|
|
335
|
+
- with a default locale
|
|
336
|
+
|
|
337
|
+
```ruby
|
|
338
|
+
my_entry = blog_post_content_type.entries.create(post_title: 'Title', assets_array_field: [image_asset_1, ...], entries_array_field: [entry_1, ...], location_field: location)
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
- with multiple locales
|
|
342
|
+
|
|
343
|
+
```ruby
|
|
344
|
+
my_entry = blog_post_content_type.entries.new
|
|
345
|
+
my_entry.post_title_with_locales = {'en-US' => 'EN Title', 'pl' => 'PL Title'}
|
|
346
|
+
my_entry.save
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Updating an entry:
|
|
350
|
+
- with a default locale
|
|
351
|
+
|
|
352
|
+
```ruby
|
|
353
|
+
my_entry.update(params)
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
- with another locale
|
|
357
|
+
```ruby
|
|
358
|
+
entry.locale = 'nl'
|
|
359
|
+
entry.update(params)
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
- with multiple locales
|
|
363
|
+
|
|
364
|
+
```ruby
|
|
365
|
+
my_entry.post_title_with_locales = {'en-US' => 'EN Title', 'pl' => 'PL Title'}
|
|
366
|
+
my_entry.save
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
Destroying an entry:
|
|
370
|
+
|
|
371
|
+
```ruby
|
|
372
|
+
my_entry.destroy
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
Archiving or unarchiving the entry:
|
|
376
|
+
|
|
377
|
+
```ruby
|
|
378
|
+
my_entry.archive
|
|
379
|
+
my_entry.unarchive
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Checking if the entry is archived:
|
|
383
|
+
|
|
384
|
+
```ruby
|
|
385
|
+
my_entry.archived?
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Publishing or unpublishing the entry:
|
|
389
|
+
|
|
390
|
+
```ruby
|
|
391
|
+
my_entry.publish
|
|
392
|
+
my_entry.unpublish
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Checking if the entry is published:
|
|
396
|
+
|
|
397
|
+
```ruby
|
|
398
|
+
my_entry.published?
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
## Contributing
|
|
403
|
+
|
|
404
|
+
1. Fork it ( https://github.com/[my-github-username]/contentful-management/fork )
|
|
405
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
406
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
407
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
408
|
+
5. Create a new Pull Request
|