class NsdaQaSearch

Public Class Methods

show(id, action="all") click to toggle source
# File lib/nsda_qa_search.rb, line 46
def self.show(id, action="all")
  url_answers = "http://api.stackexchange.com/2.2/questions/%s/answers?order=desc&sort=activity&site=stackoverflow&filter=!9WgJfjI5u" % id
  url_question = "http://api.stackexchange.com/2.2/questions/%s?order=desc&sort=creation&site=stackoverflow&filter=!9WgJfiTRL" % id
      
  response_answers = HTTParty.get(url_answers)
  response_question = HTTParty.get(url_question)
      
  result ||= "question api url: %s\n" % url_question
  result ||= "answer url      : %s\n" % url_answers
  result +=  "-" * 80 + "\n"
  
  question = response_question['items'][0]
  result += "######%s. %s######\n" % [question['question_id'], question['title']]
  result += "+" * 80 + "\n"
  result += "+" * 80 + "\n"
  response_answers['items'].each_with_index do |item, index|
    result += "### %s. %s\n" % [:id, item['answer_id']]
    result += "### %s: %s\n" % [:is_accepted, item['is_accepted']]
    result += "#" * 80 + "\n"
    result += "###%s: %s\n" % [:content, item['body']]
    result += "#" * 80 + "\n"
    result += "-" * 80 + "\n"
  end
  
  result
end