Class: MandarinApi::Wrapper
- Inherits:
-
Object
- Object
- MandarinApi::Wrapper
- Defined in:
- lib/mandarin_api/wrapper.rb
Overview
Wraps request sending
Instance Method Summary collapse
-
#initialize(merchant_id:, secret:) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #request(endpoint, params = {}) ⇒ Object
Constructor Details
#initialize(merchant_id:, secret:) ⇒ Wrapper
Returns a new instance of Wrapper.
7 8 9 10 |
# File 'lib/mandarin_api/wrapper.rb', line 7 def initialize(merchant_id:, secret:) @merchant_id = merchant_id @secret = secret end |
Instance Method Details
#request(endpoint, params = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mandarin_api/wrapper.rb', line 12 def request(endpoint, params = {}) url = URI.join(MandarinApi.config.request_url, endpoint).to_s RestClient.post(url, json(params), header) do |response| case response.code when 200 JSON.parse response.body else { 'status' => response.status, 'error' => 'Invalid request' } end end end |