Class: MandarinApi::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/mandarin_api/wrapper.rb

Overview

Wraps request sending

Instance Method Summary collapse

Constructor Details

#initialize(merchant_id:, secret:, logger: nil) ⇒ Wrapper

Returns a new instance of Wrapper.



10
11
12
13
14
# File 'lib/mandarin_api/wrapper.rb', line 10

def initialize(merchant_id:, secret:, logger: nil)
  @merchant_id = merchant_id
  @secret = secret
  @logger = logger
end

Instance Method Details

#request(endpoint, params = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/mandarin_api/wrapper.rb', line 16

def request(endpoint, params = {})
  url = URI.join(MandarinApi.config.request_url, endpoint).to_s
  perform_loging url, params, header
  curl = Curl::Easy.new(url)
  curl.headers = header
   curl.post(json(params))
  body = JSON.parse(curl.body_str)
  return body if curl.response_code == 200
  { 'status' => curl.response_code, 'error' => body }
end