contentful-management 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af6595494f26b3a85d5394e675069faa4518cfbb51b0fd7856da47a94a5e1d1d
4
- data.tar.gz: b7da54f816b90d302c91995ac77beb1c383b3b385872cccadb07dfde301fc0c0
3
+ metadata.gz: e9ee1535df6db39a73f0eba091acdeb3e90250e74a911e73faefc7fb23f90ef6
4
+ data.tar.gz: 92f738e34c2247f8b831fee2449a4702a1598b3be3b200ce37e1517e5ba700dc
5
5
  SHA512:
6
- metadata.gz: 6f04b5c262ee9182ad6562008968711b7df6627b03be6fc9b8a980594205560a0868c3de151c55a2c53c33e3da18805b8cdcb0b5ac4e1d8cd065bf721d0a09f2
7
- data.tar.gz: e7e855348fba05bcd88da84a4645d221203a4de67a3dd346866fc8423f41a877297306ca2b30585147c1915754a5a7ac3c2c872d175a9cb10102e6d161b55597
6
+ metadata.gz: 85026e49bf8c1a2915462600063a39098ea547732324d82a68885319732007683bca4191db95d5cc303fc90ed0954edc92be2b67022ff7df9c96387cd3972917
7
+ data.tar.gz: d3a7dbd58d80e868a0b70f544422dd1c1803f777ce0483295cf9f146d406bf22e41f5fa900e47aa739a6998b66a15236d921fa1878a88ffa94d1471cc9259441
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 2.1.0
6
+ ### Added
7
+ * Added environment selection option for Api Keys.
8
+ * Added a way to obtain Preview Api Keys.
9
+
10
+ ### Fixed
11
+ * Fixed `Link#resolve` not working for all resource types.
12
+
5
13
  ## 2.0.2
6
14
  ### Fixed
7
15
  * Fixed environment ID fetching for environment aware resources.
@@ -12,7 +20,7 @@
12
20
 
13
21
  ## 2.0.0
14
22
  ### Added
15
- * Added support for Environments
23
+ * Added support for Environments.
16
24
 
17
25
  ### Changed
18
26
 
data/README.md CHANGED
@@ -851,10 +851,56 @@ blog_post_api_key = blog_space.api_keys.find(api_key_id)
851
851
  ```
852
852
 
853
853
  Creating an API key:
854
+
854
855
  ```ruby
855
856
  blog_space.api_keys.create(name: 'foobar key', description: 'key for foobar mobile app')
