Class: Kiva::JournalEntry
- Inherits:
-
Object
- Object
- Kiva::JournalEntry
- Defined in:
- lib/kiva.rb
Overview
Journal entries are attached to loans. Using the class method load
you can retrieve all entries attached to a particular loan.
Constant Summary collapse
- KEY =
"journal_entries"
- LOAD =
"http://api.kivaws.org/v1/loans/%s/journal_entries.json?"
- SEARCH =
"http://api.kivaws.org/v1/journal_entries/search.json?"
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#body ⇒ Object
Returns the value of attribute body.
-
#bulk ⇒ Object
Returns the value of attribute bulk.
-
#comment_count ⇒ Object
Returns the value of attribute comment_count.
-
#date ⇒ Object
Returns the value of attribute date.
-
#id ⇒ Object
Returns the value of attribute id.
-
#image ⇒ Object
Returns the value of attribute image.
-
#recommendation_count ⇒ Object
Returns the value of attribute recommendation_count.
-
#subject ⇒ Object
Returns the value of attribute subject.
Class Method Summary collapse
-
.load(id, page = nil, include_bulk = nil) ⇒ Object
Load journal entries for a loan.
-
.search(filter, sort_by = nil, page = nil) ⇒ Object
Search for journal entries.
Instance Method Summary collapse
-
#comments ⇒ Object
Retrieve an array of
Comment
instances associated with this entry.
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
391 392 393 |
# File 'lib/kiva.rb', line 391 def @author end |
#body ⇒ Object
Returns the value of attribute body.
388 389 390 |
# File 'lib/kiva.rb', line 388 def body @body end |
#bulk ⇒ Object
Returns the value of attribute bulk.
393 394 395 |
# File 'lib/kiva.rb', line 393 def bulk @bulk end |
#comment_count ⇒ Object
Returns the value of attribute comment_count.
390 391 392 |
# File 'lib/kiva.rb', line 390 def comment_count @comment_count end |
#date ⇒ Object
Returns the value of attribute date.
389 390 391 |
# File 'lib/kiva.rb', line 389 def date @date end |
#id ⇒ Object
Returns the value of attribute id.
387 388 389 |
# File 'lib/kiva.rb', line 387 def id @id end |
#image ⇒ Object
Returns the value of attribute image.
394 395 396 |
# File 'lib/kiva.rb', line 394 def image @image end |
#recommendation_count ⇒ Object
Returns the value of attribute recommendation_count.
395 396 397 |
# File 'lib/kiva.rb', line 395 def recommendation_count @recommendation_count end |
#subject ⇒ Object
Returns the value of attribute subject.
392 393 394 |
# File 'lib/kiva.rb', line 392 def subject @subject end |
Class Method Details
.load(id, page = nil, include_bulk = nil) ⇒ Object
Load journal entries for a loan.
Parameters
id
: a loan id or an instance of Loan
Returns
an array of JournalEntry
instances.
Corresponds
developers.wiki.kiva.org/KivaAPI#loans/ltidgt/journalentries
430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/kiva.rb', line 430 def load id, page = nil, include_bulk = nil id = id.id if id.is_a? Loan url = LOAD % id url = page ? url + "page=#{page}&" : url url = (! include_bulk.nil?) ? url + "include_bulk=#{include_bulk}" : url raw = raw = Kiva.execute(url) unw = JSON.parse(raw) Kiva._populate JournalEntry, unw[KEY] end |
.search(filter, sort_by = nil, page = nil) ⇒ Object
Search for journal entries.
Parameters
filter
: an instance of JournalFilter defining the search sort_by
: one of [:newest, :oldest, :recommendation_count, :comment_count] page
: page to load
Returns
an array of JournalEntry
instances.
Corresponds
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/kiva.rb', line 458 def search filter, sort_by=nil, page=nil url = SEARCH filter ||= JournalFilter.new if sort_by && [:newest, :oldest, :recommendation_count, :comment_count].include?(sort_by) filter["sort_by"]=sort_by end if page filter["page"]=page end raw = Kiva.execute url, filter.params unw = JSON.parse(raw) Kiva._populate JournalEntry, unw[KEY] end |
Instance Method Details
#comments ⇒ Object
Retrieve an array of Comment
instances associated with this entry. N.B. this leads to a further network call.
401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/kiva.rb', line 401 def comments unless @comments return nil if id.nil? if @comment_count != 0 @comments = Comment.load(self) else @commetns = [] end end @comments end |