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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.rubocop_todo.yml +2 -2
  4. data/CHANGELOG.md +27 -3
  5. data/README.md +34 -7
  6. data/lib/contentful/management/api_key.rb +4 -43
  7. data/lib/contentful/management/array.rb +1 -2
  8. data/lib/contentful/management/asset.rb +29 -191
  9. data/lib/contentful/management/client.rb +96 -7
  10. data/lib/contentful/management/client_api_key_methods_factory.rb +15 -0
  11. data/lib/contentful/management/client_asset_methods_factory.rb +13 -0
  12. data/lib/contentful/management/client_association_all_published_method_factory.rb +21 -0
  13. data/lib/contentful/management/client_association_methods_factory.rb +54 -0
  14. data/lib/contentful/management/client_content_type_methods_factory.rb +13 -0
  15. data/lib/contentful/management/client_entry_methods_factory.rb +21 -0
  16. data/lib/contentful/management/client_locale_methods_factory.rb +15 -0
  17. data/lib/contentful/management/client_space_methods_factory.rb +58 -0
  18. data/lib/contentful/management/client_webhook_methods_factory.rb +15 -0
  19. data/lib/contentful/management/content_type.rb +30 -151
  20. data/lib/contentful/management/content_type_entry_methods_factory.rb +9 -3
  21. data/lib/contentful/management/dynamic_entry.rb +20 -39
  22. data/lib/contentful/management/entry.rb +47 -182
  23. data/lib/contentful/management/http_client.rb +41 -8
  24. data/lib/contentful/management/locale.rb +7 -76
  25. data/lib/contentful/management/request.rb +3 -3
  26. data/lib/contentful/management/resource.rb +105 -7
  27. data/lib/contentful/management/resource/all_published.rb +24 -0
  28. data/lib/contentful/management/resource/archiver.rb +37 -0
  29. data/lib/contentful/management/resource/field_aware.rb +49 -29
  30. data/lib/contentful/management/resource/publisher.rb +37 -0
  31. data/lib/contentful/management/resource/refresher.rb +1 -1
  32. data/lib/contentful/management/resource_builder.rb +8 -4
  33. data/lib/contentful/management/resource_requester.rb +96 -0
  34. data/lib/contentful/management/space.rb +40 -43
  35. data/lib/contentful/management/space_association_all_published_method_factory.rb +1 -1
  36. data/lib/contentful/management/space_association_methods_factory.rb +6 -3
  37. data/lib/contentful/management/space_entry_methods_factory.rb +1 -1
  38. data/lib/contentful/management/version.rb +1 -1
  39. data/lib/contentful/management/webhook.rb +9 -82
  40. data/spec/fixtures/vcr_cassettes/asset/create.yml +1 -1
  41. data/spec/fixtures/vcr_cassettes/asset/create_with_locale.yml +1 -1
  42. data/spec/fixtures/vcr_cassettes/asset/process.yml +1 -1
  43. data/spec/fixtures/vcr_cassettes/asset/publish_after_create.yml +1 -1
  44. data/spec/fixtures/vcr_cassettes/content_type/create.yml +1 -1
  45. data/spec/fixtures/vcr_cassettes/content_type/create_with_Array_field.yml +1 -1
  46. data/spec/fixtures/vcr_cassettes/content_type/create_with_Boolean_field.yml +1 -1
  47. data/spec/fixtures/vcr_cassettes/content_type/create_with_Date_field.yml +1 -1
  48. data/spec/fixtures/vcr_cassettes/content_type/create_with_Integer_field.yml +1 -1
  49. data/spec/fixtures/vcr_cassettes/content_type/create_with_Link_field.yml +1 -1
  50. data/spec/fixtures/vcr_cassettes/content_type/create_with_Location_field.yml +1 -1
  51. data/spec/fixtures/vcr_cassettes/content_type/create_with_Number_field.yml +1 -1
  52. data/spec/fixtures/vcr_cassettes/content_type/create_with_Object_field.yml +1 -1
  53. data/spec/fixtures/vcr_cassettes/content_type/create_with_Symbol_field.yml +1 -1
  54. data/spec/fixtures/vcr_cassettes/content_type/create_with_Text_field.yml +1 -1
  55. data/spec/fixtures/vcr_cassettes/content_type/entry/create.yml +1 -1
  56. data/spec/fixtures/vcr_cassettes/content_type/entry/create_only_with_localized_fields.yml +1 -1
  57. data/spec/fixtures/vcr_cassettes/content_type/entry/create_to_single_locale_only_with_localized_fields.yml +1 -1
  58. data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_camel_case_id_to_multiple_locales.yml +1 -1
  59. data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_entries.yml +1 -1
  60. data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_entries_for_multiple_locales.yml +1 -1
  61. data/spec/fixtures/vcr_cassettes/content_type/entry/create_with_multiple_locales.yml +1 -1
  62. data/spec/fixtures/vcr_cassettes/content_type/fields/create_array_types.yml +1 -1
  63. data/spec/fixtures/vcr_cassettes/content_type/save_new.yml +1 -1
  64. data/spec/fixtures/vcr_cassettes/delete_request.yml +38 -0
  65. data/spec/fixtures/vcr_cassettes/entry/create.yml +1 -1
  66. data/spec/fixtures/vcr_cassettes/entry/create_with_asset.yml +1 -1
  67. data/spec/fixtures/vcr_cassettes/entry/create_with_assets.yml +1 -1
  68. data/spec/fixtures/vcr_cassettes/entry/create_with_entries.yml +1 -1
  69. data/spec/fixtures/vcr_cassettes/entry/create_with_entry.yml +1 -1
  70. data/spec/fixtures/vcr_cassettes/entry/create_with_just_id.yml +1 -1
  71. data/spec/fixtures/vcr_cassettes/entry/create_with_location.yml +1 -1
  72. data/spec/fixtures/vcr_cassettes/entry/create_with_specified_locale.yml +1 -1
  73. data/spec/fixtures/vcr_cassettes/entry/create_with_symbols.yml +1 -1
  74. data/spec/fixtures/vcr_cassettes/entry/too_many_requests.yml +1 -1
  75. data/spec/fixtures/vcr_cassettes/entry/update_bool_field.yml +1 -1
  76. data/spec/fixtures/vcr_cassettes/post_request.yml +64 -0
  77. data/spec/fixtures/vcr_cassettes/proxy_request.yml +562 -0
  78. data/spec/fixtures/vcr_cassettes/put_request.yml +40 -0
  79. data/spec/fixtures/vcr_cassettes/space/asset/create.yml +1 -1
  80. data/spec/fixtures/vcr_cassettes/space/asset/create_with_multiple_locales.yml +1 -1
  81. data/spec/fixtures/vcr_cassettes/space/content_type/create.yml +1 -1
  82. data/spec/fixtures/vcr_cassettes/space/create_with_client_default_locale.yml +197 -36
  83. data/spec/fixtures/vcr_cassettes/space/webhook/create.yml +1 -1
  84. data/spec/lib/contentful/management/api_key_spec.rb +7 -1
  85. data/spec/lib/contentful/management/array_spec.rb +1 -1
  86. data/spec/lib/contentful/management/asset_spec.rb +52 -32
  87. data/spec/lib/contentful/management/client_spec.rb +38 -0
  88. data/spec/lib/contentful/management/content_type_spec.rb +37 -22
  89. data/spec/lib/contentful/management/entry_spec.rb +68 -57
  90. data/spec/lib/contentful/management/locale_spec.rb +7 -1
  91. data/spec/lib/contentful/management/space_spec.rb +9 -3
  92. data/spec/lib/contentful/management/webhook_spec.rb +11 -5
  93. metadata +23 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7374c6a0e9550339b72a54bc9e834b7f3bca3a8a