856
857
  ```
857
858
 
859
+ Creating an API key with multiple environments:
860
+
861
+ ```ruby
862
+ blog_space.api_keys.create(
863
+ name: 'foobar key - multiple environments',
864
+ description: 'key for foobar app',
865
+ environments: [
866
+ {
867
+ sys: {
868
+ type: 'Link',
869
+ linkType: 'Environment',
870
+ id: 'master'
871
+ }
872
+ },
873
+ {
874
+ sys: {
875
+ type: 'Link',
876
+ linkType: 'Environment',
877
+ id: 'staging'
878
+ }
879
+ }
880
+ ]
881
+ )
882
+ ```
883
+
884
+ ### Preview API Keys
885
+
886
+ Retrieving all Preview API keys from the space:
887
+
888
+ ```ruby
889
+ blog_post_preview_api_keys = blog_space.preview_api_keys.all
890
+ ```
891
+
892
+ Retrieving one Preview API key by ID from the space:
893
+
894
+ ```ruby
895
+ blog_post_preview_api_key = blog_space.preview_api_keys.find(api_key_id)
896
+ ```
897
+
898
+ If you already have an API key fetched, you can retrieve the Preview API key from it:
899
+
900
+ ```ruby
901
+ blog_post_preview_api_key = blog_post_api_key.preview_api_key
902
+ ```
903
+
858
904
  ### Personal Access Tokens
859
905
 
860
906
  Retrieving all personal access tokens:
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'guard-rspec'
31
31
  spec.add_development_dependency 'guard-rubocop'
32
32
  spec.add_development_dependency 'guard-yard'
33
- spec.add_development_dependency 'rubocop', '~> 0.41.0'
33
+ spec.add_development_dependency 'rubocop', '~> 0.49.1'
34
34
  spec.add_development_dependency 'listen', '~> 3.0'
35
35
  spec.add_development_dependency 'vcr'
36
36
  spec.add_development_dependency 'webmock', '~> 1', '>= 1.17.3'
@@ -13,12 +13,15 @@ module Contentful
13
13
  property :policies
14
14
  property :description
15
15
  property :accessToken
16
+ property :environments
17
+ property :preview_api_key, Link
16
18
 
17
19
  # @private
18
20
  def self.create_attributes(_client, attributes)
19
21
  {
20
22
  'name' => attributes.fetch(:name),
21
- 'description' => attributes.fetch(:description, nil)
23
+ 'description' => attributes.fetch(:description, nil),
24
+ 'environments' => attributes.fetch(:environments, []) # Will default to master if empty
22
25
  }
23
26
  end
24
27
 
@@ -44,6 +47,18 @@ module Contentful
44
47
  def self.find(client, space_id, api_key_id)
45
48
  super(client, space_id, nil, api_key_id)
46
49
  end
50
+
51
+ # Returns the environment links associated to this Api Key
52
+ def environments
53
+ properties[:environments].map { |environment| Link.new(environment, nil, client) }
54
+ end
55
+
56
+ # Finds the Preview API Key associated to this API Key
57
+ #
58
+ # @return [Contentful::Management::PreviewApiKey]
59
+ def preview_api_key
60
+ client.preview_api_keys(space.id).find(properties[:preview_api_key].id)
61
+ end
47
62
  end
48
63
  end
49
64
  end
@@ -26,6 +26,7 @@ require 'contentful/management/client_content_type_methods_factory'
26
26
  require 'contentful/management/client_ui_extension_methods_factory'
27
27
  require 'contentful/management/client_webhook_call_methods_factory'
28
28
  require 'contentful/management/client_webhook_health_methods_factory'
29
+ require 'contentful/management/client_preview_api_key_methods_factory'
29
30
  require 'contentful/management/client_space_membership_methods_factory'
30
31
  require 'contentful/management/client_editor_interface_methods_factory'
31
32
  require 'contentful/management/client_personal_access_tokens_methods_factory'
@@ -148,6 +149,15 @@ module Contentful
148
149
  ClientApiKeyMethodsFactory.new(self, space_id)
149
150
  end
150
151
 
152
+ # Allows manipulation of api keys in context of the current client
153
+ # Allows listing all preview api keys for client and finding one by ID.
154
+ # @see _ README for details.
155
+ #
156
+ # @return [Contentful::Management::ClientPreviewApiKeyMethodsFactory]
157
+ def preview_api_keys(space_id)
158
+ ClientPreviewApiKeyMethodsFactory.new(self, space_id)
159
+ end
160
+
151
161
  # Allows manipulation of personal access tokens in context of the current client
152
162
  # Allows listing all personal access tokens for client, creating new and finding one by ID.
153
163
  # @see _ README for details.
@@ -375,7 +385,7 @@ module Contentful
375
385
 
376
386
  # @private
377
387
  def host_url(request)
378
- (%r{^spaces/[\w|-|_]+/uploads(?:/[\w|-|_]*)?$} =~ request.url) ? uploads_url : base_url
388
+ %r{^spaces/[\w|-|_]+/uploads(?:/[\w|-|_]*)?$} =~ request.url ? uploads_url : base_url
379
389
  end
380
390
 
381
391
  # @private
@@ -0,0 +1,23 @@
1
+ require_relative 'client_association_methods_factory'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Wrapper for PreviewApiKey API for usage from within Client
6
+ # @private
7
+ class ClientPreviewApiKeyMethodsFactory
8
+ include Contentful::Management::ClientAssociationMethodsFactory
9
+
10
+ def new(*)
11
+ fail 'Not supported'
12
+ end
13
+
14
+ def find(resource_id)
15
+ associated_class.find(client, @space_id, resource_id)
16
+ end
17
+
18
+ def create(*)
19
+ fail 'Not supported'
20
+ end
21
+ end
22
+ end
23
+ end
@@ -126,7 +126,7 @@ module Contentful
126
126
  end
127
127
 
128
128
  fields.define_singleton_method(:destroy) do |id|
129
- fields = content_type.fields.select { |field| field.id != id }
129
+ fields = content_type.fields.reject { |field| field.id == id }
130
130
  content_type.update(fields: fields)
131
131
  end
132
132
  end
@@ -231,6 +231,7 @@ module Contentful
231
231
  end
232
232
  end
233
233
 
234
+ # rubocop:disable Style/MethodMissing
234
235
  def method_missing(name, *args, &block)
235
236
  if content_type.nil?
236
237
  fetch_content_type
@@ -242,6 +243,7 @@ module Contentful
242
243
 
243
244
  fail NameError.new("undefined local variable or method `#{name}' for #{self.class}:#{sys[:id]}", name)
244
245
  end
246
+ # rubocop:enable Style/MethodMissing
245
247
 
246
248
  def fetch_content_type
247
249
  content_type_id = if sys[:contentType].is_a?(::Contentful::Management::Resource)
