contentful-management 2.9.1 → 2.13.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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +30 -13
  4. data/contentful-management.gemspec +6 -5
  5. data/lib/contentful/management/client.rb +10 -12
  6. data/lib/contentful/management/{client_usage_period_methods_factory.rb → client_organization_periodic_usage_methods_factory.rb} +3 -4
  7. data/lib/contentful/management/client_space_methods_factory.rb +2 -2
  8. data/lib/contentful/management/{client_api_usage_methods_factory.rb → client_space_periodic_usage_methods_factory.rb} +4 -11
  9. data/lib/contentful/management/entry.rb +14 -12
  10. data/lib/contentful/management/field.rb +3 -1
  11. data/lib/contentful/management/organization.rb +18 -8
  12. data/lib/contentful/management/{api_usage.rb → organization_periodic_usage.rb} +13 -18
  13. data/lib/contentful/management/organization_user_methods_factory.rb +18 -0
  14. data/lib/contentful/management/resource.rb +3 -2
  15. data/lib/contentful/management/resource/environment_aware.rb +11 -8
  16. data/lib/contentful/management/resource_builder.rb +4 -4
  17. data/lib/contentful/management/space.rb +12 -2
  18. data/lib/contentful/management/{usage_period.rb → space_periodic_usage.rb} +12 -9
  19. data/lib/contentful/management/space_user_methods_factory.rb +19 -0
  20. data/lib/contentful/management/user.rb +7 -1
  21. data/lib/contentful/management/validation.rb +6 -1
  22. data/lib/contentful/management/version.rb +1 -1
  23. data/spec/fixtures/vcr_cassettes/asset/196_environment_id.yml +140 -0
  24. data/spec/fixtures/vcr_cassettes/content_type/196_retain_environment_id.yml +150 -0
  25. data/spec/fixtures/vcr_cassettes/entry/issue_215_1.yml +905 -0
  26. data/spec/fixtures/vcr_cassettes/entry/issue_215_2.yml +899 -0
  27. data/spec/fixtures/vcr_cassettes/entry/issue_215_3.yml +893 -0
  28. data/spec/fixtures/vcr_cassettes/organization/user.yml +238 -0
  29. data/spec/fixtures/vcr_cassettes/organization_periodic_usage/all.yml +368 -0
  30. data/spec/fixtures/vcr_cassettes/organization_periodic_usage/filters.yml +167 -0
  31. data/spec/fixtures/vcr_cassettes/space/user.yml +254 -0
  32. data/spec/fixtures/vcr_cassettes/space_periodic_usage/all.yml +6800 -0
  33. data/spec/fixtures/vcr_cassettes/space_periodic_usage/filters.yml +1976 -0
  34. data/spec/lib/contentful/management/asset_spec.rb +8 -0
  35. data/spec/lib/contentful/management/content_type_spec.rb +6 -0
  36. data/spec/lib/contentful/management/entry_spec.rb +48 -0
  37. data/spec/lib/contentful/management/organization_periodic_usage_spec.rb +36 -0
  38. data/spec/lib/contentful/management/organization_spec.rb +20 -0
  39. data/spec/lib/contentful/management/space_periodic_usage_spec.rb +36 -0
  40. data/spec/lib/contentful/management/space_spec.rb +20 -0
  41. metadata +68 -34
  42. data/spec/fixtures/vcr_cassettes/api_usage/all.yml +0 -155
  43. data/spec/fixtures/vcr_cassettes/usage_period/all.yml +0 -114
  44. data/spec/lib/contentful/management/api_usage_spec.rb +0 -28
  45. data/spec/lib/contentful/management/usage_period_spec.rb +0 -27
@@ -6,14 +6,17 @@ module Contentful
6
6
  # Gets the environment ID for the resource.
7
7
  def environment_id
8
8
  env = sys.fetch(:environment, {})
9
- case env
10
- when ::Hash
11
- env.fetch(:id, 'master')
12
- when ::Contentful::Management::Link
13
- env.id
14
- else
15
- 'master'
16
- end
9
+ env_from_sys =
10
+ case env
11
+ when ::Hash
12
+ env.fetch(:id, nil)
13
+ when ::Contentful::Management::Link, ::Contentful::Management::Environment
14
+ env.id
15
+ end
16
+
17
+ return env_from_sys if env_from_sys
18
+
19
+ respond_to?(:content_type) && content_type && content_type.environment_id || 'master'
17
20
  end
