Module: BillsPayment
- Defined in:
- lib/bills-payment.rb,
lib/bills-payment/worker.rb,
lib/bills-payment/actions/post.rb,
lib/bills-payment/bills_payment_object.rb,
lib/bills-payment/errors/connection_error.rb,
lib/bills-payment/errors/bills_payment_error.rb,
lib/bills-payment/errors/authentication_error.rb,
lib/bills-payment/errors/invalid_request_error.rb
Defined Under Namespace
Modules: Actions Classes: AuthenticationError, BillsPaymentError, BillsPaymentObject, ConnectionError, InvalidRequestError, Worker
Class Method Summary collapse
-
.request(api_url, method, params = {}) ⇒ Object
BillsPaymentError :api_key, :base_url.
Class Method Details
.request(api_url, method, params = {}) ⇒ Object
BillsPaymentError :api_key, :base_url
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bills-payment.rb', line 25 def request(api_url, method, params = {}) # raise(AuthenticationError, 'Set your API Key using BillsPayment.api_key = <API_KEY>') unless api_key begin url = URI.join(@base_url, api_url).to_s # response = RestClient::Request.execute(method: method, url: url, payload: params.to_json)#, headers: request_headers) RestClient.post url, params.to_json JSON.parse(response) unless response.empty? rescue RestClient::ExceptionWithResponse => e if (response_code = e.http_code) && (response_body = e.http_body) handle_api_error(response_code, JSON.parse(response_body)) else handle_restclient_error(e) end rescue RestClient::Exception, Errno::ECONNREFUSED => e handle_restclient_error(e) end end |