Class: StackExchange::StackOverflow::Comment

Inherits:
Base
  • Object
show all
Defined in:
lib/pilha/stack_overflow/comment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#api_methods, client, #initialize, parse_with_class, request, setup_delegators

Constructor Details

This class inherits a constructor from StackExchange::StackOverflow::Base

Class Method Details

.find(id, options = {}) ⇒ Object



10
11
12
# File 'lib/pilha/stack_overflow/comment.rb', line 10

def find(id, options = {})
  request('/comments/:id/', id, options)
end

.find_by_mentioned_user_id(id, options = {}) ⇒ Object



26
27
28
# File 'lib/pilha/stack_overflow/comment.rb', line 26

def find_by_mentioned_user_id(id, options = {})
  request('/users/:id/mentioned', id, options) 
end

.find_by_question_id(id, options = {}) ⇒ Object



14
15
16
# File 'lib/pilha/stack_overflow/comment.rb', line 14

def find_by_question_id(id, options = {})
  request('/questions/:id/comments', id, options)
end

.find_by_user_id(id, options = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/pilha/stack_overflow/comment.rb', line 18

def find_by_user_id(id, options = {})
  if options[:to_user]
    request('/users/:id/comments/:to_user', id, options)
  else
    request('/users/:id/comments', id, options)
  end
end

.parse(response) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/pilha/stack_overflow/comment.rb', line 30

def parse(response)
  response['comments'].each do |comment|
    parse_with_class(comment, 'owner', User)
    parse_with_class(comment, 'reply_to_user', User)
  end
  parse_with_class(response, 'comments', Comment)
  OpenStruct.new response
end

Instance Method Details

#idObject



40
41
42
# File 'lib/pilha/stack_overflow/comment.rb', line 40

def id
  @struct.comment_id
end

#mentioned_userObject



44
45
46
# File 'lib/pilha/stack_overflow/comment.rb', line 44

def mentioned_user
  @struct.reply_to_user
end