contentful-management 0.8.0 → 0.9.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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -29
  3. data/.rubocop_todo.yml +24 -0
  4. data/.travis.yml +1 -1
  5. data/.yardopts +4 -0
  6. data/CHANGELOG.md +12 -0
  7. data/Gemfile +1 -0
  8. data/Guardfile +39 -34
  9. data/README.md +42 -1
  10. data/Rakefile +2 -0
  11. data/contentful-management.gemspec +2 -1
  12. data/lib/contentful/management/api_key.rb +65 -0
  13. data/lib/contentful/management/array.rb +3 -2
  14. data/lib/contentful/management/asset.rb +124 -58
  15. data/lib/contentful/management/client.rb +60 -19
  16. data/lib/contentful/management/content_type.rb +104 -49
  17. data/lib/contentful/management/content_type_entry_methods_factory.rb +21 -0
  18. data/lib/contentful/management/dynamic_entry.rb +22 -18
  19. data/lib/contentful/management/entry.rb +138 -80
  20. data/lib/contentful/management/error.rb +23 -23
  21. data/lib/contentful/management/field.rb +16 -13
  22. data/lib/contentful/management/http_client.rb +29 -0
  23. data/lib/contentful/management/link.rb +3 -3
  24. data/lib/contentful/management/locale.rb +55 -26
  25. data/lib/contentful/management/location.rb +1 -1
  26. data/lib/contentful/management/request.rb +11 -12
  27. data/lib/contentful/management/resource.rb +27 -12
  28. data/lib/contentful/management/resource/array_like.rb +1 -1
  29. data/lib/contentful/management/resource/asset_fields.rb +1 -0
  30. data/lib/contentful/management/resource/entry_fields.rb +2 -0
  31. data/lib/contentful/management/resource/field_aware.rb +16 -5
  32. data/lib/contentful/management/resource/fields.rb +16 -8
  33. data/lib/contentful/management/resource/refresher.rb +1 -0
  34. data/lib/contentful/management/resource/system_properties.rb +13 -6
  35. data/lib/contentful/management/resource_builder.rb +43 -40
  36. data/lib/contentful/management/space.rb +67 -28
  37. data/lib/contentful/management/space_api_key_methods_factory.rb +15 -0
  38. data/lib/contentful/management/space_asset_methods_factory.rb +4 -0
  39. data/lib/contentful/management/space_association_all_published_method_factory.rb +11 -0
  40. data/lib/contentful/management/space_association_methods_factory.rb +4 -2
  41. data/lib/contentful/management/space_content_type_methods_factory.rb +4 -0
  42. data/lib/contentful/management/space_entry_methods_factory.rb +4 -0
  43. data/lib/contentful/management/space_locale_methods_factory.rb +2 -0
  44. data/lib/contentful/management/space_webhook_methods_factory.rb +2 -0
  45. data/lib/contentful/management/validation.rb +3 -2
  46. data/lib/contentful/management/version.rb +4 -1
  47. data/lib/contentful/management/webhook.rb +42 -21
  48. data/spec/fixtures/vcr_cassettes/api_key/all_for_space.yml +194 -0
  49. data/spec/fixtures/vcr_cassettes/api_key/create_for_space.yml +113 -0
  50. data/spec/fixtures/vcr_cassettes/api_key/find.yml +113 -0
  51. data/spec/fixtures/vcr_cassettes/api_key/find_for_space_not_found.yml +71 -0
  52. data/spec/fixtures/vcr_cassettes/asset/all_public.yml +112 -0
  53. data/spec/fixtures/vcr_cassettes/content_type/all_public.yml +106 -0
  54. data/spec/fixtures/vcr_cassettes/entry/all_public.yml +102 -0
  55. data/spec/fixtures/vcr_cassettes/locale/destroy.yml +330 -0
  56. data/spec/fixtures/vcr_cassettes/locale/update_both.yml +306 -0
  57. data/spec/fixtures/vcr_cassettes/locale/update_code.yml +306 -0
  58. data/spec/fixtures/vcr_cassettes/locale/update_name.yml +306 -0
  59. data/spec/fixtures/vcr_cassettes/space/api_key/all.yml +410 -0
  60. data/spec/fixtures/vcr_cassettes/space/api_key/create.yml +329 -0
  61. data/spec/fixtures/vcr_cassettes/space/api_key/find.yml +329 -0
  62. data/spec/fixtures/vcr_cassettes/space/asset/all_public.yml +328 -0
  63. data/spec/fixtures/vcr_cassettes/space/content_type/all_public.yml +322 -0
  64. data/spec/fixtures/vcr_cassettes/space/entry/all_public.yml +318 -0
  65. data/spec/lib/contentful/management/api_key_spec.rb +55 -0
  66. data/spec/lib/contentful/management/asset_spec.rb +10 -0
  67. data/spec/lib/contentful/management/content_type_spec.rb +10 -0
  68. data/spec/lib/contentful/management/entry_spec.rb +10 -0
  69. data/spec/lib/contentful/management/locale_spec.rb +58 -0
  70. data/spec/lib/contentful/management/space_spec.rb +53 -0
  71. metadata +58 -9