18
21
  end
19
22
  end
@@ -12,9 +12,7 @@ require_relative 'webhook'
12
12
  require_relative 'api_key'
13
13
  require_relative 'resource'
14
14
  require_relative 'snapshot'
15
- require_relative 'api_usage'
16
15
  require_relative 'environment'
17
- require_relative 'usage_period'
18
16
  require_relative 'organization'
19
17
  require_relative 'content_type'
20
18
  require_relative 'webhook_call'
@@ -24,7 +22,9 @@ require_relative 'webhook_health'
24
22
  require_relative 'preview_api_key'
25
23
  require_relative 'space_membership'
26
24
  require_relative 'editor_interface'
25
+ require_relative 'space_periodic_usage'
27
26
  require_relative 'personal_access_token'
27
+ require_relative 'organization_periodic_usage'
28
28
 
29
29
  module Contentful
30
30
  module Management
@@ -37,8 +37,8 @@ module Contentful
37
37
  'Space' => Contentful::Management::Space,
38
38
  'SpaceMembership' => Contentful::Management::SpaceMembership,
39
39
  'Organization' => Contentful::Management::Organization,
40
- 'ApiUsage' => Contentful::Management::ApiUsage,
41
- 'UsagePeriod' => Contentful::Management::UsagePeriod,
40
+ 'SpacePeriodicUsage' => Contentful::Management::SpacePeriodicUsage,
41
+ 'OrganizationPeriodicUsage' => Contentful::Management::OrganizationPeriodicUsage,
42
42
  'User' => Contentful::Management::User,
43
43
  'Environment' => Contentful::Management::Environment,
44
44
  'ContentType' => Contentful::Management::ContentType,
@@ -6,6 +6,7 @@ require_relative 'resource'
6
6
  require_relative 'environment'
7
7
  require_relative 'space_membership'
8
8
  require_relative 'space_role_methods_factory'
9
+ require_relative 'space_user_methods_factory'
9
10
  require_relative 'space_webhook_methods_factory'
10
11
  require_relative 'space_api_key_methods_factory'
11
12
  require_relative 'space_environment_methods_factory'
@@ -35,8 +36,8 @@ module Contentful
35
36
  # @param [Contentful::Management::Client] client
36
37
  #
37
38
  # @return [Contentful::Management::Array<Contentful::Management::Space>]
38
- def self.all(client)
39
- ClientSpaceMethodsFactory.new(client).all
39
+ def self.all(client, query = {})
40
+ ClientSpaceMethodsFactory.new(client).all(query)
40
41
  end
41
42
 
42
43
  # Gets a specific space.
@@ -155,6 +156,15 @@ module Contentful
155
156
  SpaceRoleMethodsFactory.new(self)
156
157
  end
157
158
 
159
+ # Allows viewing of users in context of the current space
160
+ # Allows listing all users of space, and finding one by ID.
161
+ # @see _ README for details.
162
+ #
163
+ # @return [Contentful::Management::SpaceUserMethodsFactory]
164
+ def users
165
+ SpaceUserMethodsFactory.new(self)
166
+ end
167
+
158
168
  # Allows manipulation of webhooks in context of the current space
159
169
  # Allows listing all webhooks for space and finding one by ID.
160
170
  # @see _ README for details.
@@ -2,32 +2,35 @@ require_relative 'resource'
2
2
 
3
3
  module Contentful
4
4
  module Management
5
- # Resource class for UsagePeriod.
6
- # @see _ https://www.contentful.com/developers/docs/references/content-management-api/#/reference/api-usages
7
- class UsagePeriod
5
+ # Resource class for SpacePeriodicUsage.
6
+ # @see _ https://www.contentful.com/developers/docs/references/content-management-api/#/reference/usage/space-usage/get-space-usage/console/curl
7
+ class SpacePeriodicUsage
8
8
  include Contentful::Management::Resource
9
9
  include Contentful::Management::Resource::Refresher
10
10
  include Contentful::Management::Resource::SystemProperties
11
11
 
12
- property :startDate, :date
13
- property :endDate, :date
12
+ property :metric, :string
13
+ property :usage, :integer
14
+ property :usagePerDay, :object
15
+ property :unitOfMeasure, :string
16
+ property :dateRange, :object
14
17
 
15
18
  # @private
16
19
  def self.build_endpoint(endpoint_options)
17
20
  organization_id = endpoint_options[:organization_id]
18
21
 
