Class: EasyBroker::ApiClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/easy_broker/api_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil) ⇒ ApiClient

Returns a new instance of ApiClient.



10
11
12
13
14
15
16
17
18
# File 'lib/easy_broker/api_client.rb', line 10

def initialize(logger: nil)
  self.class.base_uri EasyBroker.configuration.api_root_url
  self.class.headers EasyBroker::DEFAULT_HEADERS.merge(
    EasyBroker::AUTHORIZATION_HEADER => EasyBroker.configuration.api_key,
    EasyBroker::COUNTRY_CODE_HEADER => EasyBroker.configuration.country_code,
    EasyBroker::USE_PARTNER_CODE_HEADER => EasyBroker.configuration.use_partner_code&.to_s
  ).compact
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/easy_broker/api_client.rb', line 8

def logger
  @logger
end

Instance Method Details

#delete(path, query: {}) ⇒ Object



32
33
34
# File 'lib/easy_broker/api_client.rb', line 32

def delete(path, query: {})
  send_request(:delete, path, query: query)
end

#get(path, query: {}) ⇒ Object



20
21
22
# File 'lib/easy_broker/api_client.rb', line 20

def get(path, query: {})
  send_request(:get, path, query: query)
end

#post(path, query: {}, body: {}) ⇒ Object



24
25
26
# File 'lib/easy_broker/api_client.rb', line 24

def post(path, query: {}, body: {})
  send_request(:post, path, query: query, body: body.to_json)
end

#put(path, query: {}, body: {}) ⇒ Object



28
29
30
# File 'lib/easy_broker/api_client.rb', line 28

def put(path, query: {}, body: {})
  send_request(:put, path, query: query, body: body.to_json)
end