Class: Kiva::Comment

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

Overview

User comment made in response to a JournalEntry.

Constant Summary collapse

KEY =
"comments"
URL =
"http://api.kivaws.org/v1/journal_entries/%s/comments.json?"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#authorObject

Returns the value of attribute author.



482
483
484
# File 'lib/kiva.rb', line 482

def author
  @author
end

#bodyObject



480
481
482
# File 'lib/kiva.rb', line 480

def body
  @body
end

#dateObject

Returns the value of attribute date.



481
482
483
# File 'lib/kiva.rb', line 481

def date
  @date
end

#idObject

Returns the value of attribute id.



483
484
485
# File 'lib/kiva.rb', line 483

def id
  @id
end

#whereaboutsObject

Returns the value of attribute whereabouts.



484
485
486
# File 'lib/kiva.rb', line 484

def whereabouts
  @whereabouts
end

Class Method Details

.load(id, page = nil) ⇒ Object

Loads an array of comments for a JournalEntry.

Parameters

  • id : the numerical id of a Journal Entry or an instance of the class JournalEntry

  • page: which page of comments to load, default is the first.

Returns

array of Comments

Corresponds

developers.wiki.kiva.org/KivaAPI#journalentries/ltidgt/comments



503
504
505
506
507
508
509
510
511
512
# File 'lib/kiva.rb', line 503

def load id, page=nil
  id = id.id if id.is_a?(JournalEntry)
     
  url = URL % id
  url = page ? url + "page=#{page}&" : url

  raw = raw = Kiva.execute(url)
  unw = JSON.parse(raw)
  Kiva._populate Comment, unw[KEY]
end