@@ -0,0 +1,15 @@
1
+ require_relative 'space_association_methods_factory'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Wrapper for ApiKey API for usage from within Space
6
+ # @private
7
+ class SpaceApiKeyMethodsFactory
8
+ include Contentful::Management::SpaceAssociationMethodsFactory
9
+
10
+ def new
11
+ fail 'Not supported'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,9 +1,13 @@
1
1
  require_relative 'space_association_methods_factory'
2
+ require_relative 'space_association_all_published_method_factory'
2
3
 
3
4
  module Contentful
4
5
  module Management
6
+ # Wrapper for Asset API for usage from within Space
7
+ # @private
5
8
  class SpaceAssetMethodsFactory
6
9
  include Contentful::Management::SpaceAssociationMethodsFactory
10
+ include Contentful::Management::SpaceAssociationAllPublishedMethodsFactory
7
11
  end
8
12
  end
9
13
  end
@@ -0,0 +1,11 @@
1
+ module Contentful
2
+ module Management
3
+ # Wrapper for /public API for usage from within Space Wrapper Classes
4
+ # @private
5
+ module SpaceAssociationAllPublishedMethodsFactory
6
+ def all_published(params = {})
7
+ associated_class.all_published(space.id, params)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,7 @@
1
1
  module Contentful
2
2
  module Management
3
+ # Wrapper for Space Association Methods
4
+ # @private
3
5
  module SpaceAssociationMethodsFactory
4
6
  attr_reader :space
5
7
 
@@ -27,8 +29,8 @@ module Contentful
27
29
 
28
30
  def associated_class
29
31
  class_name = /\A(.+)Space(.+)MethodsFactory\z/.match(self.class.name).captures.join
30
- class_name.split('::').reduce(Object) do |mod, class_name|
31
- mod.const_get(class_name)
32
+ class_name.split('::').reduce(Object) do |mod, actual_class_name|
33
+ mod.const_get(actual_class_name)
32
34
  end
33
35
  end
34
36
  end
@@ -1,9 +1,13 @@
1
1
  require_relative 'space_association_methods_factory'
2
+ require_relative 'space_association_all_published_method_factory'
2
3
 
3
4
  module Contentful
4
5
  module Management
6
+ # Wrapper for ContentType API for usage from within Space
7
+ # @private
5
8
  class SpaceContentTypeMethodsFactory
6
9
  include Contentful::Management::SpaceAssociationMethodsFactory
10
+ include Contentful::Management::SpaceAssociationAllPublishedMethodsFactory
7
11
  end
8
12
  end
9
13
  end
@@ -1,9 +1,13 @@
1
1
  require_relative 'space_association_methods_factory'
2
+ require_relative 'space_association_all_published_method_factory'
2
3
 
3
4
  module Contentful
4
5
  module Management
6
+ # Wrapper for ContentType API for usage from within Space
7
+ # @private
5
8
  class SpaceEntryMethodsFactory
6
9
  include Contentful::Management::SpaceAssociationMethodsFactory
10
+ include Contentful::Management::SpaceAssociationAllPublishedMethodsFactory
7
11
 
8
12
  def create(_attributes)