19
- "organizations/#{organization_id}/usage_periods"
22
+ "organizations/#{organization_id}/space_periodic_usages"
20
23
  end
21
24
 
22
- # Gets all usage periods for a given organization.
25
+ # Gets all space periodic usages for a given organization.
23
26
  #
24
27
  # @param [Contentful::Management::Client] client
25
28
  # @param [String] organization_id
26
29
  # @param [Hash] params
27
30
  #
28
- # @return [Contentful::Management::Array<Contentful::Management::UsagePeriod>]
31
+ # @return [Contentful::Management::Array<Contentful::Management::SpacePeriodicUsage>]
29
32
  def self.all(client, organization_id, params = {})
30
- ClientUsagePeriodMethodsFactory.new(client, organization_id).all(params)
33
+ ClientSpacePeriodicUsageMethodsFactory.new(client, organization_id).all(params)
31
34
  end
32
35
 
33
36
  # Not supported
@@ -0,0 +1,19 @@
1
+ require_relative 'space_association_methods_factory'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Wrapper for User API for usage from within Space
6
+ # @private
7
+ class SpaceUserMethodsFactory
8
+ attr_reader :space
9
+
10
+ def initialize(space)
11
+ @space = space
12
+ end
13
+
14
+ def find(id)
15
+ User.find(space.client, space.id, nil, id)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -19,7 +19,13 @@ module Contentful
19
19
 
20
20
  # @private
21
21
  def self.build_endpoint(endpoint_options)
22
- endpoint = 'users'
22
+ endpoint = if endpoint_options[:space_id]
23
+ "spaces/#{endpoint_options[:space_id]}/users"
24
+ elsif endpoint_options[:organization_id]
25
+ "organizations/#{endpoint_options[:organization_id]}/users"
26
+ else
27
+ 'users'
28
+ end
23
29
  endpoint = "#{endpoint}/#{endpoint_options[:resource_id]}" if endpoint_options[:resource_id]
24
30
  endpoint
25
31
  end
@@ -4,6 +4,9 @@ module Contentful
4
4
  module Management
5
5
  # A ContentType's validations schema
6
6
  class Validation
7
+ # Properties not specific to a field type validation
8
+ NON_TYPE_PROPERTIES = %i[validations message].freeze
9
+
7
10
  include Contentful::Management::Resource
8
11
 
9
12
  property :in, :array
@@ -19,6 +22,8 @@ module Contentful
19
22
  property :assetImageDimensions, :hash
20
23
  property :enabledNodeTypes, :array
21
24
  property :enabledMarks, :array
25
+ property :nodes, :hash
26
+ property :message, :string
22
27
 
23
28
  # @private
24
29
  def properties_to_hash
@@ -30,7 +35,7 @@ module Contentful
30
35
  # Returns type of validation
31
36
  # @return [Symbol]
32
37
  def type
33
- properties.keys.reject { |key| key == :validations }.each do |type|
38
+ properties.keys.reject { |key| NON_TYPE_PROPERTIES.include?(key) }.each do |type|
34
39
  value = send(Support.snakify(type))
35
40
  return type if !value.nil? && value
36
41
  end
@@ -3,6 +3,6 @@ module Contentful
3
3
  # Management Namespace
4
4
  module Management
5
5
  # Gem Version
6
- VERSION = '2.9.1'.freeze
6
+ VERSION = '2.13.0'.freeze
7
7
  end
8
8
  end