@@ -14,7 +14,7 @@ module Contentful
14
14
  def resolve(space_id = nil, environment_id = nil)
15
15
  return client.spaces.find(id) if link_type == 'Space'
16
16
 
17
- method = Contentful::Management::Support.snakify(link_type).to_sym
17
+ method = Contentful::Management::Support.base_path_for(link_type).to_sym
18
18
 
19
19
  if space_id && environment_id.nil?
20
20
  return client.public_send(
@@ -0,0 +1,29 @@
1
+ require_relative 'resource'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Resource class for PreviewApiKey.
6
+ # @see _ https://www.contentful.com/developers/docs/references/content-management-api/#/reference/api-keys/preview-api-key/get-a-single-preview-api-key
7
+ class PreviewApiKey
8
+ include Contentful::Management::Resource
9
+ include Contentful::Management::Resource::Refresher
10
+ include Contentful::Management::Resource::SystemProperties
11
+
12
+ property :name
13
+ property :description
14
+ property :accessToken
15
+ property :environments
16
+
17
+ # Finds a Preview API Key by ID.
18
+ #
19
+ # @param [Contentful::Management::Client] client
20
+ # @param [String] space_id
21
+ # @param [String] preview_api_key_id
22
+ #
23
+ # @return [Contentful::Management::PreviewApiKey]
24
+ def self.find(client, space_id, preview_api_key_id)
25
+ super(client, space_id, nil, preview_api_key_id)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -49,10 +49,11 @@ module Contentful
49
49
  # @private
50
50
  def self.create_setter_field(entry, field, value, locale, default_locale)
51
51
  fields = entry.instance_variable_get(:@fields)
52
- if localized_or_default_locale(field, default_locale, locale)
53
- fields[locale] ||= {}
54
- fields[locale][field.id.to_sym] = value
55
- end
52
+
53
+ return unless localized_or_default_locale(field, default_locale, locale)
54
+
55
+ fields[locale] ||= {}
56
+ fields[locale][field.id.to_sym] = value
56
57
  end
57
58
 
58
59
  # Verifies if field is localized or default locale matches current locale
@@ -52,8 +52,7 @@ module Contentful
52
52
  end
53
53
 
54
54
  # @private
55
- def after_create(_attributes)
56
- end
55
+ def after_create(_attributes); end
57
56
 
58
57
  # Updates a resource.
59
58
  #
@@ -19,6 +19,7 @@ require_relative 'webhook_call'
19
19
  require_relative 'ui_extension'
20
20
  require_relative 'dynamic_entry'
21
21
  require_relative 'webhook_health'
22
+ require_relative 'preview_api_key'
22
23
  require_relative 'space_membership'
23
24
  require_relative 'editor_interface'
24
25
  require_relative 'personal_access_token'
@@ -46,6 +47,7 @@ module Contentful
46
47
  'WebhookCallDetails' => Contentful::Management::WebhookCall,
47
48
  'Webhook' => Contentful::Management::WebhookHealth,
48
49
  'ApiKey' => Contentful::Management::ApiKey,
50
+ 'PreviewApiKey' => Contentful::Management::PreviewApiKey,
49
51
  'PersonalAccessToken' => Contentful::Management::PersonalAccessToken,
50
52
  'Locale' => Contentful::Management::Locale,
51
53
  'Role' => Contentful::Management::Role,
@@ -236,7 +238,7 @@ module Contentful
236
238
  def replace_links_with_known_resources(res, seen_resource_ids = [])
237
239
  seen_resource_ids << res.id
238
240
 
239
- property_containers = [:properties, :sys, :fields].map do |property_container_name|
241
+ property_containers = %i[properties sys fields].map do |property_container_name|
240
242
  res.public_send(property_container_name)
241
243
  end.compact
242
244
 
@@ -9,6 +9,7 @@ require_relative 'space_role_methods_factory'
9
9
  require_relative 'space_webhook_methods_factory'
10
10
  require_relative 'space_api_key_methods_factory'
11
11
  require_relative 'space_environment_methods_factory'
12
+ require_relative 'space_preview_api_key_methods_factory'
12
13
  require_relative 'space_space_membership_methods_factory'
13
14
 
14
15
  module Contentful
@@ -127,6 +128,15 @@ module Contentful
127
128
  SpaceApiKeyMethodsFactory.new(self)
128
129
  end
129
130
 
131
+ # Allows manipulation of preview api keys in context of the current space
132
+ # Allows listing all api keys of space and finding one by ID.
133
+ # @see _ README for details.
134
+ #
135
+ # @return [Contentful::Management::SpacePreviewApiKeyMethodsFactory]
136
+ def preview_api_keys
137
+ SpacePreviewApiKeyMethodsFactory.new(self)
138
+ end
139
+
130
140
  # Allows manipulation of space memberships in context of the current space
131
141
  # Allows listing all space memberships of space, creating new and finding one by ID.
132
142
  # @see _ README for details.
@@ -0,0 +1,19 @@
1
+ require_relative 'space_association_methods_factory'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Wrapper for PreviewApiKey API for usage from within Space
6
+ # @private
7
+ class SpacePreviewApiKeyMethodsFactory
8
+ include Contentful::Management::SpaceAssociationMethodsFactory
9
+
10
+ def new
11
+ fail 'Not supported'
12
+ end
13
+
14
+ def create
15
+ fail 'Not supported'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -32,6 +32,24 @@ module Contentful
32
32
 
33
33
  parameters
34
34
  end
35
+
36
+ # Returns the path for a specified resource name.
37
+ def base_path_for(resource_name)
38
+ {
39
+ 'Role' => 'roles',
40
+ 'Space' => 'spaces',
41
+ 'Asset' => 'assets',
42
+ 'Entry' => 'entries',
43
+ 'Locale' => 'locales',
44
+ 'Upload' => 'uploads',
45
+ 'ApiKey' => 'api_keys',
46
+ 'UIExtension' => 'extensions',
47
+ 'Environment' => 'environments',
48
+ 'ContentType' => 'content_types',
49
+ 'PreviewApiKey' => 'preview_api_keys',
50
+ 'SpaceMembership' => 'space_memberships'
51
+ }[resource_name]
52
+ end
35
53
  end
36
54
  end
37
55
  end
@@ -3,6 +3,6 @@ module Contentful
3
3
  # Management Namespace
4
4
  module Management
5
5
  # Gem Version
6
- VERSION = '2.0.2'.freeze
6
+ VERSION = '2.1.0'.freeze
7
7
  end
8
8
  end
@@ -24,7 +24,7 @@ module Contentful
24
24
 
25
25
  # @private
26
26
  def self.create_attributes(_client, attributes)
27
- attributes.select { |key, _value| [:httpBasicUsername, :httpBasicPassword, :url, :name, :headers, :topics].include? key }
27
+ attributes.select { |key, _value| %i[httpBasicUsername httpBasicPassword url name headers topics].include? key }
28
28
  end
29
29
 
30
30
  # Creates a webhook.
@@ -0,0 +1,158 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.contentful.com/spaces/facgnwwgj5fe/api_keys
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"name":"test with env","description":null,"environments":[{"sys":{"type":"Link","linkType":"Environment","id":"master"}},{"sys":{"type":"Link","linkType":"Environment","id":"testing"}}]}'
9
+ headers:
10
+ X-Contentful-User-Agent:
11
+ - sdk contentful-management.rb/2.0.2; platform ruby/2.5.1; os macOS/16;
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: 201
25
+ message: Created
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
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
+ Date:
48
+ - Tue, 15 May 2018 11:08:53 GMT
49
+ Etag:
50
+ - W/"63c2d753533d795321f09e08ecca0c17"
51
+ Location:
52
+ - https://api.contentful.com/spaces/facgnwwgj5fe/api_keys/29BbI2yvRgqGrKqA0Jfs2C
53
+ Server:
54
+ - Contentful
55
+ Strict-Transport-Security:
56
+ - max-age=15768000
57
+ X-Content-Type-Options:
58
+ - nosniff
59
+ X-Contentful-Ratelimit-Hour-Limit:
60
+ - '36000'
61
+ X-Contentful-Ratelimit-Hour-Remaining:
62
+ - '35999'
63
+ X-Contentful-Ratelimit-Reset:
64
+ - '0'
65
+ X-Contentful-Ratelimit-Second-Limit:
66
+ - '10'
67
+ X-Contentful-Ratelimit-Second-Remaining:
68
+ - '9'
69
+ X-Contentful-Request-Id:
70
+ - ae22d7e31e07ae03cfa004a4aab0218c
71
+ X-Frame-Options:
72
+ - ALLOWALL
73
+ X-Xss-Protection:
74
+ - 1; mode=block
75
+ Content-Length:
76
+ - '1161'
77
+ Connection:
78
+ - Close
79
+ Set-Cookie:
80
+ - incap_ses_467_673446=JGyMEWxMIx1qE/oViR97BsS/+loAAAAAOLofxJ7nizcrbzabZLY1tA==;
81
+ path=/; Domain=.contentful.com
82
+ - nlbi_673446=CUHfeN0h7Rb9Sfr56lKYhQAAAADFhdA19R6fEVqqErPX2ZrC; path=/; Domain=.contentful.com
83
+ - visid_incap_673446=YaUkVgKbSwminuB6lMpCQ8S/+loAAAAAQUIPAAAAAAAZXdhM77WCeecx0WlfwwE9;
84
+ expires=Wed, 15 May 2019 07:47:46 GMT; path=/; Domain=.contentful.com
85
+ X-Iinfo:
86
+ - 3-701776-701780 NNNN CT(112 112 0) RT(1526382531872 61) q(0 0 2 -1) r(6 6)
87
+ U5
88
+ X-Cdn:
89
+ - Incapsula
90
+ body:
91
+ encoding: ASCII-8BIT
92
+ string: |+
93
+ {
94
+ "name":"test with env",
95
+ "description":null,
96
+ "accessToken":"348518f9a8a4bde30eb9672d45de5e612010ee5271b05255ea986ab961661762",
97
+ "policies":[
98
+ {
99
+ "effect":"allow",
100
+ "actions":"all"
101
+ }
102
+ ],
103
+ "sys":{
104
+ "type":"ApiKey",
105
+ "id":"29BbI2yvRgqGrKqA0Jfs2C",
106
+ "version":0,
107
+ "space":{
108
+ "sys":{
109
+ "type":"Link",
110
+ "linkType":"Space",
111
+ "id":"facgnwwgj5fe"
112
+ }
113
+ },
114
+ "createdBy":{
115
+ "sys":{
116
+ "type":"Link",
117
+ "linkType":"User",
118
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
119
+ }
120
+ },
121
+ "createdAt":"2018-05-15T11:08:53Z",
122
+ "updatedBy":{
123
+ "sys":{
124
+ "type":"Link",
125
+ "linkType":"User",
126
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
127
+ }
128
+ },
129
+ "updatedAt":"2018-05-15T11:08:53Z"
130
+ },
131
+ "environments":[
132
+ {
133
+ "sys":{
134
+ "id":"master",
135
+ "type":"Link",
136
+ "linkType":"Environment"
137
+ }
138
+ },
139
+ {
140
+ "sys":{
141
+ "id":"testing",
142
+ "type":"Link",
143
+ "linkType":"Environment"
144
+ }
145
+ }
146
+ ],
147
+ "preview_api_key":{
148
+ "sys":{
149
+ "type":"Link",
150
+ "linkType":"PreviewApiKey",
151
+ "id":"29BPiYGUSf61b93lTZWbKW"
152
+ }
153
+ }
154
+ }
155
+
156
+ http_version:
157
+ recorded_at: Tue, 15 May 2018 11:08:52 GMT
158
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,288 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.contentful.com/spaces/facgnwwgj5fe/api_keys/5mxNhKOZYOp1wzafOR9qPw
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Contentful-User-Agent:
11
+ - sdk contentful-management.rb/2.0.2; platform ruby/2.5.1; os macOS/16;
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
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
+ Date:
48
+ - Tue, 15 May 2018 11:12:44 GMT
49
+ Etag:
50
+ - W/"87e77bf3868775cda5b9da89a4b1e149"
51
+ Server:
52
+ - Contentful
53
+ Strict-Transport-Security:
54
+ - max-age=15768000
55
+ X-Content-Type-Options:
56
+ - nosniff
57
+ X-Contentful-Ratelimit-Hour-Limit:
58
+ - '36000'
59
+ X-Contentful-Ratelimit-Hour-Remaining:
60
+ - '35998'
61
+ X-Contentful-Ratelimit-Reset:
62
+ - '0'
63
+ X-Contentful-Ratelimit-Second-Limit:
64
+ - '10'
65
+ X-Contentful-Ratelimit-Second-Remaining:
66
+ - '9'
67
+ X-Contentful-Request-Id:
68
+ - 74b648b6f15e0e6bf835ff37bb820f9e
69
+ X-Frame-Options:
70
+ - ALLOWALL
71
+ X-Xss-Protection:
72
+ - 1; mode=block
73
+ Content-Length:
74
+ - '1060'
75
+ Connection:
76
+ - Close
77
+ Set-Cookie:
78
+ - incap_ses_467_673446=MtX5Bt6UCyf0t/oViR97BqvA+loAAAAAkjW5p6TsMPDtAZEbBxaI2g==;
79
+ path=/; Domain=.contentful.com
80
+ - nlbi_673446=ZwczeLNCryAOn4a26lKYhQAAAAD+xpwdhVPFZtQ1zX1nvNad; path=/; Domain=.contentful.com
81
+ - visid_incap_673446=QBHgG/q9Tq+ZKgk8cx0PV6vA+loAAAAAQUIPAAAAAABBnXt2Bz4P1TuDIMoO+hDg;
82
+ expires=Wed, 15 May 2019 07:47:40 GMT; path=/; Domain=.contentful.com
83
+ X-Iinfo:
84
+ - 10-1716806-1716814 NNNN CT(102 102 0) RT(1526382763486 58) q(0 0 2 -1) r(4
85
+ 4) U5
86
+ X-Cdn:
87
+ - Incapsula
88
+ body:
89
+ encoding: ASCII-8BIT
90
+ string: |+
91
+ {
92
+ "name":"management.py - playground 1",
93
+ "description":"",
94
+ "accessToken":"ba52beb5d428ca879aff9073cff7791f2c2ab9ff04a60911fec1ec3c80bcac6c",
95
+ "policies":[
96
+ {
97
+ "effect":"allow",
98
+ "actions":"all"
99
+ }
100
+ ],
101
+ "sys":{
102
+ "type":"ApiKey",
103
+ "id":"5mxNhKOZYOp1wzafOR9qPw",
104
+ "version":1,
105
+ "space":{
106
+ "sys":{
107
+ "type":"Link",
108
+ "linkType":"Space",
109
+ "id":"facgnwwgj5fe"
110
+ }
111
+ },
112
+ "createdBy":{
113
+ "sys":{
114
+ "type":"Link",
115
+ "linkType":"User",
116
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
117
+ }
118
+ },
119
+ "createdAt":"2018-02-27T10:19:59Z",
120
+ "updatedBy":{
121
+ "sys":{
122
+ "type":"Link",
123
+ "linkType":"User",
124
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
125
+ }
126
+ },
127
+ "updatedAt":"2018-02-27T10:20:13Z"
128
+ },
129
+ "environments":[
130
+ {
131
+ "sys":{
132
+ "id":"testing",
133
+ "type":"Link",
134
+ "linkType":"Environment"
135
+ }
136
+ }
137
+ ],
138
+ "preview_api_key":{
139
+ "sys":{
140
+ "type":"Link",
141
+ "linkType":"PreviewApiKey",
142
+ "id":"5mytqWZjcqEWMIHVfe5cUi"
143
+ }
144
+ }
145
+ }
146
+
147
+ http_version:
148
+ recorded_at: Tue, 15 May 2018 11:12:44 GMT
149
+ - request:
150
+ method: get
151
+ uri: https://api.contentful.com/spaces/facgnwwgj5fe/preview_api_keys/5mytqWZjcqEWMIHVfe5cUi
152
+ body:
153
+ encoding: US-ASCII
154
+ string: ''
155
+ headers:
156
+ X-Contentful-User-Agent:
157
+ - sdk contentful-management.rb/2.0.2; platform ruby/2.5.1; os macOS/16;
158
+ Authorization:
159
+ - Bearer <ACCESS_TOKEN>
160
+ Content-Type:
161
+ - application/vnd.contentful.management.v1+json
162
+ Connection:
163
+ - close
164
+ Host:
165
+ - api.contentful.com
166
+ User-Agent:
167
+ - http.rb/2.2.2
168
+ response:
169
+ status:
170
+ code: 200
171
+ message: OK
172
+ headers:
173
+ Accept-Ranges:
174
+ - bytes
175
+ Access-Control-Allow-Headers:
176
+ - 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
177
+ Access-Control-Allow-Methods:
178
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
179
+ Access-Control-Allow-Origin:
180
+ - "*"
181
+ Access-Control-Expose-Headers:
182
+ - Etag
183
+ Access-Control-Max-Age:
184
+ - '1728000'
185
+ Cache-Control:
186
+ - max-age=0
187
+ Cf-Organization-Id:
188
+ - 4SsuxQCaMaemfIms52Jr8s
189
+ Cf-Space-Id:
190
+ - facgnwwgj5fe
191
+ Content-Type:
192
+ - application/vnd.contentful.management.v1+json
193
+ Date:
194
+ - Tue, 15 May 2018 11:12:45 GMT
195
+ Etag:
196
+ - W/"f8047a35183c5d1c13a2ed8ddbc390e0"
197
+ Server:
198
+ - Contentful
199
+ Strict-Transport-Security:
200
+ - max-age=15768000
201
+ X-Content-Type-Options:
202
+ - nosniff
203
+ X-Contentful-Ratelimit-Hour-Limit:
204
+ - '36000'
205
+ X-Contentful-Ratelimit-Hour-Remaining:
206
+ - '35997'
207
+ X-Contentful-Ratelimit-Reset:
208
+ - '0'
209
+ X-Contentful-Ratelimit-Second-Limit:
210
+ - '10'
211
+ X-Contentful-Ratelimit-Second-Remaining:
212
+ - '9'
213
+ X-Contentful-Request-Id:
214
+ - bd4b4ff9e62b3e208be9c798abae6795
215
+ X-Frame-Options:
216
+ - ALLOWALL
217
+ X-Xss-Protection:
218
+ - 1; mode=block
219
+ Content-Length:
220
+ - '932'
221
+ Connection:
222
+ - Close
223
+ Set-Cookie:
224
+ - incap_ses_467_673446=BPmedbScch9YuPoViR97BqzA+loAAAAAGCZbde/HHV9sM7ITMFmtqg==;
225
+ path=/; Domain=.contentful.com
226
+ - nlbi_673446=2DvcEriRfBTT9tsU6lKYhQAAAACE/17pda5G1ADz6Ja6KckH; path=/; Domain=.contentful.com
227
+ - visid_incap_673446=+4KFWFQ2QtmTh3Pfvu/nbazA+loAAAAAQUIPAAAAAADbpxpRhQbqdwZ3n4vPzqh9;
228
+ expires=Wed, 15 May 2019 07:47:46 GMT; path=/; Domain=.contentful.com
229
+ X-Iinfo:
230
+ - 8-376124-376127 NNNN CT(99 100 0) RT(1526382764088 90) q(0 0 2 -1) r(4 4)
231
+ U5
232
+ X-Cdn:
233
+ - Incapsula
234
+ body:
235
+ encoding: ASCII-8BIT
236
+ string: |+
237
+ {
238
+ "name":"management.py - playground 1",
239
+ "description":null,
240
+ "accessToken":"PREVIEW_TOKEN",
241
+ "policies":[
242
+ {
243
+ "effect":"allow",
244
+ "actions":"all"
245
+ }
246
+ ],
247
+ "sys":{
248
+ "type":"PreviewApiKey",
249
+ "id":"5mytqWZjcqEWMIHVfe5cUi",
250
+ "version":0,
251
+ "space":{
252
+ "sys":{
253
+ "type":"Link",
254
+ "linkType":"Space",
255
+ "id":"facgnwwgj5fe"
256
+ }
257
+ },
258
+ "createdBy":{
259
+ "sys":{
260
+ "type":"Link",
261
+ "linkType":"User",
262
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
263
+ }
264
+ },
265
+ "createdAt":"2018-02-27T10:19:59Z",
266
+ "updatedBy":{
267
+ "sys":{
268
+ "type":"Link",
269
+ "linkType":"User",
270
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
271
+ }
272
+ },
273
+ "updatedAt":"2018-02-27T10:19:59Z"
274
+ },
275
+ "environments":[
276
+ {
277
+ "sys":{
278
+ "id":"master",
279
+ "type":"Link",
280
+ "linkType":"Environment"
281
+ }
282
+ }
283
+ ]
284
+ }
285
+
286
+ http_version:
287
+ recorded_at: Tue, 15 May 2018 11:12:44 GMT
288
+ recorded_with: VCR 4.0.0
@@ -5,7 +5,7 @@ require 'contentful/management/client'
5
5
  module Contentful
