Class: Ecoportal::API::Common::Content::Client

Inherits:
Ecoportal::API::Common::Client
  • Object
show all
Defined in:
lib/ecoportal/api/common/content/client.rb

Overview

See Also:

  • Ecoportal::API::Common::Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, version: 'v2', host: 'live.ecoportal.com', logger: nil) ⇒ Client

Note:

the api_key will be automatically added as parameter X-ECOPORTAL-API-KEY in the header of the http requests.

Returns a new instance of Client.



11
12
13
14
15
16
17
18
# File 'lib/ecoportal/api/common/content/client.rb', line 11

def initialize(
  api_key:,
  version: 'v2',
  host:    'live.ecoportal.com',
  logger:  nil
)
  super
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/ecoportal/api/common/content/client.rb', line 7

def logger
  @logger
end

Instance Method Details

#base_requestHTTP

Note:

It configures HTTP so it only allows body data in json format.

Creates a HTTP object adding the X-ECOPORTAL-API-KEY param to the header.

Returns:

  • (HTTP)

    HTTP object.



38
39
40
41
42
# File 'lib/ecoportal/api/common/content/client.rb', line 38

def base_request
  @base_request ||= HTTP.headers(
    'X-ECOPORTAL-API-KEY' => @api_key
  ).accept(:json)
end

#delete(_path) ⇒ Object



20
21
22
# File 'lib/ecoportal/api/common/content/client.rb', line 20

def delete(_path)
  raise "DELETE operation does not have integration for api #{@version}"
end

#post(path, data:, params: {}) ⇒ Object

Parameters:

  • params (Hash) (defaults to: {})

    the header paramters of the http request (not including the api key).

Options Hash (params:):

  • :template_id (String)

    original template.

See Also:

  • Ecoportal::API::Common::Client#post


27
28
29
30
31
32
33
# File 'lib/ecoportal/api/common/content/client.rb', line 27

def post(path, data:, params: {})
  instrument('POST', path, params) do
    request do |http|
      http.post(url_for(path), json: data, params: params)
    end
  end
end