stack_overflow 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile.lock +15 -13
- data/README.rdoc +12 -10
- data/lib/answer.rb +29 -0
- data/lib/question.rb +35 -0
- data/lib/stack_overflow.rb +56 -53
- data/lib/stack_overflow/version.rb +4 -2
- data/spec/get_answers_spec.rb +11 -0
- data/spec/get_questions_spec.rb +11 -0
- data/spec/stack_overflow_spec.rb +11 -25
- data/stack_overflow.gemspec +1 -1
- metadata +8 -3
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stack_overflow (0.0.
|
4
|
+
stack_overflow (0.0.9)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
json (1.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
rspec-
|
18
|
-
|
19
|
-
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
httparty (0.8.1)
|
11
|
+
multi_json
|
12
|
+
multi_xml
|
13
|
+
json (1.6.3)
|
14
|
+
multi_json (1.0.4)
|
15
|
+
multi_xml (0.4.1)
|
16
|
+
rspec (2.7.0)
|
17
|
+
rspec-core (~> 2.7.0)
|
18
|
+
rspec-expectations (~> 2.7.0)
|
19
|
+
rspec-mocks (~> 2.7.0)
|
20
|
+
rspec-core (2.7.1)
|
21
|
+
rspec-expectations (2.7.0)
|
20
22
|
diff-lcs (~> 1.1.2)
|
21
|
-
rspec-mocks (2.
|
23
|
+
rspec-mocks (2.7.0)
|
22
24
|
|
23
25
|
PLATFORMS
|
24
26
|
ruby
|
data/README.rdoc
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
= Stack Overflow
|
2
2
|
|
3
|
+
*Ive* *namespaced* *this* *gem* *to* API::StackOverflow *so* *that* *I* *could* *use* 'StackOverflow' *for* *other* *namespacing* *purposes*
|
4
|
+
|
3
5
|
This is a simple gem that utilizes HTTParty and the StackOverflow API.
|
4
6
|
|
5
7
|
gem install stack_overflow
|
@@ -10,7 +12,7 @@ The StackOverflow API help can be found at http://api.stackoverflow.com/1.1/usag
|
|
10
12
|
|
11
13
|
Be sure to set the API Key.
|
12
14
|
|
13
|
-
StackOverflow.API_KEY = YOUR_KEY_GOES_HERE
|
15
|
+
API::StackOverflow.API_KEY = YOUR_KEY_GOES_HERE
|
14
16
|
|
15
17
|
You can get your key from StackOverflow by going here : http://stackapps.com/apps/register
|
16
18
|
|
@@ -18,51 +20,51 @@ You can get your key from StackOverflow by going here : http://stackapps.com/app
|
|
18
20
|
|
19
21
|
API documentation can be found at http://api.stackoverflow.com/1.1/usage/methods/users
|
20
22
|
|
21
|
-
StackOverflow.get_all_users
|
23
|
+
API::StackOverflow.get_all_users
|
22
24
|
|
23
25
|
By default the api returns the first page of users with 30 per page. This information can be read from the results. To get additional pages or change the pagesize (0-100) you can make call like:
|
24
26
|
|
25
|
-
StackOverflow.get_all_users(:page => 2, :per_page => 50)
|
27
|
+
API::StackOverflow.get_all_users(:page => 2, :per_page => 50)
|
26
28
|
|
27
29
|
== Get User(s)
|
28
30
|
|
29
31
|
API documentation can be found at http://api.stackoverflow.com/1.1/usage/methods/users-by-ids
|
30
32
|
|
31
|
-
StackOverflow.get_user(#user_id)
|
33
|
+
API::StackOverflow.get_user(#user_id)
|
32
34
|
|
33
35
|
You can also get a group of users by using
|
34
36
|
|
35
|
-
StackOverflow.get_users([#user_id1, #user_id2, etc])
|
37
|
+
API::StackOverflow.get_users([#user_id1, #user_id2, etc])
|
36
38
|
|
37
39
|
== Get User's Tags
|
38
40
|
|
39
41
|
API documentation can be found at http://api.stackoverflow.com/1.1/usage/methods/user-tags
|
40
42
|
|
41
|
-
StackOverflow.get_user_tags(#user_id)
|
43
|
+
API::StackOverflow.get_user_tags(#user_id)
|
42
44
|
|
43
45
|
== Get User's Questions
|
44
46
|
|
45
47
|
API documentation can be found at http://api.stackoverflow.com/1.1/usage/methods/questions
|
46
48
|
|
47
|
-
StackOverflow.get_user_questions(#user_id)
|
49
|
+
API::StackOverflow.get_user_questions(#user_id)
|
48
50
|
|
49
51
|
== Get User's Answers
|
50
52
|
|
51
53
|
API documentation can be found at http://api.stackoverflow.com/1.1/usage/methods/answers
|
52
54
|
|
53
|
-
StackOverflow.get_user_answers(#user_id)
|
55
|
+
API::StackOverflow.get_user_answers(#user_id)
|
54
56
|
|
55
57
|
== Get Tags
|
56
58
|
|
57
59
|
API documentation can be found at http://api.stackoverflow.com/1.1/usage/methods/tags
|
58
60
|
|
59
|
-
StackOverflow.get_tags
|
61
|
+
API::StackOverflow.get_tags
|
60
62
|
|
61
63
|
== Get Tags Synonyms
|
62
64
|
|
63
65
|
API documentation can be found at http://api.stackoverflow.com/1.1/usage/methods/tag-synonyms
|
64
66
|
|
65
|
-
StackOverflow.get_tags_synonyms
|
67
|
+
API::StackOverflow.get_tags_synonyms
|
66
68
|
|
67
69
|
== Work in progress
|
68
70
|
|
data/lib/answer.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module API
|
2
|
+
module StackOverflow
|
3
|
+
class Answer
|
4
|
+
attr_accessor :id, :accepted, :comments_url, :question_id, :title
|
5
|
+
attr_accessor :creation_date, :last_activity_date
|
6
|
+
attr_accessor :up_vote_count, :down_vote_count, :view_count, :score, :community_owned
|
7
|
+
|
8
|
+
def initialize(so_answer)
|
9
|
+
@id = so_answer["answer_id"]
|
10
|
+
@title = so_answer["title"]
|
11
|
+
@accepted = so_answer["accepted"]
|
12
|
+
@comments_url = so_answer["answer_comments_url"]
|
13
|
+
@question_id = so_answer["question_id"]
|
14
|
+
@creation_date = Time.at(so_answer["creation_date"]) if so_answer["creation_date"]
|
15
|
+
@last_activity_date = Time.at(so_answer["last_activity_date"]) if so_answer["last_activity_date"]
|
16
|
+
@up_vote_count = so_answer["up_vote_count"]
|
17
|
+
@down_vote_count = so_answer["down_vote_count"]
|
18
|
+
@view_count = so_answer["view_count"]
|
19
|
+
@score = so_answer["score"]
|
20
|
+
@community_owned = so_answer["community_owned"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def vote_count
|
24
|
+
@up_vote_count - @down_vote_count
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/question.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module API
|
2
|
+
module StackOverflow
|
3
|
+
class Question
|
4
|
+
attr_accessor :answer_count, :accepted_answer_id, :favorite_count, :timeline_url
|
5
|
+
attr_accessor :comments_url, :answers_url, :id
|
6
|
+
attr_accessor :creation_date, :last_edit_date, :last_activity_date
|
7
|
+
attr_accessor :up_vote_count, :down_vote_count, :view_count, :score
|
8
|
+
attr_accessor :community_owned, :title
|
9
|
+
|
10
|
+
def initialize(so_question)
|
11
|
+
@id = so_question["question_id"]
|
12
|
+
@answer_count = so_question["answer_count"]
|
13
|
+
@accepted_answer_id = so_question["accepted_answer_id"]
|
14
|
+
@favorite_count = so_question["favorite_count"]
|
15
|
+
@timeline_url = so_question["question_timeline_url"]
|
16
|
+
@comments_url = so_question["question_comments_url"]
|
17
|
+
@answers_url = so_question["question_answers_url"]
|
18
|
+
@creation_date = Time.at(so_question["creation_date"]) if so_question["creation_date"]
|
19
|
+
@last_edit_date = Time.at(so_question["last_edit_date"]) if so_question["last_edit_date"]
|
20
|
+
@last_activity_date = Time.at(so_question["last_activity_date"]) if so_question["last_activity_date"]
|
21
|
+
@up_vote_count = so_question["up_vote_count"]
|
22
|
+
@down_vote_count = so_question["down_vote_count"]
|
23
|
+
@view_count = so_question["view_count"]
|
24
|
+
@score = so_question["score"]
|
25
|
+
@community_owned = so_question["community_owned"]
|
26
|
+
@title = so_question["title"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def vote_count
|
30
|
+
@up_vote_count - @down_vote_count
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/stack_overflow.rb
CHANGED
@@ -1,58 +1,61 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'json'
|
3
|
+
require 'question'
|
4
|
+
require 'answer'
|
5
|
+
|
6
|
+
module API
|
7
|
+
module StackOverflow
|
8
|
+
include HTTParty
|
9
|
+
@@API_KEY = nil
|
10
|
+
@@URL = "http://api.stackoverflow.com/1.1/"
|
11
|
+
|
12
|
+
def self.API_KEY=(value)
|
13
|
+
@@API_KEY = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get_all_users(options={})
|
17
|
+
key = @@API_KEY
|
18
|
+
page = options[:page] || 1
|
19
|
+
pagesize = options[:pagesize] || 30
|
20
|
+
url = URI.parse(@@URL + "users?key=#{key}&page=#{page}&pagesize=#{pagesize}")
|
21
|
+
response = Net::HTTP.get_response url
|
22
|
+
gz = Zlib::GzipReader.new(StringIO.new(response.body))
|
23
|
+
JSON.parse(gz.read)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.get_user(user_id)
|
27
|
+
result = get(@@URL + "users/#{user_id}?key=#{@@API_KEY}")
|
28
|
+
return nil if result["users"].nil?
|
29
|
+
result["users"].first
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_users(user_ids)
|
33
|
+
user_id = user_ids.join(";").to_s
|
34
|
+
result = get(@@URL + "users/#{user_id}?key=#{@@API_KEY}")
|
35
|
+
result["users"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.get_user_questions(user_id)
|
39
|
+
result = get(@@URL + "users/#{user_id}/questions?key=#{@@API_KEY}")
|
40
|
+
result["questions"].map{|q| Question.new(q) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.get_user_answers(user_id)
|
44
|
+
result = get(@@URL + "users/#{user_id}/answers?key=#{@@API_KEY}")
|
45
|
+
result["answers"].map{|a| Answer.new(a) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.get_user_tags(user_id)
|
49
|
+
get(@@URL + "users/#{user_id}/tags?key=#{@@API_KEY}")
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.get_tags
|
53
|
+
get(@@URL + "tags?key=#{@@API_KEY}")
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.get_tags_synonyms
|
57
|
+
get(@@URL + "tags/synonyms?key=#{@@API_KEY}")
|
58
|
+
end
|
3
59
|
|
4
|
-
class StackOverflow
|
5
|
-
include HTTParty
|
6
|
-
@@API_KEY = nil
|
7
|
-
@@URL = "http://api.stackoverflow.com/1.1/"
|
8
|
-
|
9
|
-
def self.API_KEY=(value)
|
10
|
-
@@API_KEY = value
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.get_all_users(options={})
|
14
|
-
key = @@API_KEY
|
15
|
-
page = options[:page] || 1
|
16
|
-
pagesize = options[:pagesize] || 30
|
17
|
-
url = URI.parse(@@URL + "users?key=#{key}&page=#{page}&pagesize=#{pagesize}")
|
18
|
-
response = Net::HTTP.get_response url
|
19
|
-
gz = Zlib::GzipReader.new(StringIO.new(response.body))
|
20
|
-
JSON.parse(gz.read)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.get_user(user_id)
|
24
|
-
result = get(@@URL + "users/#{user_id}?key=#{@@API_KEY}")
|
25
|
-
return nil if result["users"].nil?
|
26
|
-
result["users"].first
|
27
60
|
end
|
28
|
-
|
29
|
-
def self.get_users(user_ids)
|
30
|
-
user_id = user_ids.join(";").to_s
|
31
|
-
result = get(@@URL + "users/#{user_id}?key=#{@@API_KEY}")
|
32
|
-
result["users"]
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.get_user_questions(user_id)
|
36
|
-
result = get(@@URL + "users/#{user_id}/questions?key=#{@@API_KEY}")
|
37
|
-
result["questions"]
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
def self.get_user_answers(user_id)
|
42
|
-
result = get(@@URL + "users/#{user_id}/answers?key=#{@@API_KEY}")
|
43
|
-
result["answers"]
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.get_user_tags(user_id)
|
47
|
-
get(@@URL + "users/#{user_id}/tags?key=#{@@API_KEY}")
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.get_tags
|
51
|
-
get(@@URL + "tags?key=#{@@API_KEY}")
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.get_tags_synonyms
|
55
|
-
get(@@URL + "tags/synonyms?key=#{@@API_KEY}")
|
56
|
-
end
|
57
|
-
|
58
61
|
end
|
data/spec/stack_overflow_spec.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe StackOverflow do
|
3
|
+
describe API::StackOverflow do
|
4
4
|
before(:each) do
|
5
|
-
StackOverflow.API_KEY = ENV["SO_API_KEY"]
|
5
|
+
API::StackOverflow.API_KEY = ENV["SO_API_KEY"]
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "get all users" do
|
9
9
|
context "all users" do
|
10
10
|
before(:each) do
|
11
|
-
@result = StackOverflow.get_all_users
|
11
|
+
@result = API::StackOverflow.get_all_users
|
12
12
|
end
|
13
13
|
it { @result.should_not be_nil }
|
14
14
|
end
|
15
15
|
|
16
16
|
context "second page" do
|
17
17
|
before(:each) do
|
18
|
-
@result = StackOverflow.get_all_users(:page => 2)
|
18
|
+
@result = API::StackOverflow.get_all_users(:page => 2)
|
19
19
|
end
|
20
20
|
it { @result.should_not be_nil }
|
21
21
|
end
|
22
22
|
|
23
23
|
context "50 per page" do
|
24
24
|
before(:each) do
|
25
|
-
@result = StackOverflow.get_all_users(:pagesize => 50)
|
25
|
+
@result = API::StackOverflow.get_all_users(:pagesize => 50)
|
26
26
|
end
|
27
27
|
it { @result["users"].count.should == 50 }
|
28
28
|
end
|
@@ -31,7 +31,7 @@ describe StackOverflow do
|
|
31
31
|
describe "get user" do
|
32
32
|
context "60336" do
|
33
33
|
before(:each) do
|
34
|
-
@user = StackOverflow.get_user(60336)
|
34
|
+
@user = API::StackOverflow.get_user(60336)
|
35
35
|
end
|
36
36
|
it { @user.should_not be_nil }
|
37
37
|
it { @user["display_name"].should == "JB."}
|
@@ -39,7 +39,7 @@ describe StackOverflow do
|
|
39
39
|
|
40
40
|
context "Jared314" do
|
41
41
|
before(:each) do
|
42
|
-
@user = StackOverflow.get_user("Jared314")
|
42
|
+
@user = API::StackOverflow.get_user("Jared314")
|
43
43
|
end
|
44
44
|
it { @user.should be_nil }
|
45
45
|
end
|
@@ -47,7 +47,7 @@ describe StackOverflow do
|
|
47
47
|
|
48
48
|
describe "get users" do
|
49
49
|
before(:each) do
|
50
|
-
@users = StackOverflow.get_users([60336, 3381])
|
50
|
+
@users = API::StackOverflow.get_users([60336, 3381])
|
51
51
|
end
|
52
52
|
it { @users.should_not be_nil }
|
53
53
|
it { @users.select{|u| u["display_name"] == "JB"}.should_not be_nil }
|
@@ -56,7 +56,7 @@ describe StackOverflow do
|
|
56
56
|
|
57
57
|
describe "get user tags" do
|
58
58
|
before(:each) do
|
59
|
-
@tags = StackOverflow.get_user_tags(60336)
|
59
|
+
@tags = API::StackOverflow.get_user_tags(60336)
|
60
60
|
end
|
61
61
|
it { @tags.should_not be_nil }
|
62
62
|
it { @tags["tags"].count.should > 0 }
|
@@ -64,7 +64,7 @@ describe StackOverflow do
|
|
64
64
|
|
65
65
|
describe "get tags" do
|
66
66
|
before(:each) do
|
67
|
-
@tags = StackOverflow.get_tags
|
67
|
+
@tags = API::StackOverflow.get_tags
|
68
68
|
end
|
69
69
|
it { @tags.should_not be_nil }
|
70
70
|
it { @tags["tags"].count.should > 0 }
|
@@ -72,26 +72,12 @@ describe StackOverflow do
|
|
72
72
|
|
73
73
|
describe "get tags synonyms" do
|
74
74
|
before(:each) do
|
75
|
-
@tags_synonyms = StackOverflow.get_tags_synonyms
|
75
|
+
@tags_synonyms = API::StackOverflow.get_tags_synonyms
|
76
76
|
end
|
77
77
|
it { @tags_synonyms.should_not be_nil }
|
78
78
|
it { @tags_synonyms["tag_synonyms"].count.should > 0 }
|
79
79
|
end
|
80
80
|
|
81
|
-
describe "get users answers" do
|
82
|
-
before(:each) do
|
83
|
-
@answers = StackOverflow.get_user_answers(363881)
|
84
|
-
end
|
85
|
-
it { @answers.should_not be_nil }
|
86
|
-
it { @answers.count.should > 0 }
|
87
|
-
end
|
88
81
|
|
89
|
-
describe "get users questions" do
|
90
|
-
before(:each) do
|
91
|
-
@questions = StackOverflow.get_user_questions(363881)
|
92
|
-
end
|
93
|
-
it { @questions.should_not be_nil }
|
94
|
-
it { @questions.count.should > 0 }
|
95
|
-
end
|
96
82
|
|
97
83
|
end
|
data/stack_overflow.gemspec
CHANGED
@@ -4,7 +4,7 @@ require "stack_overflow/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "stack_overflow"
|
7
|
-
s.version = StackOverflow::VERSION
|
7
|
+
s.version = API::StackOverflow::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Jonathan Birkholz"]
|
10
10
|
s.email = ["rookieone@gmail.com"]
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: stack_overflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.9
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jonathan Birkholz
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2012-01-15 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -60,9 +60,12 @@ files:
|
|
60
60
|
- Gemfile.lock
|
61
61
|
- README.rdoc
|
62
62
|
- Rakefile
|
63
|
-
- lib
|
63
|
+
- lib/answer.rb
|
64
|
+
- lib/question.rb
|
64
65
|
- lib/stack_overflow.rb
|
65
66
|
- lib/stack_overflow/version.rb
|
67
|
+
- spec/get_answers_spec.rb
|
68
|
+
- spec/get_questions_spec.rb
|
66
69
|
- spec/spec_helper.rb
|
67
70
|
- spec/stack_overflow_spec.rb
|
68
71
|
- stack_overflow.gemspec
|
@@ -94,5 +97,7 @@ signing_key:
|
|
94
97
|
specification_version: 3
|
95
98
|
summary: HTTParty over the StackOverflow API
|
96
99
|
test_files:
|
100
|
+
- spec/get_answers_spec.rb
|
101
|
+
- spec/get_questions_spec.rb
|
97
102
|
- spec/spec_helper.rb
|
98
103
|
- spec/stack_overflow_spec.rb
|