6
6
  module Management
7
7
  describe ApiKey do
8
- let(:token) { '<ACCESS_TOKEN>' }
8
+ let(:token) { ENV.fetch('CF_TEST_CMA_TOKEN', '<ACCESS_TOKEN>') }
9
9
  let(:space_id) { 'bjwq7b86vgmm' }
10
10
  let(:api_key_id) { '6vbW35TjBTc8FyRTAuXZZe' }
11
11
 
@@ -55,6 +55,53 @@ module Contentful
55
55
  end
56
56
  end
57
57
  end
58
+
59
+ describe 'environments' do
60
+ let(:space_id) { 'facgnwwgj5fe' }
61
+ subject { client.api_keys(space_id) }
62
+
63
+ it 'can create an api key with environments' do
64
+ vcr('api_key/create_with_environments') {
65
+ api_key = subject.create(name: 'test with env', environments: [
66
+ {
67
+ sys: {
68
+ type: 'Link',
69
+ linkType: 'Environment',
70
+ id: 'master'
71
+ }
72
+ },
73
+ {
74
+ sys: {
75
+ type: 'Link',
76
+ linkType: 'Environment',
77
+ id: 'testing'
78
+ }
79
+ }
80
+ ])
81
+ expect(api_key.environments.size).to eq 2
82
+ expect(api_key.environments.first.id).to eq 'master'
83
+ expect(api_key.environments.last.id).to eq 'testing'
84
+ }
85
+ end
86
+ end
87
+
88
+ describe 'preview api tokens' do
89
+ let(:space_id) { 'facgnwwgj5fe' }
90
+ let(:api_key_id) { '5mxNhKOZYOp1wzafOR9qPw' }
91
+ subject { client.api_keys(space_id) }
92
+
93
+ it 'can fetch preview api keys' do
94
+ vcr('api_key/preview') {
95
+ api_key = subject.find(api_key_id)
96
+
97
+ expect(api_key.properties[:preview_api_key]).to be_a Contentful::Management::Link
98
+
99
+ preview_api_key = api_key.preview_api_key
100
+ expect(preview_api_key).to be_a Contentful::Management::PreviewApiKey
101
+ expect(preview_api_key.access_token).to eq 'PREVIEW_TOKEN'
102
+ }
103
+ end
104
+ end
58
105
  end
