module Ecoportal module API module Common module Content # @see Ecoportal::API::Common::Client class Client < Ecoportal::API::Common::Client attr_accessor :logger # @note the `api_key` will be automatically added as parameter `X-ECOPORTAL-API-KEY` in the header of the http requests. def initialize(api_key:, version: "v2", host: "live.ecoportal.com", logger: nil) super(api_key: api_key, version: "v2", host: host, logger: logger) end def delete(path) raise "DELETE operation does not have integration for api #{@version}" end # @see Ecoportal::API::Common::Client#post # @param params [Hash] the header paramters of the http request (not including the api key). # @option params [String] :template_id original template. 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 # Creates a HTTP object adding the `X-ECOPORTAL-API-KEY` param to the header. # @note It configures HTTP so it only allows body data in json format. # @return [HTTP] HTTP object. def base_request @base_request ||= HTTP.headers("X-ECOPORTAL-API-KEY" => @api_key).accept(:json) end end end end end end