stack_overflow 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -2
- data/lib/stack_overflow/version.rb +1 -1
- data/lib/stack_overflow.rb +8 -2
- data/spec/stack_overflow_spec.rb +14 -4
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -4,6 +4,8 @@ This is a simple gem that utilizes HTTParty and the StackOverflow API.
|
|
4
4
|
|
5
5
|
gem install stack_overflow
|
6
6
|
|
7
|
+
The StackOverflow API help can be found at http://api.stackoverflow.com/1.0/help
|
8
|
+
|
7
9
|
== Set API Key
|
8
10
|
|
9
11
|
Be sure to set the API Key.
|
@@ -12,9 +14,15 @@ Be sure to set the API Key.
|
|
12
14
|
|
13
15
|
You can get your key from StackOverflow by going here : http://stackapps.com/apps/register
|
14
16
|
|
15
|
-
== Get
|
17
|
+
== Get User(s)
|
18
|
+
|
19
|
+
API documentation can be found at http://api.stackoverflow.com/1.0/help/method?method=users/{id}
|
20
|
+
|
21
|
+
StackOverflow.get_user(#user_id)
|
22
|
+
|
23
|
+
You can also get a group of users by using
|
16
24
|
|
17
|
-
StackOverflow.
|
25
|
+
StackOverflow.get_users([#user_id1, #user_id2, etc])
|
18
26
|
|
19
27
|
== Work in progress
|
20
28
|
|
data/lib/stack_overflow.rb
CHANGED
@@ -8,8 +8,14 @@ class StackOverflow
|
|
8
8
|
@@API_KEY = value
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.
|
12
|
-
get("http://stackoverflow.com/users
|
11
|
+
def self.get_user(user_id)
|
12
|
+
result = get("http://api.stackoverflow.com/1.0/users/#{user_id}?key=#{@@API_KEY}")
|
13
|
+
result["users"].first
|
13
14
|
end
|
14
15
|
|
16
|
+
def self.get_users(user_ids)
|
17
|
+
user_id = user_ids.join(";").to_s
|
18
|
+
result = get("http://api.stackoverflow.com/1.0/users/#{user_id}?key=#{@@API_KEY}")
|
19
|
+
result["users"]
|
20
|
+
end
|
15
21
|
end
|
data/spec/stack_overflow_spec.rb
CHANGED
@@ -5,12 +5,22 @@ describe StackOverflow do
|
|
5
5
|
StackOverflow.API_KEY = ENV["SO_API_KEY"]
|
6
6
|
end
|
7
7
|
|
8
|
-
describe "get
|
8
|
+
describe "get user" do
|
9
9
|
before(:each) do
|
10
|
-
@
|
10
|
+
@user = StackOverflow.get_user(60336)
|
11
11
|
end
|
12
|
-
it { @
|
13
|
-
it { @
|
12
|
+
it { @user.should_not be_nil }
|
13
|
+
it { @user["display_name"].should == "JB"}
|
14
14
|
end
|
15
15
|
|
16
|
+
describe "get user2" do
|
17
|
+
before(:each) do
|
18
|
+
@users = StackOverflow.get_users([60336, 3381])
|
19
|
+
end
|
20
|
+
it { @users.should_not be_nil }
|
21
|
+
it { @users.select{|u| u["display_name"] == "JB"}.should_not be_nil }
|
22
|
+
it { @users.select{|u| u["display_name"] == "Ben Scheirman"}.should_not be_nil }
|
23
|
+
end
|
24
|
+
|
25
|
+
|
16
26
|
end
|