59
106
  end
60
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful-management
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Protas
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-04-18 00:00:00.000000000 Z
13
+ date: 2018-05-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http
@@ -192,14 +192,14 @@ dependencies:
192
192
  requirements:
193
193
  - - "~>"
194
194
  - !ruby/object:Gem::Version
195
- version: 0.41.0
195
+ version: 0.49.1
196
196
  type: :development
197
197
  prerelease: false
198
198
  version_requirements: !ruby/object:Gem::Requirement
199
199
  requirements:
200
200
  - - "~>"
201
201
  - !ruby/object:Gem::Version
202
- version: 0.41.0
202
+ version: 0.49.1
203
203
  - !ruby/object:Gem::Dependency
204
204
  name: listen
205
205
  requirement: !ruby/object:Gem::Requirement
@@ -307,6 +307,7 @@ files:
307
307
  - lib/contentful/management/client_locale_methods_factory.rb
308
308
  - lib/contentful/management/client_organization_methods_factory.rb
309
309
  - lib/contentful/management/client_personal_access_tokens_methods_factory.rb
310
+ - lib/contentful/management/client_preview_api_key_methods_factory.rb
310
311
  - lib/contentful/management/client_role_methods_factory.rb
311
312
  - lib/contentful/management/client_snapshot_methods_factory.rb
