Class: Kiva::Lender

Inherits:
Object
  • Object
show all
Defined in:
lib/kiva.rb

Overview

Represents a Lender (whoda guessed.) The accessible parameters are all all there is to this. Depending on how a particular instance of loan was loaded, not all of the attributes need have a value, so remember to check for nil.

Use one of the class functions:

  • load

  • load_for_loan

to load lender information from Kiva.

Constant Summary collapse

KEY =
"lenders"
LOAD =
"http://api.kivaws.org/v1/lenders/%s.json"
LOAD_FOR_LOAN =
"http://api.kivaws.org/v1/loans/%s/lenders.json?"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#country_codeObject

Returns the value of attribute country_code.



279
280
281
# File 'lib/kiva.rb', line 279

def country_code
  @country_code
end

#imageObject

Returns the value of attribute image.



285
286
287
# File 'lib/kiva.rb', line 285

def image
  @image
end

#invitee_countObject

Returns the value of attribute invitee_count.



281
282
283
# File 'lib/kiva.rb', line 281

def invitee_count
  @invitee_count
end

#lender_idObject

Returns the value of attribute lender_id.



275
276
277
# File 'lib/kiva.rb', line 275

def lender_id
  @lender_id
end

#loan_becauseObject

Returns the value of attribute loan_because.



280
281
282
# File 'lib/kiva.rb', line 280

def loan_because
  @loan_because
end

#loan_countObject

Returns the value of attribute loan_count.



277
278
279
# File 'lib/kiva.rb', line 277

def loan_count
  @loan_count
end

#member_sinceObject

Returns the value of attribute member_since.



286
287
288
# File 'lib/kiva.rb', line 286

def member_since
  @member_since
end

#nameObject

Returns the value of attribute name.



276
277
278
# File 'lib/kiva.rb', line 276

def name
  @name
end

#occupationObject

Returns the value of attribute occupation.



278
279
280
# File 'lib/kiva.rb', line 278

def occupation
  @occupation
end

#occupational_infoObject

Returns the value of attribute occupational_info.



282
283
284
# File 'lib/kiva.rb', line 282

def occupational_info
  @occupational_info
end

#personal_urlObject

Returns the value of attribute personal_url.



283
284
285
# File 'lib/kiva.rb', line 283

def personal_url
  @personal_url
end

#uidObject



274
275
276
# File 'lib/kiva.rb', line 274

def uid
  @uid
end

#whereaboutsObject

Returns the value of attribute whereabouts.



284
285
286
# File 'lib/kiva.rb', line 284

def whereabouts
  @whereabouts
end

Class Method Details

.load(ids) ⇒ Object

Load details for one or more Lenders.

Parameters

ids : a lender id or and array of id’s

Returns

an array of Lender instances.

Corresponds

developers.wiki.kiva.org/KivaAPI#lenders/ltlenderidsgt



335
336
337
338
339
340
341
342
# File 'lib/kiva.rb', line 335

def load ids
  ids  = ids.join(",") if ids.is_a?(Array)
  url  = LOAD % ids
  raw  = Kiva.execute(url)
  unw = JSON.parse(raw)

  Kiva._populate Lender, unw[KEY]
end

.load_for_loan(loan, page = nil) ⇒ Object

List public lenders of a loan.

Parameters

loan : a loan id or an instance of Loan

Returns

an array of Lender instances.

Corresponds

developers.wiki.kiva.org/KivaAPI#loans/ltidgt/lenders



309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/kiva.rb', line 309

def load_for_loan loan, page = nil
  loan = loan.id if loan.is_a?(Loan)

  url = LOAD_FOR_LOAN % loan

  url = page ? url + "page=#{page}&" : url
  
  raw  = Kiva.execute(url)
  unw = JSON.parse(raw)

  Kiva._populate Lender, unw[KEY]

end