9
13
  fail 'Not supported'
@@ -2,6 +2,8 @@ require_relative 'space_association_methods_factory'
2
2
 
3
3
  module Contentful
4
4
  module Management
5
+ # Wrapper for Locale API for usage from within Space
6
+ # @private
5
7
  class SpaceLocaleMethodsFactory
6
8
  include Contentful::Management::SpaceAssociationMethodsFactory
7
9
 
@@ -2,6 +2,8 @@ require_relative 'space_association_methods_factory'
2
2
 
3
3
  module Contentful
4
4
  module Management
5
+ # Wrapper for Webhook API for usage from within Space
6
+ # @private
5
7
  class SpaceWebhookMethodsFactory
6
8
  include Contentful::Management::SpaceAssociationMethodsFactory
7
9
 
@@ -15,6 +15,7 @@ module Contentful
15
15
  property :linkMimetypeGroup, :string
16
16
  property :linkField, :boolean
17
17
 
18
+ # @private
18
19
  def properties_to_hash
19
20
  properties.each_with_object({}) do |(key, value), results|
20
21
  results[key] = value if Field.value_exists?(value)
@@ -22,13 +23,13 @@ module Contentful
22
23
  end
23
24
 
24
25
  # Returns type of validation
26
+ # @return [Symbol]
25
27
  def type
26
28
  properties.keys.reject { |key| key == :validations }.each do |type|
27
- value = self.send(Support.snakify(type))
29
+ value = send(Support.snakify(type))
28
30
  return type if !value.nil? && value
29
31
  end
30
32
  end
31
-
32
33
  end
33
34
  end
34
35
  end
@@ -1,5 +1,8 @@
1
+ # Contentful Namespace
1
2
  module Contentful
3
+ # Management Namespace
2
4
  module Management
3
- VERSION = '0.8.0'
5
+ # Gem Version
6
+ VERSION = '0.9.0'
4
7
  end
5
8
  end
@@ -3,7 +3,7 @@ require_relative 'resource'
3
3
  module Contentful
4
4
  module Management
5
5
  # Resource class for Webhook.
6
- # https://www.contentful.com/developers/documentation/content-management-api/http/#resources-webhooks
6
+ # @see _ https://www.contentful.com/developers/documentation/content-management-api/http/#resources-webhooks
7
7
  class Webhook
8
8
  include Contentful::Management::Resource
9
9
  include Contentful::Management::Resource::SystemProperties
@@ -13,12 +13,17 @@ module Contentful
13
13
  property :httpBasicUsername, :string
14
14
 
15
15
  # Gets a collection of webhooks.
16
- # Takes an id of space and hash of parameters.
17
- # Returns a Contentful::Management::Array of Contentful::Management::Webhook.
16
+ #
17
+ # @param [String] space_id
18
+ # @param [Hash] parameters
19
+ # @option parameters [String] 'sys.id'
20
+ # @option parameters [String] :url
21
+ #
22
+ # @return [Contentful::Management::Array<Contentful::Management::Webhook>]
18
23
  def self.all(space_id, parameters = {})
19
24
  request = Request.new(
20
- "/#{ space_id }/webhook_definitions",
21
- parameters
25
+ "/#{space_id}/webhook_definitions",
26
+ parameters
22
27
  )
23
28
  response = request.get
24
29
  result = ResourceBuilder.new(response, {}, {})
@@ -26,37 +31,51 @@ module Contentful
26
31
  end
27
32
 
28
33
  # Gets a specific webhook.
29
- # Takes an id of space and webhook.
30
- # Returns a Contentful::Management::Webhook.
34
+ #
35
+ # @param [String] space_id
36
+ # @param [String] webhook_id
37
+ #
38
+ # @return [Contentful::Management::Webhook]
31
39
  def self.find(space_id, webhook_id)
32
- request = Request.new("/#{ space_id }/webhook_definitions/#{ webhook_id }")
40
+ request = Request.new("/#{space_id}/webhook_definitions/#{webhook_id}")
33
41
  response = request.get
34
42
  result = ResourceBuilder.new(response, {}, {})
35
43
  result.run
36
44
  end
