Class: Kiva::JournalEntry

Inherits:
Object
  • Object
show all
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?"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorObject

Returns the value of attribute author.



390
391
392
# File 'lib/kiva.rb', line 390

def author
  @author
end

#bodyObject

Returns the value of attribute body.



387
388
389
# File 'lib/kiva.rb', line 387

def body
  @body
end

#bulkObject

Returns the value of attribute bulk.



392
393
394
# File 'lib/kiva.rb', line 392

def bulk
  @bulk
end

#comment_countObject

Returns the value of attribute comment_count.



389
390
391
# File 'lib/kiva.rb', line 389

def comment_count
  @comment_count
end

#dateObject

Returns the value of attribute date.



388
389
390
# File 'lib/kiva.rb', line 388

def date
  @date
end

#idObject

Returns the value of attribute id.



386
387
388
# File 'lib/kiva.rb', line 386

def id
  @id
end

#recommendation_countObject

attr_accessor :image



394
395
396
# File 'lib/kiva.rb', line 394

def recommendation_count
  @recommendation_count
end

#subjectObject

Returns the value of attribute subject.



391
392
393
# File 'lib/kiva.rb', line 391

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



428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/kiva.rb', line 428

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

Instance Method Details

#commentsObject

Retrieve an array of Comment instances associated with this entry. N.B. this leads to a further network call.



400
401
402
403
404
405
406
407
408
409
410
# File 'lib/kiva.rb', line 400

def comments
  unless @comments 
    return nil if id.is_nil?
    if @comment_count != 0
      @comments = Comment.load(this)
    else
      @commetns = []
    end
  end
  @comments
end