Class: StackExchange::StackOverflow::Question

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

.all(options = {}) ⇒ Object



13
14
15
# File 'lib/pilha/stack_overflow/question.rb', line 13

def all(options = {})
  request('/questions', nil, options)
end

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



17
18
19
# File 'lib/pilha/stack_overflow/question.rb', line 17

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

.find_by_tags(*tags) ⇒ Object



29
30
31
32
33
# File 'lib/pilha/stack_overflow/question.rb', line 29

def find_by_tags(*tags)
  options = tags.last.is_a?(Hash) ? tags.pop : {}
  options.merge!(:conditions => { :tagged => tags.join('+') })
  request('/questions', nil, options)
end

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



21
22
23
# File 'lib/pilha/stack_overflow/question.rb', line 21

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

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



25
26
27
# File 'lib/pilha/stack_overflow/question.rb', line 25

def find_favorites_by_user_id(id, options = {})
  request('/users/:id/favorites', id, options) 
end

.parse(response) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/pilha/stack_overflow/question.rb', line 39

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

.unanswered(options = {}) ⇒ Object



35
36
37
# File 'lib/pilha/stack_overflow/question.rb', line 35

def unanswered(options = {})
  request('/questions/unanswered', nil, options)
end

Instance Method Details

#idObject



48
49
50
# File 'lib/pilha/stack_overflow/question.rb', line 48

def id
  @struct.question_id
end