37
45
 
38
46
  # Creates a webhook.
39
- # Takes a space id and hash with attributes (url, httpBasicUsername, httpBasicPassword)
40
- # Returns a Contentful::Management::Webhook.
47
+ #
48
+ # @param [String] space_id
49
+ # @param [Hash] attributes
50
+ # @option attributes [String] :url
51
+ # @option attributes [String] :httpBasicUsername
52
+ # @option attributes [String] :httpBasicPassword
53
+ #
54
+ # @return [Contentful::Management::Webhook]
41
55
  def self.create(space_id, attributes)
42
56
  id = attributes[:id]
43
57
  request = Request.new(
44
- "/#{ space_id }/webhook_definitions/#{ id }",
45
- endpoint_parameters(attributes)
58
+ "/#{space_id}/webhook_definitions/#{id}",
59
+ endpoint_parameters(attributes)
46
60
  )
47
61
  response = id.nil? ? request.post : request.put
48
62
  ResourceBuilder.new(response, {}, {}).run
49
63
  end
50
64
 
51
65
  # Updates a webhook.
52
- # Takes a hash with attributes.
53
- # Returns a Contentful::Management::Webhook.
66
+ #
67
+ # @param [Hash] attributes
68
+ # @option attributes [String] :url
69
+ # @option attributes [String] :httpBasicUsername
70
+ # @option attributes [String] :httpBasicPassword
71
+ #
72
+ # @return [Contentful::Management::Webhook]
54
73
  def update(attributes)
55
74
  request = Request.new(
56
- "/#{ space.id }/webhook_definitions/#{ id }",
57
- self.class.endpoint_parameters(attributes),
58
- id = nil,
59
- version: sys[:version]
75
+ "/#{space.id}/webhook_definitions/#{id}",
76
+ self.class.endpoint_parameters(attributes),
77
+ nil,
78
+ version: sys[:version]
60
79
  )
61
80
  response = request.put
62
81
  result = ResourceBuilder.new(response, {}, {})
@@ -64,18 +83,20 @@ module Contentful
64
83
  end
65
84
 
66
85
  # Destroys an webhook.
67
- # Returns true if succeed.
86
+ #
87
+ # @return [true, Contentful::Management::Error] success
68
88
  def destroy
69
- request = Request.new("/#{ space.id }/webhook_definitions/#{ id }")
89
+ request = Request.new("/#{space.id}/webhook_definitions/#{id}")
70
90
  response = request.delete
71
91
  if response.status == :no_content
72
- return true
92
+ true
73
93
  else
74
94
  result = ResourceBuilder.new(response, {}, {})
75
95
  result.run
76
96
  end
77
97
  end
78
98
 
99
+ # @private
79
100
  def self.endpoint_parameters(attributes)
80
101
  attributes.select { |key, _value| [:httpBasicUsername, :httpBasicPassword, :url].include? key }
81
102
  end
