contentful-management 2.9.0 → 2.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -0
- data/README.md +19 -13
- data/contentful-management.gemspec +6 -5
- data/lib/contentful/management/client.rb +10 -12
- data/lib/contentful/management/{client_usage_period_methods_factory.rb → client_organization_periodic_usage_methods_factory.rb} +3 -4
- data/lib/contentful/management/client_space_methods_factory.rb +2 -2
- data/lib/contentful/management/{client_api_usage_methods_factory.rb → client_space_periodic_usage_methods_factory.rb} +4 -11
- data/lib/contentful/management/entry.rb +14 -12
- data/lib/contentful/management/environment.rb +3 -2
- data/lib/contentful/management/organization.rb +8 -8
- data/lib/contentful/management/{api_usage.rb → organization_periodic_usage.rb} +13 -18
- data/lib/contentful/management/resource.rb +7 -4
- data/lib/contentful/management/resource/environment_aware.rb +11 -8
- data/lib/contentful/management/resource_builder.rb +5 -6
- data/lib/contentful/management/space.rb +2 -2
- data/lib/contentful/management/{usage_period.rb → space_periodic_usage.rb} +12 -9
- data/lib/contentful/management/validation.rb +6 -1
- data/lib/contentful/management/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/asset/196_environment_id.yml +140 -0
- data/spec/fixtures/vcr_cassettes/content_type/196_retain_environment_id.yml +150 -0
- data/spec/fixtures/vcr_cassettes/entry/issue_215_1.yml +905 -0
- data/spec/fixtures/vcr_cassettes/entry/issue_215_2.yml +899 -0
- data/spec/fixtures/vcr_cassettes/entry/issue_215_3.yml +893 -0
- data/spec/fixtures/vcr_cassettes/organization_periodic_usage/all.yml +368 -0
- data/spec/fixtures/vcr_cassettes/organization_periodic_usage/filters.yml +167 -0
- data/spec/fixtures/vcr_cassettes/space_periodic_usage/all.yml +6800 -0
- data/spec/fixtures/vcr_cassettes/space_periodic_usage/filters.yml +1976 -0
- data/spec/lib/contentful/management/asset_spec.rb +8 -0
- data/spec/lib/contentful/management/content_type_spec.rb +6 -0
- data/spec/lib/contentful/management/entry_spec.rb +48 -0
- data/spec/lib/contentful/management/organization_periodic_usage_spec.rb +36 -0
- data/spec/lib/contentful/management/space_periodic_usage_spec.rb +36 -0
- metadata +60 -32
- data/spec/fixtures/vcr_cassettes/api_usage/all.yml +0 -155
- data/spec/fixtures/vcr_cassettes/usage_period/all.yml +0 -114
- data/spec/lib/contentful/management/api_usage_spec.rb +0 -28
- data/spec/lib/contentful/management/usage_period_spec.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 713c97cfc5294398f42d62da51db32197d2117fff66bc2161741b463593a56f0
|
4
|
+
data.tar.gz: 78627973b71ab35edf5239e2d5c08ec90c752ff11fcf76966585715849a77d60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '019005f468ed53914a758a7853e5f59535ec03c29a726d6fa8a678418cd42da3de6539d11db3426c03cf26d5cdd6c63bffbb3cd0b61aa4497466f82a5920c63d'
|
7
|
+
data.tar.gz: 5f65e0d107b4b909ad7678bbd7e108f3a101e39daa9b5e698335ca9efc09860ff16a500fbf7dfd52e398d70c4d5fc745c059c0f1a5921fe0a5499a7c9c9f11a3
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,43 @@
|
|
2
2
|
|
3
3
|
## Master
|
4
4
|
|
5
|
+
## 2.12.1
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
* Fixed an issue where JSON fields with top-level arrays were not properly parsed. [#215](https://github.com/contentful/contentful-management.rb/issues/215)
|
9
|
+
|
10
|
+
## 2.12.0
|
11
|
+
|
12
|
+
*Note*: Only a minor change because the removed feature was *Alpha*.
|
13
|
+
|
14
|
+
### Added
|
15
|
+
* Add `OrganizationPeriodicUsage`, `Client#organization_periodic_usages` and `Organization#periodic_usages`.
|
16
|
+
* Add `SpacePeriodicUsage`, `Client#space_periodic_usages` and `Organization#space_periodic_usages`.
|
17
|
+
|
18
|
+
### Removed
|
19
|
+
* Removed now deprecated Alpha Usage APIs, which have been superseeded by the new APIs added.
|
20
|
+
|
21
|
+
## 2.11.0
|
22
|
+
### Added
|
23
|
+
* Added support for Rich Text specific validations. [#200](https://github.com/contentful/contentful-management.rb/pull/200)
|
24
|
+
|
25
|
+
### Changed
|
26
|
+
* Updated maximum allowed version of the `http` gem. [#205](https://github.com/contentful/contentful-management.rb/issues/205)
|
27
|
+
|
28
|
+
## 2.10.0
|
29
|
+
### Added
|
30
|
+
* Added support for query parameters on the Space endpoints. [#197](https://github.com/contentful/contentful-management.rb/pull/197)
|
31
|
+
|
32
|
+
### Fixed
|
33
|
+
* Fixed environment aware resources that were not having the `environment_id` properly calculated. [#195](https://github.com/contentful/contentful-management.rb/pull/195)
|
34
|
+
|
35
|
+
### Changed
|
36
|
+
* Relaxed maximum allowed version of the `json` gem. [#196](https://github.com/contentful/contentful-management.rb/pull/196)
|
37
|
+
|
38
|
+
## 2.9.1
|
39
|
+
### Fixed
|
40
|
+
* Default locale is now fetched from the client instead of passed around. [#194](https://github.com/contentful/contentful-management.rb/pull/194)
|
41
|
+
|
5
42
|
## 2.9.0
|
6
43
|
### Added
|
7
44
|
* Added validations for Rich Text. [#193](https://github.com/contentful/contentful-management.rb/pull/193)
|
data/README.md
CHANGED
@@ -827,40 +827,46 @@ Retrieving all organization details:
|
|
827
827
|
organizations = client.organizations.all
|
828
828
|
```
|
829
829
|
|
830
|
-
### Usage
|
830
|
+
### Usage
|
831
831
|
|
832
832
|
*Note*: This feature is available only to Commited v2 customers.
|
833
833
|
|
834
|
-
|
834
|
+
#### Organization Periodic Usage
|
835
|
+
|
836
|
+
Retrieving all API Usage statistics for an Organization during a given usage period, broken down by organization for all APIs:
|
835
837
|
|
836
838
|
```ruby
|
837
|
-
|
839
|
+
# Optionally, you can pass the metric, start and end date filters
|
840
|
+
usage = client.organization_periodic_usages('organization_id').all
|
841
|
+
|
842
|
+
# For example only CDA and CMA metrics from yesterday onwards
|
843
|
+
usage = client.organization_periodic_usages('organization_id').all('metric[in]': ['cda', 'cma'], startDate: (Date.today - 1).iso8601)
|
838
844
|
```
|
839
845
|
|
840
846
|
Alternatively, if you have an already fetched organization:
|
841
847
|
|
842
848
|
```ruby
|
843
|
-
|
849
|
+
# Breaking down CMA usage by space, for a given period.
|
850
|
+
usage = organization.periodic_usages.all
|
844
851
|
```
|
845
852
|
|
846
|
-
|
853
|
+
#### Space Periodic Usage
|
847
854
|
|
848
|
-
|
849
|
-
|
850
|
-
Retrieving all API Usage statistics for an Organizations during a given usage period, broken down by organization for all APIs:
|
855
|
+
Retrieving all API Usage statistics for an Organization during a given usage period, broken down by space for all APIs:
|
851
856
|
|
852
857
|
```ruby
|
853
|
-
#
|
854
|
-
|
855
|
-
|
856
|
-
|
858
|
+
# Optionally, you can pass the metric, start and end date filters
|
859
|
+
usage = client.space_periodic_usages('organization_id').all
|
860
|
+
|
861
|
+
# For example only CDA and CMA metrics from yesterday onwards
|
862
|
+
usage = client.space_periodic_usages('organization_id').all('metric[in]': ['cda', 'cma'], startDate: (Date.today - 1).iso8601)
|
857
863
|
```
|
858
864
|
|
859
865
|
Alternatively, if you have an already fetched organization:
|
860
866
|
|
861
867
|
```ruby
|
862
868
|
# Breaking down CMA usage by space, for a given period.
|
863
|
-
usage = organization.
|
869
|
+
usage = organization.space_periodic_usages.all
|
864
870
|
```
|
865
871
|
|
866
872
|
### Users
|
@@ -17,12 +17,12 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_dependency 'http', '> 1.0', '<
|
20
|
+
spec.add_dependency 'http', '> 1.0', '< 5.0'
|
21
21
|
spec.add_dependency 'multi_json', '~> 1'
|
22
|
-
spec.add_dependency 'json', '
|
22
|
+
spec.add_dependency 'json', '>= 1.8', '< 3.0'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler'
|
25
|
-
spec.add_development_dependency 'rake', '
|
25
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
26
26
|
spec.add_development_dependency 'public_suffix', '< 1.5'
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3'
|
28
28
|
spec.add_development_dependency 'rspec-its'
|
@@ -32,7 +32,8 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'guard-yard'
|
33
33
|
spec.add_development_dependency 'rubocop', '~> 0.49.1'
|
34
34
|
spec.add_development_dependency 'listen', '~> 3.0'
|
35
|
-
spec.add_development_dependency 'vcr'
|
36
|
-
spec.add_development_dependency 'webmock'
|
35
|
+
spec.add_development_dependency 'vcr', '~> 4.0'
|
36
|
+
spec.add_development_dependency 'webmock'
|
37
|
+
spec.add_development_dependency 'tins', '~> 1.6.0'
|
37
38
|
spec.add_development_dependency 'simplecov'
|
38
39
|
end
|
@@ -20,9 +20,7 @@ require 'contentful/management/client_upload_methods_factory'
|
|
20
20
|
require 'contentful/management/client_api_key_methods_factory'
|
21
21
|
require 'contentful/management/client_webhook_methods_factory'
|
22
22
|
require 'contentful/management/client_snapshot_methods_factory'
|
23
|
-
require 'contentful/management/client_api_usage_methods_factory'
|
24
23
|
require 'contentful/management/client_environment_methods_factory'
|
25
|
-
require 'contentful/management/client_usage_period_methods_factory'
|
26
24
|
require 'contentful/management/client_organization_methods_factory'
|
27
25
|
require 'contentful/management/client_content_type_methods_factory'
|
28
26
|
require 'contentful/management/client_ui_extension_methods_factory'
|
@@ -31,7 +29,9 @@ require 'contentful/management/client_webhook_health_methods_factory'
|
|
31
29
|
require 'contentful/management/client_preview_api_key_methods_factory'
|
32
30
|
require 'contentful/management/client_space_membership_methods_factory'
|
33
31
|
require 'contentful/management/client_editor_interface_methods_factory'
|
32
|
+
require 'contentful/management/client_space_periodic_usage_methods_factory'
|
34
33
|
require 'contentful/management/client_personal_access_tokens_methods_factory'
|
34
|
+
require 'contentful/management/client_organization_periodic_usage_methods_factory'
|
35
35
|
|
36
36
|
module Contentful
|
37
37
|
module Management
|
@@ -133,22 +133,20 @@ module Contentful
|
|
133
133
|
ClientOrganizationMethodsFactory.new(self)
|
134
134
|
end
|
135
135
|
|
136
|
-
# Allows
|
137
|
-
# Allows listing all usage periods for client.
|
136
|
+
# Allows listing all usage periods for organization grouped by organization.
|
138
137
|
# @see _ README for details.
|
139
138
|
#
|
140
|
-
# @return [Contentful::Management::
|
141
|
-
def
|
142
|
-
|
139
|
+
# @return [Contentful::Management::ClientOrganizationPeriodicUsageMethodsFactory]
|
140
|
+
def organization_periodic_usages(organization_id)
|
141
|
+
ClientOrganizationPeriodicUsageMethodsFactory.new(self, organization_id)
|
143
142
|
end
|
144
143
|
|
145
|
-
# Allows
|
146
|
-
# Allows listing all api usage for client.
|
144
|
+
# Allows listing all usage periods for organization grouped by space.
|
147
145
|
# @see _ README for details.
|
148
146
|
#
|
149
|
-
# @return [Contentful::Management::
|
150
|
-
def
|
151
|
-
|
147
|
+
# @return [Contentful::Management::ClientSpacePeriodicUsageMethodsFactory]
|
148
|
+
def space_periodic_usages(organization_id)
|
149
|
+
ClientSpacePeriodicUsageMethodsFactory.new(self, organization_id)
|
152
150
|
end
|
153
151
|
|
154
152
|
# Allows viewing of users in context of the current client
|
@@ -2,9 +2,9 @@ require_relative 'client_association_methods_factory'
|
|
2
2
|
|
3
3
|
module Contentful
|
4
4
|
module Management
|
5
|
-
# Wrapper for
|
5
|
+
# Wrapper for Organization Periodic Usages for usage from within Client
|
6
6
|
# @private
|
7
|
-
class
|
7
|
+
class ClientOrganizationPeriodicUsageMethodsFactory
|
8
8
|
include Contentful::Management::ClientAssociationMethodsFactory
|
9
9
|
|
10
10
|
def initialize(client, organization_id)
|
@@ -17,8 +17,7 @@ module Contentful
|
|
17
17
|
{
|
18
18
|
organization_id: @organization_id
|
19
19
|
},
|
20
|
-
params
|
21
|
-
'x-contentful-enable-alpha-feature' => 'usage-insights'
|
20
|
+
params
|
22
21
|
)
|
23
22
|
end
|
24
23
|
|
@@ -15,8 +15,8 @@ module Contentful
|
|
15
15
|
# Gets a collection of spaces.
|
16
16
|
#
|
17
17
|
# @return [Contentful::Management::Array<Contentful::Management::Space>]
|
18
|
-
def all
|
19
|
-
@resource_requester.all
|
18
|
+
def all(query = {})
|
19
|
+
@resource_requester.all({}, query)
|
20
20
|
end
|
21
21
|
|
22
22
|
# Gets a specific space.
|
@@ -2,9 +2,9 @@ require_relative 'client_association_methods_factory'
|
|
2
2
|
|
3
3
|
module Contentful
|
4
4
|
module Management
|
5
|
-
# Wrapper for
|
5
|
+
# Wrapper for Space Periodic Usages for usage from within Client
|
6
6
|
# @private
|
7
|
-
class
|
7
|
+
class ClientSpacePeriodicUsageMethodsFactory
|
8
8
|
include Contentful::Management::ClientAssociationMethodsFactory
|
9
9
|
|
10
10
|
def initialize(client, organization_id)
|
@@ -12,19 +12,12 @@ module Contentful
|
|
12
12
|
@organization_id = organization_id
|
13
13
|
end
|
14
14
|
|
15
|
-
def all(
|
16
|
-
mandatory_params = {
|
17
|
-
'filters[usagePeriod]' => usage_period_id,
|
18
|
-
'filters[metric]' => api
|
19
|
-
}
|
20
|
-
|
15
|
+
def all(params = {})
|
21
16
|
@resource_requester.all(
|
22
17
|
{
|
23
|
-
usage_type: usage_type,
|
24
18
|
organization_id: @organization_id
|
25
19
|
},
|
26
|
-
|
27
|
-
'x-contentful-enable-alpha-feature' => 'usage-insights'
|
20
|
+
params
|
28
21
|
)
|
29
22
|
end
|
30
23
|
|
@@ -95,18 +95,20 @@ module Contentful
|
|
95
95
|
|
96
96
|
# @private
|
97
97
|
def self.parse_objects_array(attributes)
|
98
|
-
attributes.each_with_object([]) do |
|
99
|
-
if
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
98
|
+
attributes.each_with_object([]) do |attribute, result|
|
99
|
+
result << if attribute.is_a? Entry
|
100
|
+
hash_with_link_object('Entry', attribute)
|
101
|
+
elsif attribute.is_a? Asset
|
102
|
+
hash_with_link_object('Asset', attribute)
|
103
|
+
elsif attribute.is_a? Hash
|
104
|
+
attribute
|
105
|
+
elsif attribute.class.ancestors.map(&:to_s).include?('Contentful::Entry')
|
106
|
+
hash_with_link_object('Entry', attribute)
|
107
|
+
elsif attribute.class.ancestors.map(&:to_s).include?('Contentful::Asset')
|
108
|
+
hash_with_link_object('Asset', attribute)
|
109
|
+
else
|
110
|
+
attribute
|
111
|
+
end
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
@@ -139,8 +139,9 @@ module Contentful
|
|
139
139
|
# @return [String]
|
140
140
|
def find_locale
|
141
141
|
locale = locales.all.detect(&:default)
|
142
|
-
return locale.code
|
143
|
-
|
142
|
+
return locale.code if locale
|
143
|
+
|
144
|
+
default_locale
|
144
145
|
end
|
145
146
|
|
146
147
|
# @private
|
@@ -16,20 +16,20 @@ module Contentful
|
|
16
16
|
'organizations'
|
17
17
|
end
|
18
18
|
|
19
|
-
# Allows listing all usage periods for organization.
|
19
|
+
# Allows listing all usage periods for organization grouped by organization or space.
|
20
20
|
# @see _ README for details.
|
21
21
|
#
|
22
|
-
# @return [Contentful::Management::
|
23
|
-
def
|
24
|
-
|
22
|
+
# @return [Contentful::Management::ClientOrganizationPeriodicUsageMethodsFactory]
|
23
|
+
def periodic_usages
|
24
|
+
ClientOrganizationPeriodicUsageMethodsFactory.new(client, id)
|
25
25
|
end
|
26
26
|
|
27
|
-
# Allows listing all
|
27
|
+
# Allows listing all usage periods for organization grouped by organization or space.
|
28
28
|
# @see _ README for details.
|
29
29
|
#
|
30
|
-
# @return [Contentful::Management::
|
31
|
-
def
|
32
|
-
|
30
|
+
# @return [Contentful::Management::ClientSpacePeriodicUsageMethodsFactory]
|
31
|
+
def space_periodic_usages
|
32
|
+
ClientSpacePeriodicUsageMethodsFactory.new(client, id)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -2,40 +2,35 @@ require_relative 'resource'
|
|
2
2
|
|
3
3
|
module Contentful
|
4
4
|
module Management
|
5
|
-
# Resource class for
|
6
|
-
# @see _ https://www.contentful.com/developers/docs/references/content-management-api/#/reference/
|
7
|
-
class
|
5
|
+
# Resource class for OrganizationPeriodicUsage.
|
6
|
+
# @see _ https://www.contentful.com/developers/docs/references/content-management-api/#/reference/usage/organization-usage/get-organization-usage/console/curl
|
7
|
+
class OrganizationPeriodicUsage
|
8
8
|
include Contentful::Management::Resource
|
9
9
|
include Contentful::Management::Resource::Refresher
|
10
10
|
include Contentful::Management::Resource::SystemProperties
|
11
11
|
|
12
|
-
property :
|
13
|
-
property :
|
14
|
-
property :
|
15
|
-
property :
|
16
|
-
property :
|
12
|
+
property :metric, :string
|
13
|
+
property :usage, :integer
|
14
|
+
property :usagePerDay, :object
|
15
|
+
property :unitOfMeasure, :string
|
16
|
+
property :dateRange, :object
|
17
17
|
|
18
18
|
# @private
|
19
19
|
def self.build_endpoint(endpoint_options)
|
20
20
|
organization_id = endpoint_options[:organization_id]
|
21
|
-
usage_type = endpoint_options[:usage_type]
|
22
21
|
|
23
|
-
"organizations/#{organization_id}/
|
22
|
+
"organizations/#{organization_id}/organization_periodic_usages"
|
24
23
|
end
|
25
24
|
|
26
|
-
# Gets all
|
25
|
+
# Gets all organization periodic usages for a given organization.
|
27
26
|
#
|
28
27
|
# @param [Contentful::Management::Client] client
|
29
28
|
# @param [String] organization_id
|
30
|
-
# @param [String] usage_type
|
31
|
-
# @param [Integer] usage_period_id
|
32
|
-
# @param [String] api
|
33
29
|
# @param [Hash] params
|
34
30
|
#
|
35
|
-
# @return [Contentful::Management::Array<Contentful::Management::
|
36
|
-
|
37
|
-
|
38
|
-
ClientApiUsageMethodsFactory.new(client, organization_id).all(usage_type, usage_period_id, api, params)
|
31
|
+
# @return [Contentful::Management::Array<Contentful::Management::OrganizationPeriodicUsage>]
|
32
|
+
def self.all(client, organization_id, params = {})
|
33
|
+
ClientOrganizationPeriodicUsageMethodsFactory.new(client, organization_id).all(params)
|
39
34
|
end
|
40
35
|
|
41
36
|
# Not supported
|
@@ -27,18 +27,16 @@ module Contentful
|
|
27
27
|
}.freeze
|
28
28
|
# rubocop:enable Style/DoubleNegation
|
29
29
|
|
30
|
-
attr_reader :properties, :request, :
|
30
|
+
attr_reader :properties, :request, :raw_object
|
31
31
|
attr_accessor :client
|
32
32
|
|
33
33
|
# @private
|
34
34
|
def initialize(object = nil,
|
35
35
|
request = nil,
|
36
36
|
client = nil,
|
37
|
-
nested_locale_fields = false
|
38
|
-
default_locale = Contentful::Management::Client::DEFAULT_CONFIGURATION[:default_locale])
|
37
|
+
nested_locale_fields = false)
|
39
38
|
self.class.update_coercions!
|
40
39
|
@nested_locale_fields = nested_locale_fields
|
41
|
-
@default_locale = default_locale
|
42
40
|
|
43
41
|
@properties = extract_from_object object, :property, self.class.property_coercions.keys
|
44
42
|
@request = request
|
@@ -134,6 +132,11 @@ module Contentful
|
|
134
132
|
nil
|
135
133
|
end
|
136
134
|
|
135
|
+
# Get default_locale from client
|
136
|
+
def default_locale
|
137
|
+
client.default_locale
|
138
|
+
end
|
139
|
+
|
137
140
|
protected
|
138
141
|
|
139
142
|
def update_headers
|
@@ -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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|