class WCC::Contentful::SimpleClient::Management
@api Client
Public Class Methods
new(space:, management_token:, **options)
click to toggle source
Calls superclass method
WCC::Contentful::SimpleClient::new
# 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
Public Instance Methods
client_type()
click to toggle source
# File lib/wcc/contentful/simple_client/management.rb, line 17 def client_type 'management' end
content_type(key, query = {})
click to toggle source
# 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)
click to toggle source
# 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 = {})
click to toggle source
# File lib/wcc/contentful/simple_client/management.rb, line 37 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
post(path, body)
click to toggle source
# File lib/wcc/contentful/simple_client/management.rb, line 83 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)
click to toggle source
{
"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" } ]
}
# File lib/wcc/contentful/simple_client/management.rb, line 75 def post_webhook_definition(webhook) resp = _instrument 'post.webhook_definitions' do post("/spaces/#{space}/webhook_definitions", webhook) end resp.assert_ok! end
webhook_definitions(**query)
click to toggle source
# File lib/wcc/contentful/simple_client/management.rb, line 45 def webhook_definitions(**query) resp = _instrument 'webhook_definitions', query: query do get("/spaces/#{space}/webhook_definitions", query) end resp.assert_ok! end
Private Instance Methods
post_http(url, body, headers = {})
click to toggle source
# File lib/wcc/contentful/simple_client/management.rb, line 98 def post_http(url, body, headers = {}) headers = { Authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/vnd.contentful.management.v1+json' }.merge(headers || {}) body = body.to_json unless body.is_a? String resp = @post_adapter.post(url, body, headers) if [301, 302, 307].include?(resp.status) && !@options[:no_follow_redirects] resp = get_http(resp.headers['location'], nil, headers) elsif resp.status == 308 && !@options[:no_follow_redirects] resp = post_http(resp.headers['location'], body, headers) end resp end