@@ -0,0 +1,140 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/facgnwwgj5fe/environments/testing
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Contentful-User-Agent:
11
+ - sdk contentful-management.rb/2.10.0; platform ruby/2.6.3; os macOS/18;
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Connection:
17
+ - close
18
+ Host:
19
+ - api.contentful.com
20
+ User-Agent:
21
+ - http.rb/2.2.2
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,X-Contentful-User-Agent,X-Contentful-Enable-Alpha-Feature,X-Contentful-Source-Environment,X-Contentful-Team,X-Contentful-Parent-Id
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
+ Cf-Organization-Id:
42
+ - 4SsuxQCaMaemfIms52Jr8s
43
+ Cf-Space-Id:
44
+ - facgnwwgj5fe
45
+ Content-Type:
46
+ - application/vnd.contentful.management.v1+json
47
+ Contentful-Api:
48
+ - cma
49
+ Date:
50
+ - Wed, 12 Jun 2019 09:50:55 GMT
51
+ Etag:
52
+ - W/"b5f8d465c58fdb2d4de7e800b00f1eaa"
53
+ Referrer-Policy:
54
+ - strict-origin-when-cross-origin
55
+ Server:
56
+ - Contentful
57
+ Strict-Transport-Security:
58
+ - max-age=15768000
59
+ X-Content-Type-Options:
60
+ - nosniff
61
+ X-Contentful-Ratelimit-Hour-Limit:
62
+ - '36000'
63
+ X-Contentful-Ratelimit-Hour-Remaining:
64
+ - '35999'
65
+ X-Contentful-Ratelimit-Reset:
66
+ - '0'
67
+ X-Contentful-Ratelimit-Second-Limit:
68
+ - '10'
69
+ X-Contentful-Ratelimit-Second-Remaining:
70
+ - '9'
71
+ X-Contentful-Request-Id:
72
+ - 2373953b0bf0c685ba5661a9fe0b5d67
73
+ X-Download-Options:
74
+ - noopen
75
+ X-Frame-Options:
76
+ - ALLOWALL
77
+ X-Permitted-Cross-Domain-Policies:
78
+ - none
79
+ X-Xss-Protection:
80
+ - 1; mode=block
81
+ Content-Length:
82
+ - '692'
83
+ Connection:
84
+ - Close
85
+ Set-Cookie:
86
+ - incap_ses_1077_673446=RtgaHDXP7XMdFb6xI0byDv/KAF0AAAAACSGiFccitmBt23MZnqPWxA==;
87
+ path=/; Domain=.contentful.com
88
+ - nlbi_673446=7nwaCaO7f3nYLwxVYMlkBAAAAAD3ZpP6TCMI5gIrwYpyuK9W; path=/; Domain=.contentful.com
89
+ - visid_incap_673446=HtXBvewwRv2t0RzGAoorGv/KAF0AAAAAQUIPAAAAAABa3NNCQ4sPwmHFDGhpUKoq;
90
+ expires=Thu, 11 Jun 2020 08:51:05 GMT; path=/; Domain=.contentful.com
91
+ X-Iinfo:
92
+ - 4-7987266-7987270 NNNN CT(108 108 0) RT(1560333054770 102) q(0 0 2 -1) r(4
93
+ 4) U5
94
+ X-Cdn:
95
+ - Incapsula
96
+ body:
97
+ encoding: ASCII-8BIT
98
+ string: |+
99
+ {
100
+ "name":"testing 2",
101
+ "sys":{
102
+ "type":"Environment",
103
+ "id":"testing",
104
+ "version":7,
105
+ "space":{
106
+ "sys":{
107
+ "type":"Link",
108
+ "linkType":"Space",
109
+ "id":"facgnwwgj5fe"
110
+ }
111
+ },
112
+ "status":{
113
+ "sys":{
114
+ "type":"Link",
115
+ "linkType":"Status",
116
+ "id":"ready"
117
+ }
118
+ },
119
+ "createdBy":{
120
+ "sys":{
121
+ "type":"Link",
122
+ "linkType":"User",
123
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
124
+ }
125
+ },
126
+ "createdAt":"2018-02-27T10:19:01Z",
127
+ "updatedBy":{
128
+ "sys":{
129
+ "type":"Link",
130
+ "linkType":"User",
131
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
132
+ }
133
+ },
134
+ "updatedAt":"2019-04-02T13:32:30Z"
135
+ }
136
+ }
137
+
138
+ http_version:
139
+ recorded_at: Wed, 12 Jun 2019 09:50:55 GMT
140
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,150 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/facgnwwgj5fe/environments/testing/content_types/foo
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Contentful-User-Agent:
11
+ - sdk contentful-management.rb/2.10.0; platform ruby/2.6.3; os macOS/18;
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Connection:
17
+ - close
18
+ Host:
19
+ - api.contentful.com
20
+ User-Agent:
21
+ - http.rb/2.2.2
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Access-Control-Allow-Headers:
28
+ - 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,X-Contentful-User-Agent,X-Contentful-Enable-Alpha-Feature,X-Contentful-Source-Environment,X-Contentful-Team,X-Contentful-Parent-Id
29
+ Access-Control-Allow-Methods:
30
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Expose-Headers:
34
+ - Etag
35
+ Access-Control-Max-Age:
36
+ - '1728000'
37
+ Cf-Environment-Id:
38
+ - testing
39
+ Cf-Space-Id:
40
+ - facgnwwgj5fe
41
+ Content-Type:
42
+ - application/vnd.contentful.management.v1+json
43
+ Contentful-Api:
44
+ - cma
45
+ Date:
46
+ - Wed, 12 Jun 2019 09:53:39 GMT
47
+ Etag:
48
+ - '"0b2c5704e213e8a4a0dd2c52b41f69f6"'
49
+ Server:
50
+ - Contentful
51
+ Strict-Transport-Security:
52
+ - max-age=15768000
53
+ X-Content-Type-Options:
54
+ - nosniff
55
+ X-Contentful-Ratelimit-Hour-Limit:
56
+ - '36000'
57
+ X-Contentful-Ratelimit-Hour-Remaining:
58
+ - '35999'
59
+ X-Contentful-Ratelimit-Reset:
60
+ - '0'
61
+ X-Contentful-Ratelimit-Second-Limit:
62
+ - '10'
63
+ X-Contentful-Ratelimit-Second-Remaining:
64
+ - '9'
65
+ X-Contentful-Request-Id:
66
+ - f5fddca25cc4f8e04c8d81881e6e7701
67
+ Content-Length:
68
+ - '1291'
69
+ Connection:
70
+ - Close
71
+ Set-Cookie:
72
+ - incap_ses_1077_673446=BpbBNbCuYjrQIb6xI0byDqPLAF0AAAAAZh/XsY8rfyTQa65eQDXXQA==;
73
+ path=/; Domain=.contentful.com
74
+ - nlbi_673446=EDV6F0YIwmCvoc7iYMlkBAAAAACzIXkMlBj6/0YOnyu4iuW5; path=/; Domain=.contentful.com
75
+ - visid_incap_673446=RDpZ/bR1RpCWIvRJhiD7DaPLAF0AAAAAQUIPAAAAAADdNxoQbzqM+ClPhb8yvpKl;
76
+ expires=Thu, 11 Jun 2020 08:51:29 GMT; path=/; Domain=.contentful.com
77
+ X-Iinfo:
78
+ - 13-3220957-3220958 NNNN CT(0 0 0) RT(1560333218442 92) q(0 0 0 -1) r(10 10)
79
+ U5
80
+ X-Cdn:
81
+ - Incapsula
82
+ body:
83
+ encoding: ASCII-8BIT
84
+ string: |
85
+ {
86
+ "sys": {
87
+ "space": {
88
+ "sys": {
89
+ "type": "Link",
90
+ "linkType": "Space",
91
+ "id": "facgnwwgj5fe"
92
+ }
93
+ },
94
+ "id": "foo",
95
+ "type": "ContentType",
96
+ "createdAt": "2017-03-02T19:32:52.225Z",
97
+ "updatedAt": "2017-03-10T15:38:16.371Z",
98
+ "environment": {
99
+ "sys": {
100
+ "id": "testing",
101
+ "type": "Link",
102
+ "linkType": "Environment"
103
+ }
104
+ },
105
+ "publishedVersion": 6,
106
+ "publishedAt": "2017-03-02T22:41:20.685Z",
107
+ "firstPublishedAt": "2017-03-02T21:51:34.581Z",
108
+ "createdBy": {
109
+ "sys": {
110
+ "type": "Link",
111
+ "linkType": "User",
112
+ "id": "4SejVrWT96dvL9IV4Nb7sQ"
113
+ }
114
+ },
115
+ "updatedBy": {
116
+ "sys": {
117
+ "type": "Link",
118
+ "linkType": "User",
119
+ "id": "4SejVrWT96dvL9IV4Nb7sQ"
120
+ }
121
+ },
122
+ "publishedCounter": 3,
123
+ "version": 9,
124
+ "publishedBy": {
125
+ "sys": {
126
+ "type": "Link",
127
+ "linkType": "User",
128
+ "id": "4SejVrWT96dvL9IV4Nb7sQ"
129
+ }
130
+ }
131
+ },
132
+ "displayField": "name",
133
+ "name": "foo",
134
+ "description": "",
135
+ "fields": [
136
+ {
137
+ "id": "name",
138
+ "name": "name",
139
+ "type": "Symbol",
140
+ "localized": false,
141
+ "required": false,
142
+ "validations": [],
143
+ "disabled": false,
144
+ "omitted": false
145
+ }
146
+ ]
147
+ }
148
+ http_version:
149
+ recorded_at: Wed, 12 Jun 2019 09:53:40 GMT
150
+ recorded_with: VCR 4.0.0