coder_wally 0.0.4 → 0.0.5
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 +4 -4
- data/README.md +6 -1
- data/lib/coder_wally/badge.rb +1 -0
- data/lib/coder_wally/client.rb +16 -5
- data/lib/coder_wally/user.rb +16 -0
- data/lib/coder_wally/version.rb +2 -2
- data/lib/coder_wally.rb +1 -0
- data/test/coder_wally_test.rb +19 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de7d714b9060a7341d0c9d2d296952014aae00f0
|
4
|
+
data.tar.gz: 2a4f6c6966cf91dd7c6102778cadf674d75d93e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8343ae8cbf488bfa7a5657ea6fe78752912c1dd1fead2b3ffbad1b156a9694f1addda68cf78307b83cbc33309a277e999fee823a9b3f33affe19f58becf03384
|
7
|
+
data.tar.gz: dfad37a1cd31aa8545307515e12b5741a917f6176973c73d00a575d3a8c1179eeaab0ec14709fe9db9adb0c73633666da2c72d5d0d9b9303296ee66b5b6b6309
|
data/README.md
CHANGED
@@ -33,11 +33,16 @@ using:
|
|
33
33
|
|
34
34
|
ruby -Ilib bin/coder_wally <username>
|
35
35
|
|
36
|
-
In
|
36
|
+
In order to get a user's badges, you do this:
|
37
37
|
|
38
38
|
client = CoderWally::Client.new
|
39
39
|
client.get_badges_for <username>
|
40
40
|
|
41
|
+
In order to get a user's details, you do this:
|
42
|
+
|
43
|
+
client = CoderWally::Client.new
|
44
|
+
client.get_details_for <username>
|
45
|
+
|
41
46
|
## Contributing
|
42
47
|
|
43
48
|
1. Fork it ( https://github.com/gregstewart/coder_wally/fork )
|
data/lib/coder_wally/badge.rb
CHANGED
data/lib/coder_wally/client.rb
CHANGED
@@ -2,13 +2,16 @@ require "open-uri"
|
|
2
2
|
require "json"
|
3
3
|
|
4
4
|
module CoderWally
|
5
|
+
# Client to access the API
|
5
6
|
class Client
|
6
|
-
# The URL of API we'll use.
|
7
|
+
# The URL of the API we'll use.
|
7
8
|
def api_url
|
8
9
|
"https://coderwall.com/%s.json"
|
9
10
|
end
|
10
11
|
# Build user URI from username and apii url
|
11
12
|
def uri_for_user username
|
13
|
+
raise(ArgumentError, "Plesae provide a username") if username.empty?
|
14
|
+
|
12
15
|
URI.parse(api_url % username)
|
13
16
|
end
|
14
17
|
# Dispatch the request
|
@@ -20,19 +23,27 @@ module CoderWally
|
|
20
23
|
raise ServerError, "Server error" if error.io.status[0] == "500"
|
21
24
|
end
|
22
25
|
end
|
23
|
-
# Get
|
26
|
+
# Get badges for given user and return has collection of `Badge`s
|
24
27
|
def get_badges_for username
|
25
|
-
raise(ArgumentError, "Plesae provide a username") if username.empty?
|
26
|
-
|
27
28
|
json_response = JSON.load(send_request(uri_for_user(username)))
|
28
29
|
|
29
30
|
json_response["badges"].map { |badge| Badge.new(badge) }
|
30
31
|
end
|
32
|
+
|
33
|
+
# Get user details for given user and return a `User` object
|
34
|
+
def get_details_for username
|
35
|
+
json_response = JSON.load(send_request(uri_for_user(username)))
|
36
|
+
|
37
|
+
User.new(json_response["name"], json_response["username"],
|
38
|
+
json_response["location"], json_response["team"])
|
39
|
+
end
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
43
|
+
# Handles user not found exception
|
34
44
|
class UserNotFoundError < StandardError
|
35
45
|
end
|
36
46
|
|
47
|
+
# Handles server exception
|
37
48
|
class ServerError < StandardError
|
38
|
-
end
|
49
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# All code in the gem is namespaced under this module.
|
2
|
+
module CoderWally
|
3
|
+
# Stores user properties
|
4
|
+
class User
|
5
|
+
# Object properties
|
6
|
+
attr_reader :name, :username, :location, :team
|
7
|
+
|
8
|
+
# Initialise object with a hash of values
|
9
|
+
def initialize(name, username, location, team)
|
10
|
+
@name = name
|
11
|
+
@username = username
|
12
|
+
@location = location
|
13
|
+
@team = team
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/coder_wally/version.rb
CHANGED
data/lib/coder_wally.rb
CHANGED
data/test/coder_wally_test.rb
CHANGED
@@ -70,4 +70,23 @@ describe "Coder Wally" do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
describe "user details" do
|
75
|
+
before do
|
76
|
+
success_response = open(File.expand_path(File.dirname(__FILE__) + "/./fixtures/200.json")).read
|
77
|
+
stub_request(:get, "https://coderwall.com/me.json").
|
78
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
79
|
+
to_return(:status => 200, :body => success_response, :headers => {})
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns a user" do
|
83
|
+
user = @client.get_details_for('me')
|
84
|
+
|
85
|
+
user.name.must_equal "Greg Stewart"
|
86
|
+
user.username.must_equal "gregstewart"
|
87
|
+
user.location.must_equal "London, UK"
|
88
|
+
user.team.must_equal nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
73
92
|
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.5
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/coder_wally.rb
|
87
87
|
- lib/coder_wally/badge.rb
|
88
88
|
- lib/coder_wally/client.rb
|
89
|
+
- lib/coder_wally/user.rb
|
89
90
|
- lib/coder_wally/version.rb
|
90
91
|
- test/coder_wally_test.rb
|
91
92
|
- test/fixtures/200.json
|