Module: API::StackOverflow

Includes:
HTTParty
Defined in:
lib/answer.rb,
lib/question.rb,
lib/stack_overflow.rb,
lib/stack_overflow/version.rb

Defined Under Namespace

Classes: Answer, Question

Constant Summary collapse

VERSION =
"0.0.9"
@@API_KEY =
nil
@@URL =
"http://api.stackoverflow.com/1.1/"

Class Method Summary collapse

Class Method Details

.API_KEY=(value) ⇒ Object



12
13
14
# File 'lib/stack_overflow.rb', line 12

def self.API_KEY=(value)
  @@API_KEY = value
end

.get_all_users(options = {}) ⇒ Object



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

def self.get_all_users(options={})
  key = @@API_KEY
  page = options[:page] || 1
  pagesize = options[:pagesize] || 30
  url = URI.parse(@@URL + "users?key=#{key}&page=#{page}&pagesize=#{pagesize}")
  response = Net::HTTP.get_response url
  gz = Zlib::GzipReader.new(StringIO.new(response.body))
  JSON.parse(gz.read)
end

.get_tagsObject



52
53
54
# File 'lib/stack_overflow.rb', line 52

def self.get_tags
  get(@@URL + "tags?key=#{@@API_KEY}")
end

.get_tags_synonymsObject



56
57
58
# File 'lib/stack_overflow.rb', line 56

def self.get_tags_synonyms
  get(@@URL + "tags/synonyms?key=#{@@API_KEY}")
end

.get_user(user_id) ⇒ Object



26
27
28
29
30
# File 'lib/stack_overflow.rb', line 26

def self.get_user(user_id)
  result = get(@@URL + "users/#{user_id}?key=#{@@API_KEY}")
  return nil if result["users"].nil?
  result["users"].first
end

.get_user_answers(user_id) ⇒ Object



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

def self.get_user_answers(user_id)
  result = get(@@URL + "users/#{user_id}/answers?key=#{@@API_KEY}")
  result["answers"].map{|a| Answer.new(a) }
end

.get_user_questions(user_id) ⇒ Object



38
39
40
41
# File 'lib/stack_overflow.rb', line 38

def self.get_user_questions(user_id)
  result = get(@@URL + "users/#{user_id}/questions?key=#{@@API_KEY}")
  result["questions"].map{|q| Question.new(q) }
end

.get_user_tags(user_id) ⇒ Object



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

def self.get_user_tags(user_id)
  get(@@URL + "users/#{user_id}/tags?key=#{@@API_KEY}")
end

.get_users(user_ids) ⇒ Object



32
33
34
35
36
# File 'lib/stack_overflow.rb', line 32

def self.get_users(user_ids)
  user_id = user_ids.join(";").to_s
  result = get(@@URL + "users/#{user_id}?key=#{@@API_KEY}")
  result["users"]
end