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-KEYparam 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.
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
#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.
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
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 |