Class: Besepa::Subscription
- Defined in:
- lib/besepa/subscription.rb
Constant Summary collapse
- FIELDS =
[:id, :last_debit, :next_debit, :status, :metadata, :starts_at, :renew_at, :created_at, :setup_fee, :customer_code, :debits_count]
Constants inherited from Resource
Constants included from Utils::Request
Utils::Request::END_POINT_URL_PREFIX
Instance Attribute Summary collapse
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#debtor_bank_account ⇒ Object
Returns the value of attribute debtor_bank_account.
-
#product ⇒ Object
Returns the value of attribute product.
Attributes inherited from Resource
Class Method Summary collapse
Instance Method Summary collapse
- #api_path(filters = {}) ⇒ Object
- #process_attributes(attrs) ⇒ Object
- #stats ⇒ Object
- #to_hash ⇒ Object
Methods included from ApiCalls::Destroy
Methods included from ApiCalls::Update
Methods included from ApiCalls::Create
Methods included from ApiCalls::Search
Methods included from ApiCalls::List
Methods inherited from Resource
#allowed_nils, #as_json, handle_errors, #initialize, klass_name, #klass_name, #serializable_hash
Methods included from Utils::Request
Methods included from Utils::Connection
Constructor Details
This class inherits a constructor from Besepa::Resource
Instance Attribute Details
#customer ⇒ Object
Returns the value of attribute customer.
16 17 18 |
# File 'lib/besepa/subscription.rb', line 16 def customer @customer end |
#debtor_bank_account ⇒ Object
Returns the value of attribute debtor_bank_account.
16 17 18 |
# File 'lib/besepa/subscription.rb', line 16 def debtor_bank_account @debtor_bank_account end |
#product ⇒ Object
Returns the value of attribute product.
16 17 18 |
# File 'lib/besepa/subscription.rb', line 16 def product @product end |
Class Method Details
.api_path(filters = {}) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/besepa/subscription.rb', line 29 def self.api_path(filters={}) customer_id = filters[:customer_id] if customer_id "#{Customer.api_path}/#{CGI.escape(customer_id)}/subscriptions" else "/subscriptions" end end |
.query_params(filters = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/besepa/subscription.rb', line 38 def self.query_params(filters = {}) filters = filters.dup filters.delete(:customer_id) filters end |
Instance Method Details
#api_path(filters = {}) ⇒ Object
49 50 51 |
# File 'lib/besepa/subscription.rb', line 49 def api_path(filters={}) "#{self.class.api_path(filters)}/#{CGI.escape(id)}" end |
#process_attributes(attrs) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/besepa/subscription.rb', line 53 def process_attributes(attrs) self.class::FIELDS.each do |key| self.send("#{key.to_s}=", attrs[key.to_s] || attrs[key.to_sym]) end self.debtor_bank_account = Besepa::BankAccount.new(attrs['debtor_bank_account']) if attrs['debtor_bank_account'] self.product = Besepa::Product.new(attrs['product']) if attrs['product'] self.customer = Besepa::Customer.new(attrs['customer']) if attrs['customer'] process_activities(attrs) self end |
#stats ⇒ Object
44 45 46 47 |
# File 'lib/besepa/subscription.rb', line 44 def stats response = get "#{api_path}/stats" response['response'] end |
#to_hash ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/besepa/subscription.rb', line 18 def to_hash values = {} self.class::FIELDS.each do |key| values[key] = self.send("#{key.to_s}") end values[:debtor_bank_account] = debtor_bank_account.to_hash if debtor_bank_account values[:product] = product.to_hash if product values[:customer] = customer.to_hash if customer values end |