Class: Camunda::BaseAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/camunda/base_api.rb

Direct Known Subclasses

Console::API, Operate::API, Tasklist::API

Class Method Summary collapse

Class Method Details

.build_url(endpoint, params = {}) ⇒ Object



41
42
43
44
45
46
# File 'lib/camunda/base_api.rb', line 41

def self.build_url(endpoint, params = {})
  url = "#{base_url}/#{Camunda.api_version}/#{endpoint}"
  url += "?#{URI.encode_www_form(params)}" unless params.empty?

  url
end

.get(endpoint, params = {}) ⇒ Object



10
11
12
13
14
15
# File 'lib/camunda/base_api.rb', line 10

def self.get(endpoint, params = {})
  url = build_url(endpoint, params)
  response = RestClient.get(url, headers)

  JSON.parse(response.body)
end

.headersObject



48
49
50
51
52
53
54
# File 'lib/camunda/base_api.rb', line 48

def self.headers
  {
    Authorization: "Bearer #{oauth_token}",
    Accept: 'application/json',
    'Content-Type': 'application/json'
  }
end

.patch(endpoint, params = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/camunda/base_api.rb', line 29

def self.patch(endpoint, params = {})
  url = build_url(endpoint)

  response = RestClient.patch(
    url,
    params.to_json,
    headers
  )

  JSON.parse(response.body)
end

.post(endpoint, params = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/camunda/base_api.rb', line 17

def self.post(endpoint, params = {})
  url = build_url(endpoint)

  response = RestClient.post(
    url,
    params.to_json,
    headers
  )

  JSON.parse(response.body) if response.code == 200
end