Class: Kiva::Loan

Inherits:
Object
  • Object
show all
Includes:
Api, DynamicInitializer
Defined in:
lib/ruby-kiva/loan.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DynamicInitializer

included

Methods included from Api

app_id, app_id=, friendly, friendly=, included

Instance Attribute Details

#activityObject

Returns the value of attribute activity.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def activity
  @activity
end

#basket_amountObject

Returns the value of attribute basket_amount.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def basket_amount
  @basket_amount
end

#borrower_countObject

Returns the value of attribute borrower_count.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def borrower_count
  @borrower_count
end

#delinquentObject

Returns the value of attribute delinquent.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def delinquent
  @delinquent
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def description
  @description
end

#funded_amountObject

Returns the value of attribute funded_amount.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def funded_amount
  @funded_amount
end

#funded_dateObject

Returns the value of attribute funded_date.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def funded_date
  @funded_date
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def id
  @id
end

#journal_totalsObject

Returns the value of attribute journal_totals.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def journal_totals
  @journal_totals
end

#loan_amountObject

Returns the value of attribute loan_amount.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def loan_amount
  @loan_amount
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def name
  @name
end

Returns the value of attribute paid_amount.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def paid_amount
  @paid_amount
end

#partner_idObject

Returns the value of attribute partner_id.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def partner_id
  @partner_id
end

#sectorObject

Returns the value of attribute sector.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def sector
  @sector
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def status
  @status
end

#termsObject

Returns the value of attribute terms.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def terms
  @terms
end

#useObject

Returns the value of attribute use.



6
7
8
# File 'lib/ruby-kiva/loan.rb', line 6

def use
  @use
end

Class Method Details

.find(params) ⇒ Object

Search for Loans. Different searches are possible either: :id: An ID, a comma delimited String of IDs or an Array of IDs __or__ :lender_id: A single ID of a lender __or__ :team_id : a single ID of a team __or a combination of__

  • :partner_id: A (comma delimited) String of Partner IDs or an Array of partner IDs

  • :status: A String or symbol with the Loan status

  • :query: A String

If searching for a single ID, then this method can return nil (no item with this ID found). Otherwise this method will always return a PagedArray instance (which might be empty though)

When searching for multiple Loans, then the :page parameter is supported to specify the desired page.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ruby-kiva/loan.rb', line 80

def self.find(params)
  if params[:id] # find one or many by ID
    data = get("/loans/#{sanitize_id_parameter(params[:id])}.json", :query => sanitize_options(params))
    many = sanitize_id_parameter(params[:id]).include?(',')
  elsif params[:lender_id] # find all loans for a lender
    data = get("/lenders/#{params[:lender_id]}/loans.json", :query => sanitize_options(params))
    many = true
  elsif params[:team_id] # find all loans for a team
    data = get("/teams/#{params[:team_id]}/loans.json", :query => sanitize_options(params))
    many = true
  else # search
    puts "Searching with #{base_options(params).merge(find_options(params)).inspect}"
    data = get('/loans/search.json', :query => sanitize_options(params))
    many = true
  end
  json_to_paged_array(data, 'loans', many)
end

.newest(options = {}) ⇒ Object

Supported options:

  • :page: The requested page number



58
59
60
61
# File 'lib/ruby-kiva/loan.rb', line 58

def self.newest(options = {})
  data = get('/loans/newest.json', :query => base_options(options))
  json_to_paged_array(data, 'loans', true)
end

Instance Method Details

#description_languagesObject



28
29
30
# File 'lib/ruby-kiva/loan.rb', line 28

def description_languages
  @description_languages
end

#description_text(language) ⇒ Object



36
37
38
# File 'lib/ruby-kiva/loan.rb', line 36

def description_text(language)
  description_texts[language]
end

#description_textsObject



32
33
34
# File 'lib/ruby-kiva/loan.rb', line 32

def description_texts
  @description_texts
end

#journal_entries(params = {}) ⇒ Object



47
48
49
# File 'lib/ruby-kiva/loan.rb', line 47

def journal_entries(params = {})
  @journal_entries ||= JournalEntry.find(params.merge({:loan_id => self.id}))
end

#lenders(params = {}) ⇒ Object

Get the lenders for this loan Caches the lenders, reload loan if you need to refresh the lenders



42
43
44
# File 'lib/ruby-kiva/loan.rb', line 42

def lenders(params = {})
  @lenders ||= Lender.find(params.merge({:loan_id => self.id}))
end

#loan_updatesObject



51
52
53
# File 'lib/ruby-kiva/loan.rb', line 51

def loan_updates
  @loan_updates ||= find_loan_updates()
end

#to_sObject



98
99
100
# File 'lib/ruby-kiva/loan.rb', line 98

def to_s()
  "<Loan '%s' (%s) in %s with status %s, from %s>" % [self.name, self.id, self.location, self.id, self.borrowers]
end