Class: Judopay::Model
- Inherits:
-
Object
- Object
- Judopay::Model
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/judopay/model.rb
Overview
Base model for Judopay API model objects
Direct Known Subclasses
AndroidPayment, ApplePayment, CardAddress, CardPayment, Collection, EncryptDetails, Judopay::Market::Payment, Judopay::Market::Preauth, Judopay::Market::Transaction, OneUseTokenPayment, Payment, PkPaymentToken, Preauth, Refund, RegisterCard, SaveCard, TokenPayment, Transaction, TransmittedField, Void, WebPayments::Payment, WebPayments::Transaction
Constant Summary collapse
- VALID_PAGING_OPTIONS =
[:sort, :offset, :page_size].freeze
Class Attribute Summary collapse
-
.resource_path ⇒ Object
Returns the value of attribute resource_path.
-
.valid_api_methods ⇒ Object
Returns the value of attribute valid_api_methods.
Class Method Summary collapse
-
.all(options = {}) ⇒ Judopay::Mash
List all records.
-
.check_api_method_is_supported(method) ⇒ Object
Check if the specified API method is supported by the current model.
-
.find(receipt_id) ⇒ Judopay::Mash
Retrieve a specific record.
-
.valid_options(options) ⇒ Object
Take an paging options hash and filter all but the valid keys.
Instance Method Summary collapse
-
#check_api_method_is_supported(method) ⇒ Object
Verify if an API method is supported for the current model.
-
#check_judo_id ⇒ Object
Use judo_id from configuration if it hasn’t been explicitly set.
-
#create ⇒ Judopay::Mash
Create a new record.
-
#resource_path ⇒ String
Retrieve the current API resource path (e.g. /transactions/payments).
-
#valid_api_methods ⇒ Array<Symbol>
Retrieve an array of valid API methods for the current model e.g [:find, :create].
-
#validate ⇒ Judopay::Mash
Validates a request.
Class Attribute Details
.resource_path ⇒ Object
Returns the value of attribute resource_path.
17 18 19 |
# File 'lib/judopay/model.rb', line 17 def resource_path @resource_path end |
.valid_api_methods ⇒ Object
Returns the value of attribute valid_api_methods.
17 18 19 |
# File 'lib/judopay/model.rb', line 17 def valid_api_methods @valid_api_methods end |
Class Method Details
.all(options = {}) ⇒ Judopay::Mash
List all records
23 24 25 26 27 28 29 |
# File 'lib/judopay/model.rb', line 23 def all( = {}) check_api_method_is_supported(__method__) api = Judopay::API.new = self.().camel_case_keys! uri = resource_path + '?' + .to_query_string api.get(uri) end |
.check_api_method_is_supported(method) ⇒ Object
Check if the specified API method is supported by the current model
44 45 46 |
# File 'lib/judopay/model.rb', line 44 def check_api_method_is_supported(method) raise Judopay::ValidationError, 'API method not supported' if valid_api_methods.nil? || !valid_api_methods.include?(method.to_sym) end |
.find(receipt_id) ⇒ Judopay::Mash
Retrieve a specific record
35 36 37 38 39 |
# File 'lib/judopay/model.rb', line 35 def find(receipt_id) check_api_method_is_supported(__method__) api = Judopay::API.new api.get(resource_path + receipt_id.to_i.to_s) end |
.valid_options(options) ⇒ Object
Take an paging options hash and filter all but the valid keys
49 50 51 52 53 54 55 56 |
# File 'lib/judopay/model.rb', line 49 def () = {} .each do |key, value| next unless VALID_PAGING_OPTIONS.include?(key) [key] = value end end |
Instance Method Details
#check_api_method_is_supported(method) ⇒ Object
Verify if an API method is supported for the current model
97 98 99 |
# File 'lib/judopay/model.rb', line 97 def check_api_method_is_supported(method) self.class.check_api_method_is_supported(method) end |
#check_judo_id ⇒ Object
Use judo_id from configuration if it hasn’t been explicitly set
102 103 104 105 |
# File 'lib/judopay/model.rb', line 102 def check_judo_id return unless respond_to?('judo_id') && judo_id.nil? self.judo_id = Judopay.configuration.judo_id end |
#create ⇒ Judopay::Mash
Create a new record
62 63 64 65 66 67 68 |
# File 'lib/judopay/model.rb', line 62 def create check_api_method_is_supported(__method__) check_judo_id check_validation api = Judopay::API.new api.post(resource_path, self) end |
#resource_path ⇒ String
Retrieve the current API resource path (e.g. /transactions/payments)
84 85 86 |
# File 'lib/judopay/model.rb', line 84 def resource_path self.class.resource_path end |
#valid_api_methods ⇒ Array<Symbol>
Retrieve an array of valid API methods for the current model e.g [:find, :create]
92 93 94 |
# File 'lib/judopay/model.rb', line 92 def valid_api_methods self.class.valid_api_methods end |
#validate ⇒ Judopay::Mash
Validates a request
73 74 75 76 77 78 79 |
# File 'lib/judopay/model.rb', line 73 def validate check_api_method_is_supported(__method__) check_judo_id check_validation api = Judopay::API.new api.post(resource_path + '/validate', self) end |