Class: Musoni::Loan

Inherits:
Endpoint show all
Defined in:
lib/musoni_ruby/endpoints/loan.rb

Instance Attribute Summary collapse

Attributes inherited from Endpoint

#attributes, #config, #endpoint, #id, #pagination, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Endpoint

#fail?, #initialize, #success?

Constructor Details

This class inherits a constructor from Musoni::Endpoint

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Musoni::Endpoint

Instance Attribute Details

#payable_items=(value) ⇒ Object (writeonly)

Sets the attribute payable_items

Parameters:

  • value

    the value to set the attribute payable_items to.



3
4
5
# File 'lib/musoni_ruby/endpoints/loan.rb', line 3

def payable_items=(value)
  @payable_items = value
end

#transactions=(value) ⇒ Object (writeonly)

Sets the attribute transactions

Parameters:

  • value

    the value to set the attribute transactions to.



3
4
5
# File 'lib/musoni_ruby/endpoints/loan.rb', line 3

def transactions=(value)
  @transactions = value
end

Class Method Details

.all(offset: 1, limit: 100) ⇒ Object

Musoni::Loan.all()



8
9
10
11
# File 'lib/musoni_ruby/endpoints/loan.rb', line 8

def all(offset:1,limit:100)
  url = "/loans"
  Musoni::Fetch.get(url,query:{offset:offset,limit:limit}).pageItems
end

.create(options = {}) ⇒ Object

account_attributes = :clientId=>“1”,:productId=>“1”,:submittedOnDate=>“13-05-2015”,:fieldOfficerId=>“1”,:charges=>[],:allowOverdraft=>false Musoni::Loan.create(account_attributes)



22
23
24
25
26
# File 'lib/musoni_ruby/endpoints/loan.rb', line 22

def create(options={})
  url = "/loans"
  response = Musoni::Fetch.post(url,options)
  new(options.merge!(id:response.loanId ,response:response)) rescue response
end

.find(loan_id, fetch: true) ⇒ Object

Musoni::Loan.find(loan_id)



14
15
16
17
18
# File 'lib/musoni_ruby/endpoints/loan.rb', line 14

def find(loan_id,fetch:true)
  url = "/loans/#{loan_id}?associations=all"
  response = Musoni::Fetch.get(url) if fetch
  loan = new(id:loan_id,response:response)
end

Instance Method Details

#allocate(options = {}) ⇒ Object

loan.allocate(account: account, amount:100) loan.allocate(client_id: clientId, account_id: savingsId, amount:100)



62
63
64
65
66
67
# File 'lib/musoni_ruby/endpoints/loan.rb', line 62

def allocate(options={})
  options = {guarantorTypeId: 1, entityId: options[:client_id], savingsId: options[:account_id], amount: options[:amount], locale: "en_GB"}
  url = "/loans/#{self.id}/guarantors"
  response = Musoni::Fetch.post(url,options)
  self.response = response
end

#update(options) ⇒ Object

loan_options = :interestCalculationPeriodType=>“1”,:interestRatePerPeriod=>“7”,:interestType=>“1”,:loanTermFrequency=>“1”,:loanTermFrequencyType=>“2”,:numberOfRepayments=>“1”,:principal=>“1000”,:productId=>1,:repaymentEvery=>“1”,:repaymentFrequencyType=>“2” loan.update(loan_options)



54
55
56
57
58
# File 'lib/musoni_ruby/endpoints/loan.rb', line 54

def update(options)
  url = "/loans/#{self.id}"
  response = Musoni::Fetch.put(url,options)
  self.response = response
end