Class: WCC::Contentful::SimpleClient::Management

Inherits:
WCC::Contentful::SimpleClient show all
Defined in:
lib/wcc/contentful/simple_client/management.rb

Constant Summary

Constants inherited from WCC::Contentful::SimpleClient

ADAPTERS

Instance Attribute Summary

Attributes inherited from WCC::Contentful::SimpleClient

#api_url, #space

Instance Method Summary collapse

Methods inherited from WCC::Contentful::SimpleClient

#get, load_adapter

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(
    api_url: options[:api_url] || 'https://api.contentful.com',
    space: space,
    access_token: management_token,
    **options
  )

  @post_adapter = @adapter if @adapter.respond_to?(:post)
  @post_adapter ||= self.class.load_adapter(nil)
end

Instance Method Details

#client_typeObject



17
18
19
# File 'lib/wcc/contentful/simple_client/management.rb', line 17

def client_type
  'management'
end

#content_types(**query) ⇒ Object



21
22
23
24
# File 'lib/wcc/contentful/simple_client/management.rb', line 21

def content_types(**query)
  resp = get('content_types', query)
  resp.assert_ok!
end

#post(path, body) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/wcc/contentful/simple_client/management.rb', line 58

def post(path, body)
  url = URI.join(@api_url, path)

  Response.new(self,
    { url: url, body: body },
    post_http(url, body))
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"
  }
]

}



53
54
55
56
# File 'lib/wcc/contentful/simple_client/management.rb', line 53

def post_webhook_definition(webhook)
  resp = post("/spaces/#{space}/webhook_definitions", webhook)
  resp.assert_ok!
end

#webhook_definitions(**query) ⇒ Object



26
27
28
29
# File 'lib/wcc/contentful/simple_client/management.rb', line 26

def webhook_definitions(**query)
  resp = get("/spaces/#{space}/webhook_definitions", query)
  resp.assert_ok!
end