Class: Kiva::Lender

Inherits:
Object
  • Object
show all
Includes:
Api, DynamicInitializer
Defined in:
lib/ruby-kiva/lender.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

#country_codeObject

Returns the value of attribute country_code.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def country_code
  @country_code
end

#invitee_countObject

Returns the value of attribute invitee_count.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def invitee_count
  @invitee_count
end

#lender_idObject

Returns the value of attribute lender_id.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def lender_id
  @lender_id
end

#loan_becauseObject

Returns the value of attribute loan_because.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def loan_because
  @loan_because
end

#loan_countObject

Returns the value of attribute loan_count.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def loan_count
  @loan_count
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def name
  @name
end

#occupationObject

Returns the value of attribute occupation.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def occupation
  @occupation
end

#occupational_infoObject

Returns the value of attribute occupational_info.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def occupational_info
  @occupational_info
end

#personal_urlObject

Returns the value of attribute personal_url.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def personal_url
  @personal_url
end

#uidObject

Returns the value of attribute uid.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def uid
  @uid
end

#whereaboutsObject

Returns the value of attribute whereabouts.



5
6
7
# File 'lib/ruby-kiva/lender.rb', line 5

def whereabouts
  @whereabouts
end

Class Method Details

.find(params = {}) ⇒ Object

Find Lenders __either__ :id : A single ID or a comma Separated String of IDs or an Array of IDs __or__ :loan_id : A single loan ID __or__ :team_id : a single team ID, supports :sort_by

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) If querying for multiple items, then :page is supported



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruby-kiva/lender.rb', line 42

def self.find(params = {})
  if params[:id] # find one or many by lender ID
    data = get("/lenders/#{sanitize_id_parameter(params[:id])}.json", :query => sanitize_options(params))
    many = sanitize_id_parameter(params[:id]).include?(',')
  elsif params[:loan_id] # find lenders for a loan
    data = get("/loans/#{params[:loan_id]}/lenders.json", :query => sanitize_options(params))
    many = true
  elsif params[:team_id]
    data = get("/teams/#{params[:team_id]}/lenders.json", :query => sanitize_options(params))
    many = true
  else
    data = get("/lenders/search.json", :query => sanitize_options(params))
    many = true
  end
  json_to_paged_array(data, 'lenders', many)
end

.newest(params = {}) ⇒ Object



27
28
29
# File 'lib/ruby-kiva/lender.rb', line 27

def self.newest(params = {})
  json_to_paged_array(get('/lenders/newest.json', :query => sanitize_options(params)), 'lenders', true)
end

Instance Method Details

#lender_page_urlObject



13
14
15
# File 'lib/ruby-kiva/lender.rb', line 13

def lender_page_url
  "http://www.kiva.org/lender/#{self.lender_id}"
end

#loans(params = {}) ⇒ Object

find the loans for this lender loans are cached to avoid roundtrips, refetch the lender if you need to refresh loans



19
20
21
# File 'lib/ruby-kiva/lender.rb', line 19

def loans(params = {})
  @loans ||= Loan.find(params.merge({:lender_id => self.lender_id}))
end

#to_sObject



23
24
25
# File 'lib/ruby-kiva/lender.rb', line 23

def to_s()
  "<Lender #{self.lender_id}>"
end