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.



448
449
450
# File 'lib/kiva.rb', line 448

def author
  @author
end

#bodyObject



446
447
448
# File 'lib/kiva.rb', line 446

def body
  @body
end

#dateObject

Returns the value of attribute date.



447
448
449
# File 'lib/kiva.rb', line 447

def date
  @date
end

#idObject

Returns the value of attribute id.



449
450
451
# File 'lib/kiva.rb', line 449

def id
  @id
end

#whereaboutsObject

Returns the value of attribute whereabouts.



450
451
452
# File 'lib/kiva.rb', line 450

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



469
470
471
472
473
474
475
476
477
478
# File 'lib/kiva.rb', line 469

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