@@ -0,0 +1,194 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/bjwq7b86vgmm/api_keys
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - RubyContentfulManagementGem/0.8.0
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Content-Length:
17
+ - '0'
18
+ Connection:
19
+ - close
20
+ Host:
21
+ - api.contentful.com
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Accept-Ranges:
28
+ - bytes
29
+ Access-Control-Allow-Headers:
30
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation
31
+ Access-Control-Allow-Methods:
32
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Expose-Headers:
36
+ - Etag
37
+ Access-Control-Max-Age:
38
+ - '1728000'
39
+ Cache-Control:
40
+ - max-age=0
41
+ Content-Type:
42
+ - application/vnd.contentful.management.v1+json
43
+ Date:
44
+ - Tue, 26 Jan 2016 13:11:06 GMT
45
+ Etag:
46
+ - '"bf2ed3f9a14d5d32893e02c307f6214d"'
47
+ Server:
48
+ - nginx
49
+ Status:
50
+ - 200 OK
51
+ Strict-Transport-Security:
52
+ - max-age=15768000
53
+ X-Content-Type-Options:
54
+ - nosniff
55
+ X-Contentful-Request-Id:
56
+ - 9e1-668687247
57
+ Content-Length:
58
+ - '2871'
59
+ Connection:
60
+ - Close
61
+ body:
62
+ encoding: UTF-8
63
+ string: |+
64
+ {
65
+ "sys":{
66
+ "type":"Array"
67
+ },
68
+ "items":[
69
+ {
70
+ "sys":{
71
+ "type":"ApiKey",
72
+ "id":"6vbW35TjBTc8FyRTAuXZZe",
73
+ "version":0,
74
+ "space":{
75
+ "sys":{
76
+ "type":"Link",
77
+ "linkType":"Space",
78
+ "id":"bjwq7b86vgmm"
79
+ }
80
+ },
81
+ "createdBy":{
82
+ "sys":{
83
+ "type":"Link",
84
+ "linkType":"User",
85
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
86
+ }
87
+ },
88
+ "createdAt":"2016-01-26T02:31:31Z",
89
+ "updatedBy":{
90
+ "sys":{
91
+ "type":"Link",
92
+ "linkType":"User",
93
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
94
+ }
95
+ },
96
+ "updatedAt":"2016-01-26T02:31:31Z"
97
+ },
98
+ "name":"testKey",
99
+ "description":null,
100
+ "accessToken":"833ea085204398499ea424c8ad832f1ae1cac4d64e2cc56db774aff87ef20b33",
101
+ "policies":[
102
+ {
103
+ "effect":"allow",
104
+ "actions":"all"
105
+ }
106
+ ]
107
+ },
108
+ {
109
+ "sys":{
110
+ "type":"ApiKey",
111
+ "id":"1hGMMHcRIRDQuZFQvANxny",
112
+ "version":0,
113
+ "space":{
114
+ "sys":{
115
+ "type":"Link",
116
+ "linkType":"Space",
117
+ "id":"bjwq7b86vgmm"
118
+ }
119
+ },
120
+ "createdBy":{
121
+ "sys":{
122
+ "type":"Link",
123
+ "linkType":"User",
124
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
125
+ }
126
+ },
127
+ "createdAt":"2016-01-26T12:49:30Z",
128
+ "updatedBy":{
129
+ "sys":{
130
+ "type":"Link",
131
+ "linkType":"User",
132
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
133
+ }
134
+ },
135
+ "updatedAt":"2016-01-26T12:49:30Z"
136
+ },
137
+ "name":"otherKey",
138
+ "description":null,
139
+ "accessToken":"163ce7aaa3d87d9cbc25fd846d2bd7d70c3a707a5e9ebd7adfcb3bc773a51fd3",
140
+ "policies":[
141
+ {
142
+ "effect":"allow",
143
+ "actions":"all"
144
+ }
145
+ ]
146
+ },
147
+ {
148
+ "sys":{
149
+ "type":"ApiKey",
150
+ "id":"1nlVhF1rbb6iLWCdm72QVi",
151
+ "version":0,
152
+ "space":{
153
+ "sys":{
154
+ "type":"Link",
155
+ "linkType":"Space",
156
+ "id":"bjwq7b86vgmm"
157
+ }
158
+ },
159
+ "createdBy":{
160
+ "sys":{
161
+ "type":"Link",
162
+ "linkType":"User",
163
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
164
+ }
165
+ },
166
+ "createdAt":"2016-01-26T13:11:03Z",
167
+ "updatedBy":{
168
+ "sys":{
169
+ "type":"Link",
170
+ "linkType":"User",
171
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
172
+ }
173
+ },
174
+ "updatedAt":"2016-01-26T13:11:03Z"
175
+ },
176
+ "name":"testLocalCreate",
177
+ "description":"bg",
178
+ "accessToken":"b8d6f1bfac699f3eeceb9ee61711d9e1011e7fcbaf6836961e706c3cd49d7751",
179
+ "policies":[
180
+ {
181
+ "effect":"allow",
182
+ "actions":"all"
183
+ }
184
+ ]
185
+ }
186
+ ],
187
+ "total":3,
188
+ "limit":25,
189
+ "skip":0
190
+ }
191
+
192
+ http_version:
193
+ recorded_at: Tue, 26 Jan 2016 13:11:06 GMT
194
+ recorded_with: VCR 2.9.3