contentful-management 0.9.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +2 -2
- data/CHANGELOG.md +27 -3
- data/README.md +34 -7
- data/lib/contentful/management/api_key.rb +4 -43
- data/lib/contentful/management/array.rb +1 -2
- data/lib/contentful/management/asset.rb +29 -191
- data/lib/contentful/management/client.rb +96 -7
- data/lib/contentful/management/client_api_key_methods_factory.rb +15 -0
- data/lib/contentful/management/client_asset_methods_factory.rb +13 -0
- data/lib/contentful/management/client_association_all_published_method_factory.rb +21 -0
- data/lib/contentful/management/client_association_methods_factory.rb +54 -0
- data/lib/contentful/management/client_content_type_methods_factory.rb +13 -0
- data/lib/contentful/management/client_entry_methods_factory.rb +21 -0
- data/lib/contentful/management/client_locale_methods_factory.rb +15 -0
- data/lib/contentful/management/client_space_methods_factory.rb +58 -0
- data/lib/contentful/management/client_webhook_methods_factory.rb +15 -0
- data/lib/contentful/management/content_type.rb +30 -151
- data/lib/contentful/management/content_type_entry_methods_factory.rb +9 -3
- data/lib/contentful/management/dynamic_entry.rb +20 -39
- data/lib/contentful/management/entry.rb +47 -182
- data/lib/contentful/management/http_client.rb +41 -8
- data/lib/contentful/management/locale.rb +7 -76
- data/lib/contentful/management/request.rb +3 -3
- data/lib/contentful/management/resource.rb +105 -7
- data/lib/contentful/management/resource/all_published.rb +24 -0
- data/lib/contentful/management/resource/archiver.rb +37 -0
- data/lib/contentful/management/resource/field_aware.rb +49 -29
- data/lib/contentful/management/resource/publisher.rb +37 -0
- data/lib/contentful/management/resource/refresher.rb +1 -1
- data/lib/contentful/management/resource_builder.rb +8 -4
- data/lib/contentful/management/resource_requester.rb +96 -0
- data/lib/contentful/management/space.rb +40 -43
- data/lib/contentful/management/space_association_all_published_method_factory.rb +1 -1
- data/lib/contentful/management/space_association_methods_factory.rb +6 -3
- data/lib/contentful/management/space_entry_methods_factory.rb +1 -1
- data/lib/contentful/management/version.rb +1 -1
- data/lib/contentful/management/webhook.rb +9 -82
- data/spec/fixtures/vcr_cassettes/asset/create.yml +1 -1
- data/spec/fixtures/vcr_cassettes/asset/create_with_locale.yml +1 -1
- data/spec/fixtures/vcr_cassettes/asset/process.yml +1 -1
- data/spec/fixtures/vcr_cassettes/asset/publish_after_create.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Array_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Boolean_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Date_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Integer_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Link_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Location_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Number_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Object_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Symbol_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/create_with_Text_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/entry/create.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/entry/create_only_with_localized_fields.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/entry/create_to_single_locale_only_with_localized_fields.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_camel_case_id_to_multiple_locales.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_entries.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_entries_for_multiple_locales.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_multiple_locales.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/fields/create_array_types.yml +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/save_new.yml +1 -1
- data/spec/fixtures/vcr_cassettes/delete_request.yml +38 -0
- data/spec/fixtures/vcr_cassettes/entry/create.yml +1 -1
- data/spec/fixtures/vcr_cassettes/entry/create_with_asset.yml +1 -1
- data/spec/fixtures/vcr_cassettes/entry/create_with_assets.yml +1 -1
- data/spec/fixtures/vcr_cassettes/entry/create_with_entries.yml +1 -1
- data/spec/fixtures/vcr_cassettes/entry/create_with_entry.yml +1 -1
- data/spec/fixtures/vcr_cassettes/entry/create_with_just_id.yml +1 -1
- data/spec/fixtures/vcr_cassettes/entry/create_with_location.yml +1 -1
- data/spec/fixtures/vcr_cassettes/entry/create_with_specified_locale.yml +1 -1
- data/spec/fixtures/vcr_cassettes/entry/create_with_symbols.yml +1 -1
- data/spec/fixtures/vcr_cassettes/entry/too_many_requests.yml +1 -1
- data/spec/fixtures/vcr_cassettes/entry/update_bool_field.yml +1 -1
- data/spec/fixtures/vcr_cassettes/post_request.yml +64 -0
- data/spec/fixtures/vcr_cassettes/proxy_request.yml +562 -0
- data/spec/fixtures/vcr_cassettes/put_request.yml +40 -0
- data/spec/fixtures/vcr_cassettes/space/asset/create.yml +1 -1
- data/spec/fixtures/vcr_cassettes/space/asset/create_with_multiple_locales.yml +1 -1
- data/spec/fixtures/vcr_cassettes/space/content_type/create.yml +1 -1
- data/spec/fixtures/vcr_cassettes/space/create_with_client_default_locale.yml +197 -36
- data/spec/fixtures/vcr_cassettes/space/webhook/create.yml +1 -1
- data/spec/lib/contentful/management/api_key_spec.rb +7 -1
- data/spec/lib/contentful/management/array_spec.rb +1 -1
- data/spec/lib/contentful/management/asset_spec.rb +52 -32
- data/spec/lib/contentful/management/client_spec.rb +38 -0
- data/spec/lib/contentful/management/content_type_spec.rb +37 -22
- data/spec/lib/contentful/management/entry_spec.rb +68 -57
- data/spec/lib/contentful/management/locale_spec.rb +7 -1
- data/spec/lib/contentful/management/space_spec.rb +9 -3
- data/spec/lib/contentful/management/webhook_spec.rb +11 -5
- metadata +23 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4351225d59ca9af60725c79bd71d0717449e68e6
|
|
4
|
+
data.tar.gz: fd90f9d188c96f5446f9f920fe6272ca579a45b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc14898bf09f8bbf6f21324bb549708e887a4dc43e132cfe615ef06dc04cfd1f6736566675060aa613d3e6fbecca9017547b247f8c47465bb11979150c25d37e
|
|
7
|
+
data.tar.gz: da8832650d78644687acebd327c84ee7477f7b9013730af37d5815a7ee31804cb9c53a08fffb951e5ac7b3a39f7a6af4db03867529e2ad062b426b3a44b6daa6
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
# Offense count: 16
|
|
10
10
|
Metrics/AbcSize:
|
|
11
|
-
Max:
|
|
11
|
+
Max: 50
|
|
12
12
|
|
|
13
13
|
# Offense count: 4
|
|
14
14
|
Metrics/CyclomaticComplexity:
|
|
@@ -17,7 +17,7 @@ Metrics/CyclomaticComplexity:
|
|
|
17
17
|
# Offense count: 21
|
|
18
18
|
# Configuration parameters: CountComments.
|
|
19
19
|
Metrics/MethodLength:
|
|
20
|
-
Max:
|
|
20
|
+
Max: 48
|
|
21
21
|
|
|
22
22
|
# Offense count: 2
|
|
23
23
|
Metrics/PerceivedComplexity:
|
data/CHANGELOG.md
CHANGED
|
@@ -2,14 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
## Master
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
###
|
|
7
|
-
*
|
|
5
|
+
## 1.0.0
|
|
6
|
+
### Breaking Changes
|
|
7
|
+
* `Client` is no longer a singleton. Therefore all `Resource` class calls (`Entry`, `Space`, `ContentType`, etc...) require an instance of a client.
|
|
8
|
+
The Client needs to be the first parameter of the call. As sending the client in every call is not a great solution, a shorthand for every resource
|
|
9
|
+
class is present on the client. Calls can be done now like: `client.entries.all`. This works for every resource class, and all of the calls existing previously
|
|
10
|
+
(`all`, `find`, `create`, `all_published`). **Note: `all_published` is specific to `Entry`, `Asset` and `ContentType`**.
|
|
11
|
+
* You can have as many instances of client, for as many users as you want.
|
|
12
|
+
|
|
13
|
+
Complete List of resource links on `Client`:
|
|
14
|
+
* `#entries`
|
|
15
|
+
* `#assets`
|
|
16
|
+
* `#spaces`
|
|
17
|
+
* `#content_types`
|
|
18
|
+
* `#locales`
|
|
19
|
+
* `#webhooks`
|
|
20
|
+
* `#api_keys`
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
* Removed code duplication between FieldAware and DynamicEntry [#78](https://github.com/contentful/contentful-management.rb/issues/78)
|
|
25
|
+
* Refactored FieldAware code to be simplified
|
|
8
26
|
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
* Proxy Support [#88](https://github.com/contentful/contentful-management.rb/issues/88)
|
|
30
|
+
|
|
31
|
+
## 0.9.0
|
|
9
32
|
### Added
|
|
10
33
|
* Added `#destroy` method to Locales
|
|
11
34
|
* Added `ApiKey` class, methods and `Space` associations
|
|
12
35
|
* Added `.all_published` methods for `ContentType`, `Asset` and `Entry`
|
|
36
|
+
* Locales can now update `:code` value
|
|
13
37
|
|
|
14
38
|
### Changed
|
|
15
39
|
* Changed documentation format to YARD
|
data/README.md
CHANGED
|
@@ -32,13 +32,13 @@ The access token can easily be created through the [management api documentation
|
|
|
32
32
|
Retrieving all spaces:
|
|
33
33
|
|
|
34
34
|
```ruby
|
|
35
|
-
spaces =
|
|
35
|
+
spaces = client.spaces.all
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
Retrieving one space by id:
|
|
39
39
|
|
|
40
40
|
```ruby
|
|
41
|
-
blog_space =
|
|
41
|
+
blog_space = client.spaces.find('blog_space_id')
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Destroying a space:
|
|
@@ -50,7 +50,7 @@ blog_space.destroy
|
|
|
50
50
|
Creating a space:
|
|
51
51
|
|
|
52
52
|
```ruby
|
|
53
|
-
blog_space =
|
|
53
|
+
blog_space = client.spaces.new
|
|
54
54
|
blog_space.name = 'Blog Space'
|
|
55
55
|
blog_space.save
|
|
56
56
|
```
|
|
@@ -58,18 +58,18 @@ blog_space.save
|
|
|
58
58
|
or
|
|
59
59
|
|
|
60
60
|
```ruby
|
|
61
|
-
blog_space =
|
|
61
|
+
blog_space = client.spaces.create(name: 'Blog Space')
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
or in the context of the organization (if you have multiple organizations within your account):
|
|
65
65
|
|
|
66
66
|
```ruby
|
|
67
|
-
blog_space =
|
|
67
|
+
blog_space = client.spaces.create(name: 'Blog Space', organization_id: 'organization_id')
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
If you want to create a default locale different from `en-US`:
|
|
71
71
|
```ruby
|
|
72
|
-
blog_space =
|
|
72
|
+
blog_space = client.spaces.create(name: 'Blog Space', default_locale: 'de-DE')
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
Updating a space:
|
|
@@ -608,11 +608,38 @@ This allows for fetching Content Types for your Space at Client instantiation ti
|
|
|
608
608
|
To enable this, in your Client instantiation do:
|
|
609
609
|
|
|
610
610
|
```ruby
|
|
611
|
-
Contentful::Management::Client.new(token, dynamic_entries: ['my_space_id'])
|
|
611
|
+
client = Contentful::Management::Client.new(token, dynamic_entries: ['my_space_id'])
|
|
612
612
|
```
|
|
613
613
|
|
|
614
614
|
You can enable the Cache for as many Spaces as you want.
|
|
615
615
|
|
|
616
|
+
## Proxy Support
|
|
617
|
+
|
|
618
|
+
This allows for using the CMA SDK through a proxy, for this, your proxy must support HTTPS and your server must have a valid signed certificate.
|
|
619
|
+
|
|
620
|
+
To enable this, in your Client instantiation do:
|
|
621
|
+
|
|
622
|
+
```ruby
|
|
623
|
+
PROXY_HOST = 'localhost'
|
|
624
|
+
PROXY_PORT = 8888
|
|
625
|
+
|
|
626
|
+
# Just Host/Port
|
|
627
|
+
client = Contributing::Management::Client.new(
|
|
628
|
+
token,
|
|
629
|
+
proxy_host: PROXY_HOST,
|
|
630
|
+
proxy_port: PROXY_PORT
|
|
631
|
+
)
|
|
632
|
+
|
|
633
|
+
# With Username/Password
|
|
634
|
+
client = Contributing::Management::Client.new(
|
|
635
|
+
token,
|
|
636
|
+
proxy_host: PROXY_HOST,
|
|
637
|
+
proxy_port: PROXY_PORT,
|
|
638
|
+
proxy_username: 'YOUR_USERNAME',
|
|
639
|
+
proxy_password: 'YOUR_PASSWORD'
|
|
640
|
+
)
|
|
641
|
+
```
|
|
642
|
+
|
|
616
643
|
## Contributing
|
|
617
644
|
|
|
618
645
|
1. Fork it ( https://github.com/[my-github-username]/contentful-management/fork )
|
|
@@ -14,51 +14,12 @@ module Contentful
|
|
|
14
14
|
property :accessToken
|
|
15
15
|
property :policies
|
|
16
16
|
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# @param [Hash] _parameters the parameters for search query
|
|
21
|
-
# @option _parameters [String] :name The ApiKey name
|
|
22
|
-
# @option _parameters [String] :description The ApiKey description
|
|
23
|
-
#
|
|
24
|
-
# @return [Contentful::Management::Array<Contentful::Management::ApiKey>]
|
|
25
|
-
def self.all(space_id = nil, _parameters = {})
|
|
26
|
-
request = Request.new("/#{space_id}/api_keys")
|
|
27
|
-
response = request.get
|
|
28
|
-
result = ResourceBuilder.new(response, { 'ApiKey' => ApiKey }, {})
|
|
29
|
-
result.run
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Gets a specific api key.
|
|
33
|
-
#
|
|
34
|
-
# @param [String] space_id
|
|
35
|
-
# @param [String] api_key_id
|
|
36
|
-
#
|
|
37
|
-
# @return [Contentful::Management::ApiKey]
|
|
38
|
-
def self.find(space_id, api_key_id)
|
|
39
|
-
request = Request.new("/#{space_id}/api_keys/#{api_key_id}")
|
|
40
|
-
response = request.get
|
|
41
|
-
result = ResourceBuilder.new(response, { 'ApiKey' => ApiKey }, {})
|
|
42
|
-
result.run
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# Creates an api key.
|
|
46
|
-
#
|
|
47
|
-
# @param [String] space_id
|
|
48
|
-
# @param [Hash] attributes
|
|
49
|
-
# @option attributes [String] :name The ApiKey name
|
|
50
|
-
# @option attributes [String] :description The ApiKey description
|
|
51
|
-
#
|
|
52
|
-
# @return [Contentful::Management::ApiKey]
|
|
53
|
-
def self.create(space_id, attributes)
|
|
54
|
-
request = Request.new(
|
|
55
|
-
"/#{space_id}/api_keys",
|
|
17
|
+
# @private
|
|
18
|
+
def self.create_attributes(_client, attributes)
|
|
19
|
+
{
|
|
56
20
|
'name' => attributes.fetch(:name),
|
|
57
21
|
'description' => attributes.fetch(:description, nil)
|
|
58
|
-
|
|
59
|
-
response = request.post
|
|
60
|
-
result = ResourceBuilder.new(response, { 'ApiKey' => ApiKey }, {})
|
|
61
|
-
result.run
|
|
22
|
+
}
|
|
62
23
|
end
|
|
63
24
|
end
|
|
64
25
|
end
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
require_relative 'resource'
|
|
2
2
|
require_relative 'resource/asset_fields'
|
|
3
|
+
require_relative 'resource/all_published'
|
|
3
4
|
require_relative 'resource/fields'
|
|
5
|
+
require_relative 'resource/archiver'
|
|
6
|
+
require_relative 'resource/publisher'
|
|
4
7
|
|
|
5
8
|
module Contentful
|
|
6
9
|
module Management
|
|
@@ -9,80 +12,20 @@ module Contentful
|
|
|
9
12
|
class Asset
|
|
10
13
|
include Contentful::Management::Resource
|
|
11
14
|
extend Contentful::Management::Resource::AssetFields
|
|
15
|
+
extend Contentful::Management::Resource::AllPublished
|
|
12
16
|
include Contentful::Management::Resource::Fields
|
|
13
17
|
include Contentful::Management::Resource::SystemProperties
|
|
14
18
|
include Contentful::Management::Resource::Refresher
|
|
19
|
+
include Contentful::Management::Resource::Archiver
|
|
20
|
+
include Contentful::Management::Resource::Publisher
|
|
15
21
|
|
|
16
|
-
#
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# @param [Hash] query Search Options
|
|
20
|
-
# @see _ For complete option list: http://docs.contentfulcda.apiary.io/#reference/search-parameters
|
|
21
|
-
# @option query [String] 'sys.id' Asset ID
|
|
22
|
-
# @option query [String] :mimetype_group Kind of Asset
|
|
23
|
-
# @option query [Integer] :limit
|
|
24
|
-
# @option query [Integer] :skip
|
|
25
|
-
#
|
|
26
|
-
# @return [Contentful::Management::Array<Contentful::Management::Asset>]
|
|
27
|
-
def self.all(space_id, query = {})
|
|
28
|
-
request = Request.new(
|
|
29
|
-
"/#{space_id}/assets",
|
|
30
|
-
query
|
|
31
|
-
)
|
|
32
|
-
response = request.get
|
|
33
|
-
result = ResourceBuilder.new(response, {}, {})
|
|
34
|
-
result.run
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# Gets a collection of published assets.
|
|
38
|
-
#
|
|
39
|
-
# @param [String] space_id
|
|
40
|
-
# @param [Hash] query Search Options
|
|
41
|
-
# @see _ For complete option list: http://docs.contentfulcda.apiary.io/#reference/search-parameters
|
|
42
|
-
# @option query [String] 'sys.id' Asset ID
|
|
43
|
-
# @option query [String] :mimetype_group Kind of Asset
|
|
44
|
-
# @option query [Integer] :limit
|
|
45
|
-
# @option query [Integer] :skip
|
|
46
|
-
#
|
|
47
|
-
# @return [Contentful::Management::Array<Contentful::Management::Asset>]
|
|
48
|
-
def self.all_published(space_id, query = {})
|
|
49
|
-
request = Request.new(
|
|
50
|
-
"/#{space_id}/public/assets",
|
|
51
|
-
query
|
|
52
|
-
)
|
|
53
|
-
response = request.get
|
|
54
|
-
result = ResourceBuilder.new(response, {}, {})
|
|
55
|
-
result.run
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Gets a specific asset.
|
|
59
|
-
#
|
|
60
|
-
# @param [String] space_id
|
|
61
|
-
# @param [String] asset_id
|
|
62
|
-
#
|
|
63
|
-
# @return [Contentful::Management::Asset]
|
|
64
|
-
def self.find(space_id, asset_id)
|
|
65
|
-
request = Request.new("/#{space_id}/assets/#{asset_id}")
|
|
66
|
-
response = request.get
|
|
67
|
-
result = ResourceBuilder.new(response, {}, {})
|
|
68
|
-
result.run
|
|
22
|
+
# @private
|
|
23
|
+
def self.client_association_class
|
|
24
|
+
ClientAssetMethodsFactory
|
|
69
25
|
end
|
|
70
26
|
|
|
71
|
-
#
|
|
72
|
-
|
|
73
|
-
# @param [String] space_id
|
|
74
|
-
# @param [Hash] attributes
|
|
75
|
-
# @option attributes [String] :title
|
|
76
|
-
# @option attributes [String] :description
|
|
77
|
-
# @option attributes [Contentful::Management::File] :file
|
|
78
|
-
# @option attributes [String] :locale
|
|
79
|
-
# @option attributes [Hash] :fields
|
|
80
|
-
#
|
|
81
|
-
# @see _ README for more information on how to create an Asset
|
|
82
|
-
#
|
|
83
|
-
# @return [Contentful::Management::Asset]
|
|
84
|
-
def self.create(space_id, attributes)
|
|
85
|
-
locale = attributes[:locale]
|
|
27
|
+
# @private
|
|
28
|
+
def self.create_attributes(client, attributes)
|
|
86
29
|
asset = new
|
|
87
30
|
asset.instance_variable_set(:@fields, attributes[:fields] || {})
|
|
88
31
|
asset.locale = attributes[:locale] || client.default_locale
|
|
@@ -90,14 +33,12 @@ module Contentful
|
|
|
90
33
|
asset.description = attributes[:description] if attributes[:description]
|
|
91
34
|
asset.file = attributes[:file] if attributes[:file]
|
|
92
35
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
result.locale = locale if locale
|
|
100
|
-
result
|
|
36
|
+
{ fields: asset.fields_for_query }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @private
|
|
40
|
+
def after_create(attributes)
|
|
41
|
+
self.locale = attributes[:locale] || client.default_locale
|
|
101
42
|
end
|
|
102
43
|
|
|
103
44
|
# Processing an Asset file
|
|
@@ -106,6 +47,7 @@ module Contentful
|
|
|
106
47
|
def process_file
|
|
107
48
|
instance_variable_get(:@fields).keys.each do |locale|
|
|
108
49
|
request = Request.new(
|
|
50
|
+
client,
|
|
109
51
|
"/#{space.id}/assets/#{id}/files/#{locale}/process",
|
|
110
52
|
{},
|
|
111
53
|
nil,
|
|
@@ -117,32 +59,6 @@ module Contentful
|
|
|
117
59
|
self
|
|
118
60
|
end
|
|
119
61
|
|
|
120
|
-
# Updates an asset.
|
|
121
|
-
#
|
|
122
|
-
# @param [Hash] attributes
|
|
123
|
-
# @option attributes [String] :title
|
|
124
|
-
# @option attributes [String] :description
|
|
125
|
-
# @option attributes [Contentful::Management::File] :file
|
|
126
|
-
# @option attributes [String] :locale
|
|
127
|
-
#
|
|
128
|
-
# @see _ README for more information on how to create an Asset
|
|
129
|
-
#
|
|
130
|
-
# @return [Contentful::Management::Asset]
|
|
131
|
-
def update(attributes)
|
|
132
|
-
self.title = attributes[:title] if attributes[:title]
|
|
133
|
-
self.description = attributes[:description] if attributes[:description]
|
|
134
|
-
self.file = attributes[:file] if attributes[:file]
|
|
135
|
-
request = Request.new(
|
|
136
|
-
"/#{space.id}/assets/#{id}",
|
|
137
|
-
{ fields: fields_for_query },
|
|
138
|
-
nil,
|
|
139
|
-
version: sys[:version]
|
|
140
|
-
)
|
|
141
|
-
response = request.put
|
|
142
|
-
result = ResourceBuilder.new(response, {}, {}).run
|
|
143
|
-
refresh_data(result)
|
|
144
|
-
end
|
|
145
|
-
|
|
146
62
|
# If an asset is a new object gets created in the Contentful, otherwise the existing asset gets updated.
|
|
147
63
|
# @see _ https://github.com/contentful/contentful-management.rb for details.
|
|
148
64
|
#
|
|
@@ -151,99 +67,11 @@ module Contentful
|
|
|
151
67
|
if id
|
|
152
68
|
update(title: title, description: description, file: file)
|
|
153
69
|
else
|
|
154
|
-
new_instance = self.class.create(sys[:space].id, fields: instance_variable_get(:@fields))
|
|
70
|
+
new_instance = self.class.create(client, sys[:space].id, fields: instance_variable_get(:@fields))
|
|
155
71
|
refresh_data(new_instance)
|
|
156
72
|
end
|
|
157
73
|
end
|
|
158
74
|
|
|
159
|
-
# Destroys an asset.
|
|
160
|
-
#
|
|
161
|
-
# @return [true, Contentful::Management::Error] success
|
|
162
|
-
def destroy
|
|
163
|
-
request = Request.new("/#{space.id}/assets/#{id}")
|
|
164
|
-
response = request.delete
|
|
165
|
-
if response.status == :no_content
|
|
166
|
-
return true
|
|
167
|
-
else
|
|
168
|
-
result = ResourceBuilder.new(response, {}, {})
|
|
169
|
-
result.run
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
# Publishes an asset.
|
|
174
|
-
#
|
|
175
|
-
# @return [Contentful::Management::Asset]
|
|
176
|
-
def publish
|
|
177
|
-
request = Request.new(
|
|
178
|
-
"/#{space.id}/assets/#{id}/published",
|
|
179
|
-
{},
|
|
180
|
-
nil,
|
|
181
|
-
version: sys[:version]
|
|
182
|
-
)
|
|
183
|
-
response = request.put
|
|
184
|
-
result = ResourceBuilder.new(response, {}, {}).run
|
|
185
|
-
refresh_data(result)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
# Unpublishes an asset.
|
|
189
|
-
#
|
|
190
|
-
# @return [Contentful::Management::Asset]
|
|
191
|
-
def unpublish
|
|
192
|
-
request = Request.new(
|
|
193
|
-
"/#{space.id}/assets/#{id}/published",
|
|
194
|
-
{},
|
|
195
|
-
nil,
|
|
196
|
-
version: sys[:version]
|
|
197
|
-
)
|
|
198
|
-
response = request.delete
|
|
199
|
-
result = ResourceBuilder.new(response, {}, {}).run
|
|
200
|
-
refresh_data(result)
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
# Archive an asset.
|
|
204
|
-
#
|
|
205
|
-
# @return [Contentful::Management::Asset]
|
|
206
|
-
def archive
|
|
207
|
-
request = Request.new(
|
|
208
|
-
"/#{space.id}/assets/#{id}/archived",
|
|
209
|
-
{},
|
|
210
|
-
nil,
|
|
211
|
-
version: sys[:version]
|
|
212
|
-
)
|
|
213
|
-
response = request.put
|
|
214
|
-
result = ResourceBuilder.new(response, {}, {}).run
|
|
215
|
-
refresh_data(result)
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
# Unarchvie an asset.
|
|
219
|
-
#
|
|
220
|
-
# @return [Contentful::Management::Asset]
|
|
221
|
-
def unarchive
|
|
222
|
-
request = Request.new(
|
|
223
|
-
"/#{space.id}/assets/#{id}/archived",
|
|
224
|
-
{},
|
|
225
|
-
nil,
|
|
226
|
-
version: sys[:version]
|
|
227
|
-
)
|
|
228
|
-
response = request.delete
|
|
229
|
-
result = ResourceBuilder.new(response, {}, {}).run
|
|
230
|
-
refresh_data(result)
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
# Checks if an asset is published.
|
|
234
|
-
#
|
|
235
|
-
# @return [Boolean]
|
|
236
|
-
def published?
|
|
237
|
-
sys[:publishedAt] ? true : false
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
# Checks if an asset is archvied.
|
|
241
|
-
#
|
|
242
|
-
# @return [Boolean]
|
|
243
|
-
def archived?
|
|
244
|
-
sys[:archivedAt] ? true : false
|
|
245
|
-
end
|
|
246
|
-
|
|
247
75
|
# Returns currently supported local or default locale.
|
|
248
76
|
# @return [String] current_locale
|
|
249
77
|
def locale
|
|
@@ -288,6 +116,16 @@ module Contentful
|
|
|
288
116
|
|
|
289
117
|
query.empty? ? file.url : "#{file.url}?#{URI.encode_www_form(query)}"
|
|
290
118
|
end
|
|
119
|
+
|
|
120
|
+
protected
|
|
121
|
+
|
|
122
|
+
def query_attributes(attributes)
|
|
123
|
+
self.title = attributes[:title] if attributes[:title]
|
|
124
|
+
self.description = attributes[:description] if attributes[:description]
|
|
125
|
+
self.file = attributes[:file] if attributes[:file]
|
|
126
|
+
|
|
127
|
+
{ fields: fields_for_query }
|
|
128
|
+
end
|
|
291
129
|
end
|
|
292
130
|
end
|
|
293
131
|
end
|