4
- data.tar.gz: 058292ffa85f933dc083712cd918cdd91ecea921
3
+ metadata.gz: 4351225d59ca9af60725c79bd71d0717449e68e6
4
+ data.tar.gz: fd90f9d188c96f5446f9f920fe6272ca579a45b6
5
5
  SHA512:
6
- metadata.gz: eaa6b839013fb7af7536e753a561fb18a92dabe287f6c782c1d87033fb2c0a927fca286e5fa9728da88d71fcaa93084ff77e1565f4a6cf06af8f207aa1c0cf86
7
- data.tar.gz: a0e156706275fbc0611f3dba7ddc2fa7d6688a06fb5a59ed7e8906defa426576c81a2e9d9dc359eeb9440275ba88d3d24035809a3d4151e600af7e937ba7add1
6
+ metadata.gz: fc14898bf09f8bbf6f21324bb549708e887a4dc43e132cfe615ef06dc04cfd1f6736566675060aa613d3e6fbecca9017547b247f8c47465bb11979150c25d37e
7
+ data.tar.gz: da8832650d78644687acebd327c84ee7477f7b9013730af37d5815a7ee31804cb9c53a08fffb951e5ac7b3a39f7a6af4db03867529e2ad062b426b3a44b6daa6
data/.rubocop.yml CHANGED
@@ -20,4 +20,4 @@ Metrics/LineLength:
20
20
  Max: 135
21
21
 
22
22
  Metrics/ClassLength:
23
- Max: 230
23
+ Max: 250
data/.rubocop_todo.yml CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  # Offense count: 16
10
10
  Metrics/AbcSize:
11
- Max: 49
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: 45
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
- ## Master
6
- ### 0.9.0
7
- * Locales can now update `:code` value
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 = Contentful::Management::Space.all
35
+ spaces = client.spaces.all
36
36
  ```
37
37
 
38
38
  Retrieving one space by id:
39
39
 
40
40
  ```ruby
41
- blog_space = Contentful::Management::Space.find('blog_space_id')
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 = Contentful::Management::Space.new
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 = Contentful::Management::Space.create(name: '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 = Contentful::Management::Space.create(name: 'Blog Space', organization_id: 'organization_id')
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 = Contentful::Management::Space.create(name: 'Blog Space', default_locale: 'de-DE')
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
- # 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",
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
@@ -26,8 +26,7 @@ module Contentful
26
26
  new_request = request.copy
27
27
  new_request.query[:skip] = new_skip
28
28
  response = new_request.get
29
- result = ResourceBuilder.new(response, {}, {})
30
- result.run
29
+ ResourceBuilder.new(response, client).run
31
30
  else
32
31
  false
33
32
  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
- # Gets a collection of assets.
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>]
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
- # Creates an asset.
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
- request = Request.new(
94
- "/#{space_id}/assets/#{attributes[:id]}",
95
- fields: asset.fields_for_query
96
- )
97
- response = attributes[:id].nil? ? request.post : request.put
98
- result = ResourceBuilder.new(response, {}, {}).run
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