coder_wally 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23d832d7527f374d52bccca30faa69afa004004e
4
- data.tar.gz: d24fb436ad305fc990a02efaa0dc90ffae4d6e35
3
+ metadata.gz: b7fa76ff7949963a19e843e7b0f2dfb0d4f4b94d
4
+ data.tar.gz: 52c08302bc1a2ef3d64f626bc514937847d52131
5
5
  SHA512:
6
- metadata.gz: 3cd99a77064e7c69c6025b6d55a5df2e27617384d07af0baab9d31cdf1e11dc85c4ea11064f8a4b62adcdde82aabf87715638c8149cb7ca5d545e8a919189d60
7
- data.tar.gz: 23a0b5e971adaa61893ae325e049edc02f8a5aa6687f2bc308061e8d73a7db42c341cdcccbd24369cf20cfa8aa6576a6316a661f9ab7518dad00633dbfd61bb6
6
+ metadata.gz: 0c9e55503774b2c46dbc3fecdaacc14e3da86605f47b2c717363404d491936fe1aba186d10f6be9a71bbae05bc379d30bed88282fbd29dfa8ddef1b1e35117ff
7
+ data.tar.gz: 6344b2c6ba97492b82b61bc4a3199ec735ed1675d5411fb060722c6e1b41083bf80b442bd734e4df73d01f26e73a3021a3686d3582ad14badee2880b3cfd33d8
data/README.md CHANGED
@@ -20,7 +20,9 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ For now you can invoke it using (remember to replace <username> with you a valid username):
24
+
25
+ ruby -Ilib bin/coder_wally <username>
24
26
 
25
27
  ## Contributing
26
28
 
data/bin/coder_wally CHANGED
@@ -2,4 +2,5 @@
2
2
 
3
3
  require 'coder_wally'
4
4
 
5
- puts CoderWally::Url
5
+ puts CoderWally.get_badges_for ARGV[0]
6
+
@@ -1,4 +1,4 @@
1
1
  module CoderWally
2
2
  # The current version of HowIStart.
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
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
- response = JSON.load(open(url))
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
@@ -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
- # before do
42
- # not_found_response = open(File.expand_path(File.dirname(__FILE__) + "/./fixtures/404.json")).read
43
- # stub_request(:get, "https://coderwall.com/me.json").
44
- # with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
45
- # to_return(:status => 404, :body => not_found_response, :headers => {})
46
- # end
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.2
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-23 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler