Class: Ecoportal::API::Common::Content::Client
- Inherits:
-
Ecoportal::API::Common::Client
- Object
- Ecoportal::API::Common::Client
- Ecoportal::API::Common::Content::Client
- Defined in:
- lib/ecoportal/api/common/content/client.rb
Overview
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#base_request ⇒ HTTP
Creates a HTTP object adding the
X-ECOPORTAL-API-KEY
param to the header. - #delete(path) ⇒ Object
-
#initialize(api_key:, version: "v2", host: "live.ecoportal.com", logger: nil) ⇒ Client
constructor
A new instance of Client.
- #post(path, data:, params: {}) ⇒ Object
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
#logger ⇒ Object
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_request ⇒ HTTP
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.
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
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 |