Class: Kiva::Loan
- Inherits:
-
Object
- Object
- Kiva::Loan
- Defined in:
- lib/kiva.rb
Overview
Represents a Loan (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_lender
-
load_newest
-
search
to load loans from Kiva.
Constant Summary collapse
- KEY =
"loans"
- LOAD_FOR_LENDER =
"http://api.kivaws.org/v1/lenders/%s/loans.json?"
- LOAD_NEWEST =
"http://api.kivaws.org/v1/loans/newest.json?"
- LOAD =
"http://api.kivaws.org/v1/loans/%s.json"
- SEARCH =
"http://api.kivaws.org/v1/loans/search.json"
Instance Attribute Summary collapse
-
#activity ⇒ Object
Returns the value of attribute activity.
-
#basket_amount ⇒ Object
Returns the value of attribute basket_amount.
-
#borrower_count ⇒ Object
Returns the value of attribute borrower_count.
-
#borrowers ⇒ Object
Returns the value of attribute borrowers.
-
#description ⇒ Object
Returns the value of attribute description.
-
#funded_amount ⇒ Object
Returns the value of attribute funded_amount.
-
#funded_date ⇒ Object
Returns the value of attribute funded_date.
-
#id ⇒ Object
Returns the value of attribute id.
-
#image ⇒ Object
Returns the value of attribute image.
-
#loan_amount ⇒ Object
Returns the value of attribute loan_amount.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
-
#partner_id ⇒ Object
Returns the value of attribute partner_id.
-
#posted_date ⇒ Object
Returns the value of attribute posted_date.
-
#sector ⇒ Object
Returns the value of attribute sector.
-
#status ⇒ Object
Returns the value of attribute status.
-
#terms ⇒ Object
Returns the value of attribute terms.
-
#use ⇒ Object
Returns the value of attribute use.
Class Method Summary collapse
-
.load(ids) ⇒ Object
Returns details for one or more loans.
-
.load_for_lender(id, sort_by = nil, page = nil) ⇒ Object
Returns loans sponsored by a specified lender.
-
.load_newest(page = nil) ⇒ Object
Returns the most recent fundraising loans.
-
.search(filter, page = nil) ⇒ Object
Search for loans matching specific criteria.
Instance Attribute Details
#activity ⇒ Object
Returns the value of attribute activity.
118 119 120 |
# File 'lib/kiva.rb', line 118 def activity @activity end |
#basket_amount ⇒ Object
Returns the value of attribute basket_amount.
129 130 131 |
# File 'lib/kiva.rb', line 129 def basket_amount @basket_amount end |
#borrower_count ⇒ Object
Returns the value of attribute borrower_count.
131 132 133 |
# File 'lib/kiva.rb', line 131 def borrower_count @borrower_count end |
#borrowers ⇒ Object
Returns the value of attribute borrowers.
119 120 121 |
# File 'lib/kiva.rb', line 119 def borrowers @borrowers end |
#description ⇒ Object
Returns the value of attribute description.
120 121 122 |
# File 'lib/kiva.rb', line 120 def description @description end |
#funded_amount ⇒ Object
Returns the value of attribute funded_amount.
124 125 126 |
# File 'lib/kiva.rb', line 124 def funded_amount @funded_amount end |
#funded_date ⇒ Object
Returns the value of attribute funded_date.
125 126 127 |
# File 'lib/kiva.rb', line 125 def funded_date @funded_date end |
#id ⇒ Object
Returns the value of attribute id.
114 115 116 |
# File 'lib/kiva.rb', line 114 def id @id end |
#image ⇒ Object
Returns the value of attribute image.
126 127 128 |
# File 'lib/kiva.rb', line 126 def image @image end |
#loan_amount ⇒ Object
Returns the value of attribute loan_amount.
132 133 134 |
# File 'lib/kiva.rb', line 132 def loan_amount @loan_amount end |
#location ⇒ Object
Returns the value of attribute location.
127 128 129 |
# File 'lib/kiva.rb', line 127 def location @location end |
#name ⇒ Object
Returns the value of attribute name.
116 117 118 |
# File 'lib/kiva.rb', line 116 def name @name end |
#partner_id ⇒ Object
Returns the value of attribute partner_id.
122 123 124 |
# File 'lib/kiva.rb', line 122 def partner_id @partner_id end |
#posted_date ⇒ Object
Returns the value of attribute posted_date.
117 118 119 |
# File 'lib/kiva.rb', line 117 def posted_date @posted_date end |
#sector ⇒ Object
Returns the value of attribute sector.
128 129 130 |
# File 'lib/kiva.rb', line 128 def sector @sector end |
#status ⇒ Object
Returns the value of attribute status.
115 116 117 |
# File 'lib/kiva.rb', line 115 def status @status end |
#terms ⇒ Object
Returns the value of attribute terms.
121 122 123 |
# File 'lib/kiva.rb', line 121 def terms @terms end |
#use ⇒ Object
Returns the value of attribute use.
123 124 125 |
# File 'lib/kiva.rb', line 123 def use @use end |
Class Method Details
.load(ids) ⇒ Object
Returns details for one or more loans.
Paramaters
ids
: an instance of Loan
or a loan id or an array Loan
‘s or loan id’s
Returns
an array of Loan
instances
Corresponds
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/kiva.rb', line 160 def load ids case ids when Loan ids = ids.id when Array if ids[0].is_a?(Loan) ids = ids.map{|l| l.id} end ids.join(",") end url = LOAD % ids raw = Kiva.execute url unw = JSON.parse(raw) Kiva._populate Loan, unw[KEY] end |
.load_for_lender(id, sort_by = nil, page = nil) ⇒ Object
Returns loans sponsored by a specified lender
Parameters
-
id
: id of lender or instance ofLender
-
sort_by
: one of:newest, :oldest
-
page
: page position
Returns
array of Loan
‘s
Corresponds
243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/kiva.rb', line 243 def load_for_lender id, sort_by=nil, page=nil id = id.uid if id.is_a?(Lender) url = LOAD_FOR_LENDER % id url = page ? url + "page=#{page}&" : url url = [:newest, :oldest].include?(sort_by) ? url + "sort_by=#{sort_by}" : url raw = Kiva.execute url unw = JSON.parse(raw) Kiva._populate Loan, unw[KEY] end |
.load_newest(page = nil) ⇒ Object
Returns the most recent fundraising loans.
Parameters
page
: the page position
Returns
an array of Loan
instances
Corresponds
217 218 219 220 221 222 223 224 225 |
# File 'lib/kiva.rb', line 217 def load_newest page=nil url = LOAD_NEWEST url = page ? url + "page=#{page}&" : url raw = Kiva.execute url unw = JSON.parse(raw) Kiva._populate Loan, unw[KEY] end |
.search(filter, page = nil) ⇒ Object
Search for loans matching specific criteria.
Parameters
filter
: an instance of LoanFilter
describing the search parameter
Returns
an array of Loan
instances
Corresponds
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/kiva.rb', line 191 def search filter, page=nil url = SEARCH filter ||= LoanFilter.new if page filter["page"] = page end raw = Kiva.execute url, filter.params unw = JSON.parse(raw) Kiva._populate Loan, unw[KEY] end |