coder_wally 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/bin/coder_wally +2 -1
- data/lib/coder_wally/version.rb +1 -1
- data/lib/coder_wally.rb +17 -2
- data/test/coder_wally_test.rb +28 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7fa76ff7949963a19e843e7b0f2dfb0d4f4b94d
|
4
|
+
data.tar.gz: 52c08302bc1a2ef3d64f626bc514937847d52131
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c9e55503774b2c46dbc3fecdaacc14e3da86605f47b2c717363404d491936fe1aba186d10f6be9a71bbae05bc379d30bed88282fbd29dfa8ddef1b1e35117ff
|
7
|
+
data.tar.gz: 6344b2c6ba97492b82b61bc4a3199ec735ed1675d5411fb060722c6e1b41083bf80b442bd734e4df73d01f26e73a3021a3686d3582ad14badee2880b3cfd33d8
|
data/README.md
CHANGED
data/bin/coder_wally
CHANGED
data/lib/coder_wally/version.rb
CHANGED
data/lib/coder_wally.rb
CHANGED
@@ -22,8 +22,23 @@ module CoderWally
|
|
22
22
|
def CoderWally.get_badges_for username
|
23
23
|
raise(ArgumentError, "Plesae provide a username") if username.empty?
|
24
24
|
url = URI.parse(Url % username)
|
25
|
-
|
26
|
-
|
25
|
+
|
26
|
+
begin
|
27
|
+
request = open(url)
|
28
|
+
rescue OpenURI::HTTPError => error
|
29
|
+
raise UserNotFoundError, "User not found" if error.io.status[0] == "404"
|
30
|
+
raise ServerError, "Server error" if error.io.status[0] == "500"
|
31
|
+
end
|
32
|
+
|
33
|
+
response = JSON.load(request)
|
34
|
+
|
27
35
|
response["badges"].map { |badge| Badge.new(badge) }
|
36
|
+
#
|
28
37
|
end
|
29
38
|
end
|
39
|
+
|
40
|
+
class UserNotFoundError < StandardError
|
41
|
+
end
|
42
|
+
|
43
|
+
class ServerError < StandardError
|
44
|
+
end
|
data/test/coder_wally_test.rb
CHANGED
@@ -27,6 +27,7 @@ describe "Coder Wally" do
|
|
27
27
|
badges.first.created.must_equal "2014-07-10T23:36:47Z"
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
30
31
|
describe "invalid user" do
|
31
32
|
it "throws an exception when no user is passed in" do
|
32
33
|
err = ->{ CoderWally.get_badges_for }.must_raise ArgumentError
|
@@ -38,12 +39,33 @@ describe "Coder Wally" do
|
|
38
39
|
err.message.must_match /Plesae provide a username/
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
describe "not found" do
|
43
|
+
before do
|
44
|
+
not_found_response = open(File.expand_path(File.dirname(__FILE__) + "/./fixtures/404.json")).read
|
45
|
+
stub_request(:get, "https://coderwall.com/me.json").
|
46
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
47
|
+
to_return(:status => 404, :body => not_found_response, :headers => {})
|
48
|
+
end
|
49
|
+
|
50
|
+
it "throws a UserNotFoundError when the user is not found" do
|
51
|
+
err = ->{ CoderWally.get_badges_for('me')}.must_raise UserNotFoundError
|
52
|
+
err.message.must_match /User not found/
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "service throws an error" do
|
58
|
+
before do
|
59
|
+
server_error = open(File.expand_path(File.dirname(__FILE__) + "/./fixtures/empty.json")).read
|
60
|
+
stub_request(:get, "https://coderwall.com/me.json").
|
61
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
62
|
+
to_return(:status => 500, :body => server_error, :headers => {})
|
63
|
+
end
|
64
|
+
|
65
|
+
it "throws a ServerError when the user is not found" do
|
66
|
+
err = ->{ CoderWally.get_badges_for('me')}.must_raise ServerError
|
67
|
+
err.message.must_match /Server error/
|
68
|
+
end
|
47
69
|
end
|
48
70
|
end
|
49
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coder_wally
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|