Class: StackExchange::StackOverflow::Answer

Inherits:
Base
  • Object
show all
Defined in:
lib/pilha/stack_overflow/answer.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



11
12
13
# File 'lib/pilha/stack_overflow/answer.rb', line 11

def find(id, options = {})
  request('/answers/:id', id, options).answers.first
end

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



19
20
21
# File 'lib/pilha/stack_overflow/answer.rb', line 19

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

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



15
16
17
# File 'lib/pilha/stack_overflow/answer.rb', line 15

def find_by_user_id(id, options = {})
  request('/users/:id/answers', id, options)
end

.parse(response) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/pilha/stack_overflow/answer.rb', line 23

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

Instance Method Details

#idObject



33
34
35
# File 'lib/pilha/stack_overflow/answer.rb', line 33

def id
  @struct.answer_id
end