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

Attributes included from Instrumentation

#_instrumentation

Instance Method Summary collapse

Methods inherited from WCC::Contentful::SimpleClient

#get, load_adapter

Methods included from Instrumentation

#_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_typeObject



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



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/wcc/contentful/simple_client/management.rb', line 99

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"
  }
]

}



91
92
93
94
95
96
97
# File 'lib/wcc/contentful/simple_client/management.rb', line 91

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) ⇒ 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