Class: FatZebra::APIResource
- Inherits:
-
FatZebraObject
- Object
- FatZebraObject
- FatZebra::APIResource
- 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
#data, #errors, #raw, #successful
Class Method Summary collapse
-
.class_name ⇒ String
The class name.
-
.request(method, path, payload = {}, options = {}) ⇒ Hash
Send a request to the API.
-
.resource_name ⇒ String
Resource name.
-
.resource_path(path = nil) ⇒ String
Resource path.
Instance Method Summary collapse
-
#request(method, resource_path, payload = {}, options = {}) ⇒ Hash
Send a request to the API.
-
#resource_name ⇒ String
Resource name.
-
#resource_path(path = nil) ⇒ String
Resource path.
Methods inherited from FatZebraObject
#[], #[]=, #add_data, #initialize, initialize_from, #keys, #load_response_api, #to_hash, #to_json, #update_attributes, #update_from
Methods included from Validation
#errors, #valid!, #valid?, #validates
Constructor Details
This class inherits a constructor from FatZebra::FatZebraObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class FatZebra::FatZebraObject
Class Method Details
.class_name ⇒ String
50 51 52 |
# File 'lib/fat_zebra/api_resource.rb', line 50 def class_name name.split('::')[-1] end |
.request(method, path, payload = {}, options = {}) ⇒ Hash
Send a request to the API
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fat_zebra/api_resource.rb', line 64 def request(method, path, payload = {}, = {}) payload[:test] = true if configurations.test_mode if method == :get url_params = !payload.empty? && Util.encode_parameters(payload) payload = nil end uri = build_endpoint_url(path, url_params) = Util.compact( method: method, url: uri.to_s, payload: payload, proxy: configurations.proxy, use_ssl: configurations.http_secure ).merge(authentication).merge(headers).merge() request = Request.execute() request.body end |
.resource_name ⇒ String
44 45 46 |
# File 'lib/fat_zebra/api_resource.rb', line 44 def resource_name Util.underscore("#{class_name}s") end |
.resource_path(path = nil) ⇒ String
38 39 40 |
# File 'lib/fat_zebra/api_resource.rb', line 38 def resource_path(path = nil) "/#{configurations.api_version}/#{path || @resource_name || CGI.escape(resource_name)}" end |
Instance Method Details
#request(method, resource_path, payload = {}, options = {}) ⇒ Hash
Send a request to the API
30 31 32 |
# File 'lib/fat_zebra/api_resource.rb', line 30 def request(method, resource_path, payload = {}, = {}) self.class.request(method, resource_path, payload, ) end |
#resource_name ⇒ String
10 11 12 |
# File 'lib/fat_zebra/api_resource.rb', line 10 def resource_name self.class.resource_name end |
#resource_path(path = nil) ⇒ String
16 17 18 |
# File 'lib/fat_zebra/api_resource.rb', line 16 def resource_path(path = nil) self.class.resource_path(path) end |