312
313
  - lib/contentful/management/client_space_membership_methods_factory.rb
@@ -342,6 +343,7 @@ files:
342
343
  - lib/contentful/management/location.rb
343
344
  - lib/contentful/management/organization.rb
344
345
  - lib/contentful/management/personal_access_token.rb
346
+ - lib/contentful/management/preview_api_key.rb
345
347
  - lib/contentful/management/request.rb
346
348
  - lib/contentful/management/resource.rb
347
349
  - lib/contentful/management/resource/all_published.rb
@@ -365,6 +367,7 @@ files:
365
367
  - lib/contentful/management/space_association_methods_factory.rb
366
368
  - lib/contentful/management/space_environment_methods_factory.rb
367
369
  - lib/contentful/management/space_membership.rb
370
+ - lib/contentful/management/space_preview_api_key_methods_factory.rb
368
371
  - lib/contentful/management/space_role_methods_factory.rb
369
372
  - lib/contentful/management/space_space_membership_methods_factory.rb
370
373
  - lib/contentful/management/space_webhook_methods_factory.rb
@@ -407,8 +410,10 @@ files:
407
410
  - spec/fixtures/pixel.jpg
408
411
  - spec/fixtures/vcr_cassettes/api_key/all_for_space.yml
409
412
  - spec/fixtures/vcr_cassettes/api_key/create_for_space.yml
