Class: Besepa::Subscription

Inherits:
Resource show all
Includes:
ApiCalls::Create, ApiCalls::Destroy, ApiCalls::List, ApiCalls::Search
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]

Constants inherited from Resource

Resource::ALLOWED_NILS

Constants included from Utils::Request

Utils::Request::END_POINT_URL_PREFIX

Instance Attribute Summary collapse

Attributes inherited from Resource

#activities

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiCalls::Destroy

#destroy

Methods included from ApiCalls::Create

included

Methods included from ApiCalls::Search

included

Methods included from ApiCalls::List

included

Methods inherited from Resource

#allowed_nils, #as_json, handle_errors, #initialize, klass_name, #klass_name, #serializable_hash

Methods included from Utils::Request

#delete, #get, #post, #put

Methods included from Utils::Connection

#connection

Constructor Details

This class inherits a constructor from Besepa::Resource

Instance Attribute Details

#customerObject

Returns the value of attribute customer.



15
16
17
# File 'lib/besepa/subscription.rb', line 15

def customer
  @customer
end

#debtor_bank_accountObject

Returns the value of attribute debtor_bank_account.



15
16
17
# File 'lib/besepa/subscription.rb', line 15

def 
  @debtor_bank_account
end

#productObject

Returns the value of attribute product.



15
16
17
# File 'lib/besepa/subscription.rb', line 15

def product
  @product
end

Class Method Details

.api_path(filters = {}) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/besepa/subscription.rb', line 28

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



37
38
39
40
41
# File 'lib/besepa/subscription.rb', line 37

def self.query_params(filters = {})
  filters = filters.dup
  filters.delete(:customer_id)
  filters
end

Instance Method Details

#api_path(filters = {}) ⇒ Object



43
44
45
# File 'lib/besepa/subscription.rb', line 43

def api_path(filters={})
  "#{self.class.api_path(filters)}/#{CGI.escape(id)}"
end

#process_attributes(attrs) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/besepa/subscription.rb', line 47

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. = 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

#to_hashObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/besepa/subscription.rb', line 17

def to_hash
  values = {}
  self.class::FIELDS.each do |key|
    values[key] = self.send("#{key.to_s}")
  end
  values[:debtor_bank_account] = .to_hash if 
  values[:product] = product.to_hash if product
  values[:customer] = customer.to_hash if customer
  values
end