contentful-management 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -29
- data/.rubocop_todo.yml +24 -0
- data/.travis.yml +1 -1
- data/.yardopts +4 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -0
- data/Guardfile +39 -34
- data/README.md +42 -1
- data/Rakefile +2 -0
- data/contentful-management.gemspec +2 -1
- data/lib/contentful/management/api_key.rb +65 -0
- data/lib/contentful/management/array.rb +3 -2
- data/lib/contentful/management/asset.rb +124 -58
- data/lib/contentful/management/client.rb +60 -19
- data/lib/contentful/management/content_type.rb +104 -49
- data/lib/contentful/management/content_type_entry_methods_factory.rb +21 -0
- data/lib/contentful/management/dynamic_entry.rb +22 -18
- data/lib/contentful/management/entry.rb +138 -80
- data/lib/contentful/management/error.rb +23 -23
- data/lib/contentful/management/field.rb +16 -13
- data/lib/contentful/management/http_client.rb +29 -0
- data/lib/contentful/management/link.rb +3 -3
- data/lib/contentful/management/locale.rb +55 -26
- data/lib/contentful/management/location.rb +1 -1
- data/lib/contentful/management/request.rb +11 -12
- data/lib/contentful/management/resource.rb +27 -12
- data/lib/contentful/management/resource/array_like.rb +1 -1
- data/lib/contentful/management/resource/asset_fields.rb +1 -0
- data/lib/contentful/management/resource/entry_fields.rb +2 -0
- data/lib/contentful/management/resource/field_aware.rb +16 -5
- data/lib/contentful/management/resource/fields.rb +16 -8
- data/lib/contentful/management/resource/refresher.rb +1 -0
- data/lib/contentful/management/resource/system_properties.rb +13 -6
- data/lib/contentful/management/resource_builder.rb +43 -40
- data/lib/contentful/management/space.rb +67 -28
- data/lib/contentful/management/space_api_key_methods_factory.rb +15 -0
- data/lib/contentful/management/space_asset_methods_factory.rb +4 -0
- data/lib/contentful/management/space_association_all_published_method_factory.rb +11 -0
- data/lib/contentful/management/space_association_methods_factory.rb +4 -2
- data/lib/contentful/management/space_content_type_methods_factory.rb +4 -0
- data/lib/contentful/management/space_entry_methods_factory.rb +4 -0
- data/lib/contentful/management/space_locale_methods_factory.rb +2 -0
- data/lib/contentful/management/space_webhook_methods_factory.rb +2 -0
- data/lib/contentful/management/validation.rb +3 -2
- data/lib/contentful/management/version.rb +4 -1
- data/lib/contentful/management/webhook.rb +42 -21
- data/spec/fixtures/vcr_cassettes/api_key/all_for_space.yml +194 -0
- data/spec/fixtures/vcr_cassettes/api_key/create_for_space.yml +113 -0
- data/spec/fixtures/vcr_cassettes/api_key/find.yml +113 -0
- data/spec/fixtures/vcr_cassettes/api_key/find_for_space_not_found.yml +71 -0
- data/spec/fixtures/vcr_cassettes/asset/all_public.yml +112 -0
- data/spec/fixtures/vcr_cassettes/content_type/all_public.yml +106 -0
- data/spec/fixtures/vcr_cassettes/entry/all_public.yml +102 -0
- data/spec/fixtures/vcr_cassettes/locale/destroy.yml +330 -0
- data/spec/fixtures/vcr_cassettes/locale/update_both.yml +306 -0
- data/spec/fixtures/vcr_cassettes/locale/update_code.yml +306 -0
- data/spec/fixtures/vcr_cassettes/locale/update_name.yml +306 -0
- data/spec/fixtures/vcr_cassettes/space/api_key/all.yml +410 -0
- data/spec/fixtures/vcr_cassettes/space/api_key/create.yml +329 -0
- data/spec/fixtures/vcr_cassettes/space/api_key/find.yml +329 -0
- data/spec/fixtures/vcr_cassettes/space/asset/all_public.yml +328 -0
- data/spec/fixtures/vcr_cassettes/space/content_type/all_public.yml +322 -0
- data/spec/fixtures/vcr_cassettes/space/entry/all_public.yml +318 -0
- data/spec/lib/contentful/management/api_key_spec.rb +55 -0
- data/spec/lib/contentful/management/asset_spec.rb +10 -0
- data/spec/lib/contentful/management/content_type_spec.rb +10 -0
- data/spec/lib/contentful/management/entry_spec.rb +10 -0
- data/spec/lib/contentful/management/locale_spec.rb +58 -0
- data/spec/lib/contentful/management/space_spec.rb +53 -0
- metadata +58 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7374c6a0e9550339b72a54bc9e834b7f3bca3a8a
|
4
|
+
data.tar.gz: 058292ffa85f933dc083712cd918cdd91ecea921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaa6b839013fb7af7536e753a561fb18a92dabe287f6c782c1d87033fb2c0a927fca286e5fa9728da88d71fcaa93084ff77e1565f4a6cf06af8f207aa1c0cf86
|
7
|
+
data.tar.gz: a0e156706275fbc0611f3dba7ddc2fa7d6688a06fb5a59ed7e8906defa426576c81a2e9d9dc359eeb9440275ba88d3d24035809a3d4151e600af7e937ba7add1
|
data/.rubocop.yml
CHANGED
@@ -1,40 +1,23 @@
|
|
1
|
-
|
2
|
-
Enabled: false
|
1
|
+
inherit_from: .rubocop_todo.yml
|
3
2
|
|
4
|
-
|
3
|
+
Encoding:
|
5
4
|
Enabled: false
|
6
5
|
|
7
|
-
ClassLength:
|
8
|
-
|
6
|
+
Metrics/ClassLength:
|
7
|
+
CountComments: false
|
9
8
|
|
10
9
|
AllCops:
|
11
10
|
Exclude:
|
12
11
|
- contentful-management.gemspec
|
13
12
|
- bin/cma-console
|
13
|
+
- spec/**/*
|
14
|
+
- examples/**/*
|
15
|
+
- Guardfile
|
16
|
+
- Gemfile
|
17
|
+
- Rakefile
|
14
18
|
|
15
|
-
LineLength:
|
19
|
+
Metrics/LineLength:
|
16
20
|
Max: 135
|
17
|
-
Style/MethodLength:
|
18
|
-
Max: 15
|
19
|
-
|
20
|
-
Style/SpaceInsideBrackets:
|
21
|
-
Enabled: false
|
22
|
-
|
23
|
-
Style/CyclomaticComplexity:
|
24
|
-
Max: 8
|
25
|
-
|
26
|
-
Style/SpaceInsideHashLiteralBraces:
|
27
|
-
EnforcedStyle: no_space
|
28
|
-
EnforcedStyleForEmptyBraces: no_space
|
29
|
-
|
30
|
-
Style/CaseIndentation:
|
31
|
-
Enabled: false
|
32
|
-
|
33
|
-
Lint/UselessAssignment:
|
34
|
-
Enabled: false
|
35
|
-
|
36
|
-
Style/IndentationWidth:
|
37
|
-
Enabled: false
|
38
21
|
|
39
|
-
|
40
|
-
|
22
|
+
Metrics/ClassLength:
|
23
|
+
Max: 230
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-02-01 08:50:00 -0300 using RuboCop version 0.34.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 16
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 49
|
12
|
+
|
13
|
+
# Offense count: 4
|
14
|
+
Metrics/CyclomaticComplexity:
|
15
|
+
Max: 10
|
16
|
+
|
17
|
+
# Offense count: 21
|
18
|
+
# Configuration parameters: CountComments.
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 45
|
21
|
+
|
22
|
+
# Offense count: 2
|
23
|
+
Metrics/PerceivedComplexity:
|
24
|
+
Max: 8
|
data/.travis.yml
CHANGED
@@ -8,7 +8,7 @@ rvm:
|
|
8
8
|
- jruby-19mode
|
9
9
|
|
10
10
|
before_install: gem install bundler -v 1.10.6
|
11
|
-
script: bundle exec rake
|
11
|
+
script: bundle exec rake rspec_rubocop
|
12
12
|
notifications:
|
13
13
|
slack:
|
14
14
|
secure: P+BWOt+sKPUlIwxUMaD7o4bVG19nIsedyv9D1MCBJELKxTYkXOyJECSNw1f5SDf9z0n4lKhfp8SY0dVigvxdUBd9/wsGqRZMMI2sykDJ8E85cYsUb8corEnIgQtwwzkAzWzhCbmWrZe39ai1Sr5ET/7bdEJ7SXIKbFS350SOn9s=
|
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
## Master
|
4
4
|
|
5
|
+
## Master
|
6
|
+
### 0.9.0
|
7
|
+
* Locales can now update `:code` value
|
8
|
+
|
9
|
+
### Added
|
10
|
+
* Added `#destroy` method to Locales
|
11
|
+
* Added `ApiKey` class, methods and `Space` associations
|
12
|
+
* Added `.all_published` methods for `ContentType`, `Asset` and `Entry`
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
* Changed documentation format to YARD
|
16
|
+
|
5
17
|
## 0.8.0
|
6
18
|
### Added
|
7
19
|
* Added `:dynamic_entries` parameter on Client initialization
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -24,47 +24,52 @@
|
|
24
24
|
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
25
|
# * 'just' rspec: 'rspec'
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
group :green_red_refactor, halt_on_fail: true do
|
28
|
+
guard :rspec, cmd: "bundle exec rspec --format documentation" do
|
29
|
+
require "guard/rspec/dsl"
|
30
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
31
|
|
31
|
-
|
32
|
+
# Feel free to open issues for suggestions and improvements
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
# RSpec files
|
35
|
+
rspec = dsl.rspec
|
36
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
38
|
+
watch(rspec.spec_files)
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
# Ruby files
|
41
|
+
ruby = dsl.ruby
|
42
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
# Rails files
|
45
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
46
|
+
dsl.watch_spec_files_for(rails.app_files)
|
47
|
+
dsl.watch_spec_files_for(rails.views)
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
watch(rails.controllers) do |m|
|
50
|
+
[
|
51
|
+
rspec.spec.("routing/#{m[1]}_routing"),
|
52
|
+
rspec.spec.("controllers/#{m[1]}_controller"),
|
53
|
+
rspec.spec.("acceptance/#{m[1]}")
|
54
|
+
]
|
55
|
+
end
|
56
|
+
|
57
|
+
# Rails config changes
|
58
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
59
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
60
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
55
61
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
62
|
+
# Capybara features specs
|
63
|
+
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
64
|
+
watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
|
60
65
|
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
# Turnip features and steps
|
67
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
68
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
69
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
70
|
+
end
|
71
|
+
end
|
64
72
|
|
65
|
-
|
66
|
-
watch(%r{^spec/acceptance/(.+)\.feature$})
|
67
|
-
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
68
|
-
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
73
|
+
guard :rubocop, cmd: "rubocop" do
|
69
74
|
end
|
70
75
|
end
|
data/README.md
CHANGED
@@ -93,6 +93,12 @@ Retrieving all content types from a space:
|
|
93
93
|
blog_post_content_types = blog_space.content_types.all
|
94
94
|
```
|
95
95
|
|
96
|
+
Retrieving all published content types from a space:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
blog_post_content_types = blog_space.content_types.all_published
|
100
|
+
```
|
101
|
+
|
96
102
|
Retrieving one content type by id from a space:
|
97
103
|
|
98
104
|
```ruby
|
@@ -199,15 +205,25 @@ Updating a locale
|
|
199
205
|
blog_post_locale.update(name: 'German', code: 'de-DE')
|
200
206
|
```
|
201
207
|
|
208
|
+
Destroying a locale
|
209
|
+
```ruby
|
210
|
+
blog_post_locale.destroy
|
211
|
+
```
|
212
|
+
|
202
213
|
### Assets
|
203
214
|
|
204
215
|
Retrieving all assets from the space:
|
205
216
|
|
206
|
-
|
207
217
|
```ruby
|
208
218
|
blog_post_assets = blog_space.assets.all
|
209
219
|
```
|
210
220
|
|
221
|
+
Retrieving all published assets from the space:
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
blog_post_assets = blog_space.assets.all_published
|
225
|
+
```
|
226
|
+
|
211
227
|
Retrieving an asset by id:
|
212
228
|
|
213
229
|
```ruby
|
@@ -314,6 +330,12 @@ Retrieving all entries from the space:
|
|
314
330
|
entries = blog_space.entries.all
|
315
331
|
```
|
316
332
|
|
333
|
+
Retrieving all published entries from the space:
|
334
|
+
|
335
|
+
```ruby
|
336
|
+
entries = blog_space.entries.all_published
|
337
|
+
```
|
338
|
+
|
317
339
|
Retrieving all entries from the space with given content type:
|
318
340
|
|
319
341
|
```ruby
|
@@ -444,6 +466,25 @@ Destroying webhook:
|
|
444
466
|
blog_post_webhook.destroy
|
445
467
|
```
|
446
468
|
|
469
|
+
### Api Keys
|
470
|
+
|
471
|
+
Retrieving all api keys from the space:
|
472
|
+
|
473
|
+
```ruby
|
474
|
+
blog_post_api_keys = blog_space.api_keys.all
|
475
|
+
```
|
476
|
+
|
477
|
+
Retrieving one api key by the api-key-id from the space:
|
478
|
+
|
479
|
+
```ruby
|
480
|
+
blog_post_api_key = blog_space.api_keys.find(api_key_id)
|
481
|
+
```
|
482
|
+
|
483
|
+
Creating an api key
|
484
|
+
```ruby
|
485
|
+
blog_space.api_keys.create(name: 'foobar key', description: 'key for foobar mobile app')
|
486
|
+
```
|
487
|
+
|
447
488
|
## Validations
|
448
489
|
|
449
490
|
#### in
|
data/Rakefile
CHANGED
@@ -26,7 +26,8 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency 'rspec', '~> 3'
|
27
27
|
spec.add_development_dependency 'rspec-its'
|
28
28
|
spec.add_development_dependency 'rubocop'
|
29
|
-
spec.add_development_dependency 'reek', '~> 2
|
29
|
+
spec.add_development_dependency 'reek', '~> 2.2.1'
|
30
|
+
spec.add_development_dependency 'unparser', '0.2.4'
|
30
31
|
spec.add_development_dependency 'vcr'
|
31
32
|
spec.add_development_dependency 'webmock', '~> 1', '>= 1.17.3'
|
32
33
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative 'resource'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Management
|
5
|
+
# Resource class for ApiKey.
|
6
|
+
# @see _ https://www.contentful.com/developers/docs/references/content-management-api/#/reference/api-keys
|
7
|
+
class ApiKey
|
8
|
+
include Contentful::Management::Resource
|
9
|
+
include Contentful::Management::Resource::SystemProperties
|
10
|
+
include Contentful::Management::Resource::Refresher
|
11
|
+
|
12
|
+
property :name
|
13
|
+
property :description
|
14
|
+
property :accessToken
|
15
|
+
property :policies
|
16
|
+
|
17
|
+
# Gets a collection of api keys.
|
18
|
+
#
|
19
|
+
# @param [String] space_id
|
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",
|
56
|
+
'name' => attributes.fetch(:name),
|
57
|
+
'description' => attributes.fetch(:description, nil)
|
58
|
+
)
|
59
|
+
response = request.post
|
60
|
+
result = ResourceBuilder.new(response, { 'ApiKey' => ApiKey }, {})
|
61
|
+
result.run
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -4,9 +4,10 @@ require_relative 'resource/array_like'
|
|
4
4
|
module Contentful
|
5
5
|
module Management
|
6
6
|
# Resource Class for Arrays (e.g. search results)
|
7
|
-
# https://www.contentful.com/developers/documentation/content-delivery-api/#arrays
|
8
|
-
# It also provides an #each method and includes Ruby's Enumerable module (gives you methods like #min, #first, etc)
|
7
|
+
# @see _ https://www.contentful.com/developers/documentation/content-delivery-api/#arrays
|
8
|
+
# @note It also provides an #each method and includes Ruby's Enumerable module (gives you methods like #min, #first, etc)
|
9
9
|
class Array
|
10
|
+
# @private
|
10
11
|
DEFAULT_LIMIT = 100
|
11
12
|
|
12
13
|
include Contentful::Management::Resource
|
@@ -5,7 +5,7 @@ require_relative 'resource/fields'
|
|
5
5
|
module Contentful
|
6
6
|
module Management
|
7
7
|
# Resource class for Asset.
|
8
|
-
# https://www.contentful.com/developers/documentation/content-management-api/#resources-assets
|
8
|
+
# @see _ https://www.contentful.com/developers/documentation/content-management-api/#resources-assets
|
9
9
|
class Asset
|
10
10
|
include Contentful::Management::Resource
|
11
11
|
extend Contentful::Management::Resource::AssetFields
|
@@ -14,12 +14,41 @@ module Contentful
|
|
14
14
|
include Contentful::Management::Resource::Refresher
|
15
15
|
|
16
16
|
# Gets a collection of assets.
|
17
|
-
#
|
18
|
-
#
|
17
|
+
#
|
18
|
+
# @param [String] space_id
|
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>]
|
19
27
|
def self.all(space_id, query = {})
|
20
28
|
request = Request.new(
|
21
|
-
|
22
|
-
|
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
|
23
52
|
)
|
24
53
|
response = request.get
|
25
54
|
result = ResourceBuilder.new(response, {}, {})
|
@@ -27,18 +56,31 @@ module Contentful
|
|
27
56
|
end
|
28
57
|
|
29
58
|
# Gets a specific asset.
|
30
|
-
#
|
31
|
-
#
|
59
|
+
#
|
60
|
+
# @param [String] space_id
|
61
|
+
# @param [String] asset_id
|
62
|
+
#
|
63
|
+
# @return [Contentful::Management::Asset]
|
32
64
|
def self.find(space_id, asset_id)
|
33
|
-
request = Request.new("/#{
|
65
|
+
request = Request.new("/#{space_id}/assets/#{asset_id}")
|
34
66
|
response = request.get
|
35
67
|
result = ResourceBuilder.new(response, {}, {})
|
36
68
|
result.run
|
37
69
|
end
|
38
70
|
|
39
71
|
# Creates an asset.
|
40
|
-
#
|
41
|
-
#
|
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]
|
42
84
|
def self.create(space_id, attributes)
|
43
85
|
locale = attributes[:locale]
|
44
86
|
asset = new
|
@@ -49,8 +91,8 @@ module Contentful
|
|
49
91
|
asset.file = attributes[:file] if attributes[:file]
|
50
92
|
|
51
93
|
request = Request.new(
|
52
|
-
|
53
|
-
|
94
|
+
"/#{space_id}/assets/#{attributes[:id]}",
|
95
|
+
fields: asset.fields_for_query
|
54
96
|
)
|
55
97
|
response = attributes[:id].nil? ? request.post : request.put
|
56
98
|
result = ResourceBuilder.new(response, {}, {}).run
|
@@ -59,13 +101,15 @@ module Contentful
|
|
59
101
|
end
|
60
102
|
|
61
103
|
# Processing an Asset file
|
104
|
+
#
|
105
|
+
# @return [Contentful::Management::Asset]
|
62
106
|
def process_file
|
63
107
|
instance_variable_get(:@fields).keys.each do |locale|
|
64
108
|
request = Request.new(
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
109
|
+
"/#{space.id}/assets/#{id}/files/#{locale}/process",
|
110
|
+
{},
|
111
|
+
nil,
|
112
|
+
version: sys[:version]
|
69
113
|
)
|
70
114
|
request.put
|
71
115
|
end
|
@@ -74,17 +118,25 @@ module Contentful
|
|
74
118
|
end
|
75
119
|
|
76
120
|
# Updates an asset.
|
77
|
-
#
|
78
|
-
#
|
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]
|
79
131
|
def update(attributes)
|
80
132
|
self.title = attributes[:title] if attributes[:title]
|
81
133
|
self.description = attributes[:description] if attributes[:description]
|
82
134
|
self.file = attributes[:file] if attributes[:file]
|
83
135
|
request = Request.new(
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
136
|
+
"/#{space.id}/assets/#{id}",
|
137
|
+
{ fields: fields_for_query },
|
138
|
+
nil,
|
139
|
+
version: sys[:version]
|
88
140
|
)
|
89
141
|
response = request.put
|
90
142
|
result = ResourceBuilder.new(response, {}, {}).run
|
@@ -92,7 +144,9 @@ module Contentful
|
|
92
144
|
end
|
93
145
|
|
94
146
|
# If an asset is a new object gets created in the Contentful, otherwise the existing asset gets updated.
|
95
|
-
#
|
147
|
+
# @see _ https://github.com/contentful/contentful-management.rb for details.
|
148
|
+
#
|
149
|
+
# @return [Contentful::Management::Asset]
|
96
150
|
def save
|
97
151
|
if id
|
98
152
|
update(title: title, description: description, file: file)
|
@@ -103,9 +157,10 @@ module Contentful
|
|
103
157
|
end
|
104
158
|
|
105
159
|
# Destroys an asset.
|
106
|
-
#
|
160
|
+
#
|
161
|
+
# @return [true, Contentful::Management::Error] success
|
107
162
|
def destroy
|
108
|
-
request = Request.new("/#{
|
163
|
+
request = Request.new("/#{space.id}/assets/#{id}")
|
109
164
|
response = request.delete
|
110
165
|
if response.status == :no_content
|
111
166
|
return true
|
@@ -116,13 +171,14 @@ module Contentful
|
|
116
171
|
end
|
117
172
|
|
118
173
|
# Publishes an asset.
|
119
|
-
#
|
174
|
+
#
|
175
|
+
# @return [Contentful::Management::Asset]
|
120
176
|
def publish
|
121
177
|
request = Request.new(
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
178
|
+
"/#{space.id}/assets/#{id}/published",
|
179
|
+
{},
|
180
|
+
nil,
|
181
|
+
version: sys[:version]
|
126
182
|
)
|
127
183
|
response = request.put
|
128
184
|
result = ResourceBuilder.new(response, {}, {}).run
|
@@ -130,13 +186,14 @@ module Contentful
|
|
130
186
|
end
|
131
187
|
|
132
188
|
# Unpublishes an asset.
|
133
|
-
#
|
189
|
+
#
|
190
|
+
# @return [Contentful::Management::Asset]
|
134
191
|
def unpublish
|
135
192
|
request = Request.new(
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
193
|
+
"/#{space.id}/assets/#{id}/published",
|
194
|
+
{},
|
195
|
+
nil,
|
196
|
+
version: sys[:version]
|
140
197
|
)
|
141
198
|
response = request.delete
|
142
199
|
result = ResourceBuilder.new(response, {}, {}).run
|
@@ -144,13 +201,14 @@ module Contentful
|
|
144
201
|
end
|
145
202
|
|
146
203
|
# Archive an asset.
|
147
|
-
#
|
204
|
+
#
|
205
|
+
# @return [Contentful::Management::Asset]
|
148
206
|
def archive
|
149
207
|
request = Request.new(
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
208
|
+
"/#{space.id}/assets/#{id}/archived",
|
209
|
+
{},
|
210
|
+
nil,
|
211
|
+
version: sys[:version]
|
154
212
|
)
|
155
213
|
response = request.put
|
156
214
|
result = ResourceBuilder.new(response, {}, {}).run
|
@@ -158,13 +216,14 @@ module Contentful
|
|
158
216
|
end
|
159
217
|
|
160
218
|
# Unarchvie an asset.
|
161
|
-
#
|
219
|
+
#
|
220
|
+
# @return [Contentful::Management::Asset]
|
162
221
|
def unarchive
|
163
222
|
request = Request.new(
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
223
|
+
"/#{space.id}/assets/#{id}/archived",
|
224
|
+
{},
|
225
|
+
nil,
|
226
|
+
version: sys[:version]
|
168
227
|
)
|
169
228
|
response = request.delete
|
170
229
|
result = ResourceBuilder.new(response, {}, {}).run
|
@@ -172,18 +231,21 @@ module Contentful
|
|
172
231
|
end
|
173
232
|
|
174
233
|
# Checks if an asset is published.
|
175
|
-
#
|
234
|
+
#
|
235
|
+
# @return [Boolean]
|
176
236
|
def published?
|
177
237
|
sys[:publishedAt] ? true : false
|
178
238
|
end
|
179
239
|
|
180
240
|
# Checks if an asset is archvied.
|
181
|
-
#
|
241
|
+
#
|
242
|
+
# @return [Boolean]
|
182
243
|
def archived?
|
183
244
|
sys[:archivedAt] ? true : false
|
184
245
|
end
|
185
246
|
|
186
247
|
# Returns currently supported local or default locale.
|
248
|
+
# @return [String] current_locale
|
187
249
|
def locale
|
188
250
|
sys && sys[:locale] ? sys[:locale] : default_locale
|
189
251
|
end
|
@@ -197,6 +259,7 @@ module Contentful
|
|
197
259
|
end
|
198
260
|
end
|
199
261
|
|
262
|
+
# @private
|
200
263
|
def get_value_from(fields, field_name)
|
201
264
|
if field_name == :file
|
202
265
|
fields[field_name].properties if fields[field_name]
|
@@ -205,19 +268,22 @@ module Contentful
|
|
205
268
|
end
|
206
269
|
end
|
207
270
|
|
208
|
-
#
|
209
|
-
#
|
210
|
-
#
|
211
|
-
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
#
|
271
|
+
# Generates a URL for the Contentful Image API
|
272
|
+
#
|
273
|
+
# @param [Hash] options
|
274
|
+
# @option options [Integer] :width
|
275
|
+
# @option options [Integer] :height
|
276
|
+
# @option options [String] :format
|
277
|
+
# @option options [String] :quality
|
278
|
+
# @see _ https://www.contentful.com/developers/documentation/content-delivery-api/#image-asset-resizing
|
279
|
+
#
|
280
|
+
# @return [String] Image API URL
|
215
281
|
def image_url(options = {})
|
216
282
|
query = {
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
283
|
+
w: options[:w] || options[:width],
|
284
|
+
h: options[:h] || options[:height],
|
285
|
+
fm: options[:fm] || options[:format],
|
286
|
+
q: options[:q] || options[:quality]
|
221
287
|
}.select { |_k, value| value }
|
222
288
|
|
223
289
|
query.empty? ? file.url : "#{file.url}?#{URI.encode_www_form(query)}"
|