Class: WCC::Contentful::SimpleClient::Management
Constant Summary
ADAPTERS
Instance Attribute Summary
#api_url, #environment, #space
#_instrumentation
Instance Method Summary
collapse
-
#client_type ⇒ Object
-
#content_type(key, query = {}) ⇒ Object
-
#content_types(**query) ⇒ Object
-
#editor_interface(content_type_id, query = {}) ⇒ Object
-
#initialize(space:, management_token:, **options) ⇒ Management
constructor
A new instance of Management.
-
#locale(key, query = {}) ⇒ Object
-
#locales(**query) ⇒ Object
-
#post(path, body) ⇒ Object
-
#post_webhook_definition(webhook) ⇒ Object
{ “name”: “My webhook”, “url”: “www.example.com/test”, “topics”: [ “Entry.create”, “ContentType.create”, “*.publish”, “Asset.*” ], “httpBasicUsername”: “yolo”, “httpBasicPassword”: “yolo”, “headers”: [ { “key”: “header1”, “value”: “value1” }, { “key”: “header2”, “value”: “value2” } ] }.
-
#put(path, body) ⇒ Object
-
#tag(key, query = {}) ⇒ Object
-
#tag_create(tag_definition) ⇒ Object
-
#tags(query = {}) ⇒ Object
-
#webhook_definitions(**query) ⇒ Object
#get, load_adapter
#_instrumentation_event_prefix, instrument
Constructor Details
#initialize(space:, management_token:, **options) ⇒ Management
Returns a new instance of Management.
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 5
def initialize(space:, management_token:, **options)
super(
**options,
api_url: options[:management_api_url] || 'https://api.contentful.com',
space: space,
access_token: management_token,
)
@post_adapter = @adapter if @adapter.respond_to?(:post)
@post_adapter ||= self.class.load_adapter(nil)
end
|
Instance Method Details
#client_type ⇒ Object
17
18
19
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 17
def client_type
'management'
end
|
#content_type(key, query = {}) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 29
def content_type(key, query = {})
resp =
_instrument 'content_types', content_type: key, query: query do
get("content_types/#{key}", query)
end
resp.assert_ok!
end
|
#content_types(**query) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 21
def content_types(**query)
resp =
_instrument 'content_types', query: query do
get('content_types', query)
end
resp.assert_ok!
end
|
#editor_interface(content_type_id, query = {}) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 53
def editor_interface(content_type_id, query = {})
resp =
_instrument 'editor_interfaces', content_type: content_type_id, query: query do
get("content_types/#{content_type_id}/editor_interface", query)
end
resp.assert_ok!
end
|
#locale(key, query = {}) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 45
def locale(key, query = {})
resp =
_instrument 'locales', content_type: key, query: query do
get("locales/#{key}", query)
end
resp.assert_ok!
end
|
#locales(**query) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 37
def locales(**query)
resp =
_instrument 'locales', query: query do
get('locales', query)
end
resp.assert_ok!
end
|
#post(path, body) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 127
def post(path, body)
url = URI.join(@api_url, path)
resp =
_instrument 'post_http', url: url do
post_http(url, body)
end
Response.new(self,
{ url: url, body: body },
resp)
end
|
#post_webhook_definition(webhook) ⇒ Object
{
"name": "My webhook",
"url": "https://www.example.com/test",
"topics": [
"Entry.create",
"ContentType.create",
"*.publish",
"Asset.*"
],
"httpBasicUsername": "yolo",
"httpBasicPassword": "yolo",
"headers": [
{
"key": "header1",
"value": "value1"
},
{
"key": "header2",
"value": "value2"
}
]
}
119
120
121
122
123
124
125
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 119
def post_webhook_definition(webhook)
resp =
_instrument 'post.webhook_definitions' do
post("/spaces/#{space}/webhook_definitions", webhook)
end
resp.assert_ok!
end
|
#put(path, body) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 140
def put(path, body)
url = URI.join(@api_url, path)
resp =
_instrument 'put_http', url: url do
post_http(url, body, {}, :put)
end
Response.new(self,
{ url: url, body: body },
resp)
end
|
#tag(key, query = {}) ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 77
def tag(key, query = {})
resp =
_instrument 'tags', tag: key, query: query do
get("/spaces/#{space}/environments/#{environment}/tags/#{key}", query)
end
resp.assert_ok!
end
|
#tag_create(tag_definition) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 85
def tag_create(tag_definition)
unless tag_id = tag_definition.dig('sys', 'id')
raise ArgumentError, "Missing tag ID in #{tag_definition}"
end
resp =
_instrument 'tag_create' do
put("/spaces/#{space}/environments/#{environment}/tags/#{tag_id}", tag_definition)
end
resp.assert_ok!
end
|
69
70
71
72
73
74
75
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 69
def tags(query = {})
resp =
_instrument 'tags', query: query do
get("/spaces/#{space}/environments/#{environment}/tags", query)
end
resp.assert_ok!
end
|
#webhook_definitions(**query) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/wcc/contentful/simple_client/management.rb', line 61
def webhook_definitions(**query)
resp =
_instrument 'webhook_definitions', query: query do
get("/spaces/#{space}/webhook_definitions", query)
end
resp.assert_ok!
end
|