Sha256: 45d0a24c124b6372fa73cedbc5802b2c72d912ac397ccea26c7552c843a0a84b

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

class Caren::Store::Account < Caren::Base

  def self.keys
    [:id,                   # Integer (Caren id)
     :balance,              # Integer (Balance in credits, unit depends on billable)
     :person_id,            # Integer (Caren person id)
     :billable_timeline_id, # Integer
    ] + super
  end

  def self.find id, session
    from_xml session.get(self.resource_url(id))
  end

  def self.all session
    from_xml session.get(self.resource_url)
  end
  
  def deposit_credits amount, session
    self.class.from_xml session.post self.class.deposit_credits_url(self.id), amount_xml(amount)
  end
  
  def withdraw_credits amount, session
    self.class.from_xml session.post self.class.withdraw_credits_url(self.id), amount_xml(amount)
  end
  
  def self.confirm_credits caren_event, session
    from_xml session.post confirm_credits_url, caren_event.to_xml
  end
  
  def self.reserve_credits caren_event, session
    from_xml session.post reserve_credits_url, caren_event.to_xml
  end
  
  def self.release_credits caren_event, session
    from_xml session.post release_credits_url, caren_event.to_xml
  end

  def self.array_root
    :accounts
  end

  def self.node_root
    :account
  end

  def amount_xml amount
    builder = Builder::XmlMarkup.new
    builder.tag! "amount", amount
  end

  def self.deposit_credits_url id
    "/api/pro/store/accounts/#{id}/deposit_credits"
  end
  
  def self.withdraw_credits_url id
    "/api/pro/store/accounts/#{id}/withdraw_credits"
  end

  def self.confirm_credits_url
    "/api/pro/store/accounts/confirm_credits"
  end
  
  def self.reserve_credits_url
    "/api/pro/store/accounts/reserve_credits"
  end
  
  def self.release_credits_url
    "/api/pro/store/accounts/release_credits"
  end

  def self.resource_location
    "/api/pro/store/accounts"
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
caren-api-0.6.16 lib/caren/store/account.rb
caren-api-0.6.15 lib/caren/store/account.rb
caren-api-0.6.14 lib/caren/store/account.rb
caren-api-0.6.13 lib/caren/store/account.rb