Class: FatZebra::APIResource
- Inherits:
-
FatZebraObject
- Object
- FatZebraObject
- FatZebra::APIResource
- Includes:
- APIHelper
- Defined in:
- lib/fat_zebra/api_resource.rb
Overview
FatZebra API Resource
Define the API requests methods
Direct Known Subclasses
BankAccount, Batch, Card, Customer, DirectCredit, DirectDebit, Information, PaymentPlan, Purchase, Refund, WebHook
Instance Attribute Summary
Attributes inherited from FatZebraObject
Attributes included from ObjectHelper
Class Method Summary collapse
- .base_path(account) ⇒ Object
-
.request(method, path, payload = {}, options = {}) ⇒ Hash
Send a request to the API.
Methods included from APIHelper
included, #request, #resource_name, #resource_path
Methods inherited from FatZebraObject
initialize_from, #load_response_api, #update_from
Methods included from Validation
#errors, #valid!, #valid?, #validates
Methods included from ObjectHelper
#[], #[]=, #add_accessor, #add_accessors, #add_data, #initialize, #inspect, #keys, #method_missing, #remove_accessor, #to_hash, #to_json, #update_attributes
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class FatZebra::ObjectHelper
Class Method Details
.base_path(account) ⇒ Object
11 12 13 |
# File 'lib/fat_zebra/api_resource.rb', line 11 def base_path(account) "#{account.api_version}/" end |
.request(method, path, payload = {}, options = {}) ⇒ Hash
Send a request to the API
rubocop:disable Metrics/AbcSize
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fat_zebra/api_resource.rb', line 26 def request(method, path, payload = {}, = {}) account = get_account full_path = "/#{base_path account}#{path}" payload[:test] = true if account.test_mode payload = Util.format_dates_in_hash(payload) url_params = URI.encode_www_form(payload) if method == :get uri = build_endpoint_url(account.gateway, full_path, url_params, http_secure: account.http_secure) = Util.compact( method: method, url: uri.to_s, payload: payload, proxy: account.proxy, use_ssl: account.http_secure ).merge(authentication(account)).merge(default_headers).merge(account.).merge() Request.execute().body rescue FatZebra::RequestError => error return error.http_body if error.http_status == 422 raise end |