Class: KivaApi::CommentsResponse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed_response) ⇒ CommentsResponse

Returns a new instance of CommentsResponse.



4
5
6
# File 'lib/kiva_api/comments_response.rb', line 4

def initialize(parsed_response)
  @response = parsed_response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



2
3
4
# File 'lib/kiva_api/comments_response.rb', line 2

def response
  @response
end

Instance Method Details

#comment_countObject



24
25
26
27
28
29
30
# File 'lib/kiva_api/comments_response.rb', line 24

def comment_count
  if @response.present? and @response["properties"].is_a?(Hash)
    @response["properties"]["count"]
  else
    0
  end
end

#commentsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/kiva_api/comments_response.rb', line 8

def comments
  if @response.present? and @response["entities"]
    comments = []
    @response["entities"].each do |comment|
      comments << {
          body: comment["properties"]["body"],
          date: comment["properties"]["date"],
          author: comment["properties"]["authorName"]
      }
    end
    comments
  else
    []
  end
end