413
+ - spec/fixtures/vcr_cassettes/api_key/create_with_environments.yml
410
414
  - spec/fixtures/vcr_cassettes/api_key/find.yml
411
415
  - spec/fixtures/vcr_cassettes/api_key/find_for_space_not_found.yml
416
+ - spec/fixtures/vcr_cassettes/api_key/preview.yml
412
417
  - spec/fixtures/vcr_cassettes/array_page_1.yml
413
418
  - spec/fixtures/vcr_cassettes/asset/143_assets_next_page.yml
414
419
  - spec/fixtures/vcr_cassettes/asset/all.yml
@@ -784,8 +789,10 @@ test_files:
784
789
  - spec/fixtures/pixel.jpg
785
790
  - spec/fixtures/vcr_cassettes/api_key/all_for_space.yml
786
791
  - spec/fixtures/vcr_cassettes/api_key/create_for_space.yml
792
+ - spec/fixtures/vcr_cassettes/api_key/create_with_environments.yml
787
793
  - spec/fixtures/vcr_cassettes/api_key/find.yml
788
794
  - spec/fixtures/vcr_cassettes/api_key/find_for_space_not_found.yml
795
+ - spec/fixtures/vcr_cassettes/api_key/preview.yml
789
796
  - spec/fixtures/vcr_cassettes/array_page_1.yml
790
797
  - spec/fixtures/vcr_cassettes/asset/143_assets_next_page.yml
791
798
  - spec/fixtures/vcr_cassettes/asset/all.yml