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.



10
11
12
# File 'lib/ecoportal/api/common/content/client.rb', line 10

def initialize(api_key:, version: "v2", host: "live.ecoportal.com", logger: nil)
  super(api_key: api_key, version: "v2", host: host, logger: logger)
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.



32
33
34
# File 'lib/ecoportal/api/common/content/client.rb', line 32

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

#delete(path) ⇒ Object



14
15
16
# File 'lib/ecoportal/api/common/content/client.rb', line 14

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


21
22
23
24
25
26
27
# File 'lib/ecoportal/api/common/content/client.rb', line 21

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