coder_wally 0.0.5 → 0.0.6
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/.ruby-version +1 -0
- data/README.md +5 -0
- data/bin/coder_wally +2 -2
- data/lib/coder_wally.rb +1 -0
- data/lib/coder_wally/client.rb +29 -13
- data/lib/coder_wally/coder_wall.rb +15 -0
- data/lib/coder_wally/version.rb +1 -1
- data/test/coder_wally_test.rb +94 -70
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf939f86aad4d6f1ce5aa03e17184d795aaa8bb
|
4
|
+
data.tar.gz: f75e93d278d3510d99a28fc075f5bb55ed256738
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c309c97c0c4040b07d37f8077c86f714f8c590f6a1d734fc9ba1fcc82b55bad408de96eae1960fc234423d2da1a30718a2734056b5ab0001a70c42ae6919b5c
|
7
|
+
data.tar.gz: 339719bdaa06eb7924e3137b1b8f7ca2d6a469bb01203d8d49954bffb051158ce55b49d5a43c0556f24c81f0ddbd036ce105667a3915fe4be270a9ded057a26a
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.5
|
data/README.md
CHANGED
@@ -43,6 +43,11 @@ In order to get a user's details, you do this:
|
|
43
43
|
client = CoderWally::Client.new
|
44
44
|
client.get_details_for <username>
|
45
45
|
|
46
|
+
In order to get everything (for now user and badges), you do this:
|
47
|
+
|
48
|
+
client = CoderWally::Client.new
|
49
|
+
client.get_everything_for <username>
|
50
|
+
|
46
51
|
## Contributing
|
47
52
|
|
48
53
|
1. Fork it ( https://github.com/gregstewart/coder_wally/fork )
|
data/bin/coder_wally
CHANGED
data/lib/coder_wally.rb
CHANGED
data/lib/coder_wally/client.rb
CHANGED
@@ -1,41 +1,57 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
3
|
|
4
4
|
module CoderWally
|
5
5
|
# Client to access the API
|
6
6
|
class Client
|
7
7
|
# The URL of the API we'll use.
|
8
8
|
def api_url
|
9
|
-
|
9
|
+
'https://coderwall.com/%s.json'
|
10
10
|
end
|
11
|
+
|
11
12
|
# Build user URI from username and apii url
|
12
13
|
def uri_for_user username
|
13
|
-
raise(ArgumentError,
|
14
|
+
raise(ArgumentError, 'Please provide a username') if username.empty?
|
14
15
|
|
15
16
|
URI.parse(api_url % username)
|
16
17
|
end
|
18
|
+
|
17
19
|
# Dispatch the request
|
18
20
|
def send_request url
|
19
21
|
begin
|
20
22
|
open(url)
|
21
23
|
rescue OpenURI::HTTPError => error
|
22
|
-
raise UserNotFoundError,
|
23
|
-
raise ServerError,
|
24
|
+
raise UserNotFoundError, 'User not found' if error.io.status[0] == '404'
|
25
|
+
raise ServerError, 'Server error' if error.io.status[0] == '500'
|
24
26
|
end
|
25
27
|
end
|
28
|
+
|
26
29
|
# Get badges for given user and return has collection of `Badge`s
|
27
30
|
def get_badges_for username
|
28
|
-
|
29
|
-
|
30
|
-
json_response["badges"].map { |badge| Badge.new(badge) }
|
31
|
+
coder_wall = build_coder_wall(username)
|
32
|
+
coder_wall.badges
|
31
33
|
end
|
32
34
|
|
33
35
|
# Get user details for given user and return a `User` object
|
34
36
|
def get_details_for username
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
coder_wall = build_coder_wall(username)
|
38
|
+
coder_wall.user
|
39
|
+
end
|
40
|
+
|
41
|
+
# Get all the information available for a given user, returns a `CoderWall` object
|
42
|
+
def get_everything_for username
|
43
|
+
build_coder_wall(username)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Builds a CoderWall object
|
47
|
+
def build_coder_wall(username)
|
48
|
+
json_response = JSON.load(send_request(uri_for_user(username)))
|
49
|
+
|
50
|
+
badges = json_response['badges'].map { |badge| Badge.new(badge) }
|
51
|
+
user = User.new(json_response['name'], json_response['username'],
|
52
|
+
json_response['location'], json_response['team'])
|
53
|
+
|
54
|
+
CoderWall.new badges, user
|
39
55
|
end
|
40
56
|
end
|
41
57
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# All code in the gem is namespaced under this module.
|
2
|
+
module CoderWally
|
3
|
+
# Stores all CoderWall attributes
|
4
|
+
class CoderWall
|
5
|
+
# :badges is the collection of user badges
|
6
|
+
# :user is the `User` object
|
7
|
+
attr_reader :badges, :user
|
8
|
+
|
9
|
+
# Instantiate the class with data
|
10
|
+
def initialize(badges, user)
|
11
|
+
@badges = badges
|
12
|
+
@user = user
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/coder_wally/version.rb
CHANGED
data/test/coder_wally_test.rb
CHANGED
@@ -5,87 +5,111 @@ describe "Coder Wally" do
|
|
5
5
|
before do
|
6
6
|
@client = CoderWally::Client.new
|
7
7
|
end
|
8
|
-
|
9
|
-
it
|
10
|
-
|
8
|
+
|
9
|
+
it 'has a default api url' do
|
10
|
+
'https://coderwall.com/%s.json'.must_equal @client.api_url
|
11
11
|
end
|
12
|
-
|
13
|
-
describe
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns a hash of badges" do
|
23
|
-
badges = @client.get_badges_for('me')
|
24
|
-
|
25
|
-
badges.count.must_equal 11
|
26
|
-
badges.first.name.must_equal "Lab"
|
27
|
-
badges.first.badge.must_equal "https://d3levm2kxut31z.cloudfront.net/assets/badges/labrador-1eb0fc532826e5a7c5487855f9880627.png"
|
28
|
-
badges.first.description.must_equal "Have at least one original repo where C# is the dominant language"
|
29
|
-
badges.first.created.must_equal "2014-07-10T23:36:47Z"
|
30
|
-
end
|
12
|
+
|
13
|
+
describe 'user badges' do
|
14
|
+
describe 'valid user' do
|
15
|
+
before do
|
16
|
+
success_response = open(File.expand_path(File.dirname(__FILE__) + '/./fixtures/200.json')).read
|
17
|
+
stub_request(:get, 'https://coderwall.com/me.json').
|
18
|
+
with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Ruby'}).
|
19
|
+
to_return(:status => 200, :body => success_response, :headers => {})
|
31
20
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
err.message.must_match /Plesae provide a username/
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "not found" do
|
45
|
-
before do
|
46
|
-
not_found_response = open(File.expand_path(File.dirname(__FILE__) + "/./fixtures/404.json")).read
|
47
|
-
stub_request(:get, "https://coderwall.com/me.json").
|
48
|
-
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
49
|
-
to_return(:status => 404, :body => not_found_response, :headers => {})
|
50
|
-
end
|
51
|
-
|
52
|
-
it "throws a UserNotFoundError when the user is not found" do
|
53
|
-
err = ->{ @client.get_badges_for('me')}.must_raise UserNotFoundError
|
54
|
-
err.message.must_match /User not found/
|
55
|
-
end
|
56
|
-
end
|
21
|
+
|
22
|
+
it 'returns a hash of badges' do
|
23
|
+
badges = @client.get_badges_for('me')
|
24
|
+
|
25
|
+
badges.count.must_equal 11
|
26
|
+
badges.first.name.must_equal 'Lab'
|
27
|
+
badges.first.badge.must_equal 'https://d3levm2kxut31z.cloudfront.net/assets/badges/labrador-1eb0fc532826e5a7c5487855f9880627.png'
|
28
|
+
badges.first.description.must_equal 'Have at least one original repo where C# is the dominant language'
|
29
|
+
badges.first.created.must_equal '2014-07-10T23:36:47Z'
|
57
30
|
end
|
58
|
-
|
59
|
-
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'invalid user' do
|
34
|
+
it 'throws an exception when no user is passed in' do
|
35
|
+
err = -> { @client.get_badges_for }.must_raise ArgumentError
|
36
|
+
err.message.must_match /wrong number/
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'throws an exception when empty string is passed in' do
|
40
|
+
err = -> { @client.get_badges_for '' }.must_raise ArgumentError
|
41
|
+
err.message.must_match /Please provide a username/
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'not found' do
|
60
45
|
before do
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
46
|
+
not_found_response = open(File.expand_path(File.dirname(__FILE__) + '/./fixtures/404.json')).read
|
47
|
+
stub_request(:get, 'https://coderwall.com/me.json').
|
48
|
+
with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Ruby'}).
|
49
|
+
to_return(:status => 404, :body => not_found_response, :headers => {})
|
65
50
|
end
|
66
|
-
|
67
|
-
it
|
68
|
-
err = ->{ @client.get_badges_for('me')}.must_raise
|
69
|
-
err.message.must_match /
|
51
|
+
|
52
|
+
it 'throws a UserNotFoundError when the user is not found' do
|
53
|
+
err = -> { @client.get_badges_for('me') }.must_raise UserNotFoundError
|
54
|
+
err.message.must_match /User not found/
|
70
55
|
end
|
71
56
|
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'service throws an error' do
|
60
|
+
before do
|
61
|
+
server_error = open(File.expand_path(File.dirname(__FILE__) + '/./fixtures/empty.json')).read
|
62
|
+
stub_request(:get, 'https://coderwall.com/me.json').
|
63
|
+
with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Ruby'}).
|
64
|
+
to_return(:status => 500, :body => server_error, :headers => {})
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'throws a ServerError when the user is not found' do
|
68
|
+
err = -> { @client.get_badges_for('me') }.must_raise ServerError
|
69
|
+
err.message.must_match /Server error/
|
70
|
+
end
|
71
|
+
end
|
72
72
|
end
|
73
|
-
|
74
|
-
describe
|
73
|
+
|
74
|
+
describe 'user details' do
|
75
75
|
before do
|
76
|
-
success_response = open(File.expand_path(File.dirname(__FILE__) +
|
77
|
-
stub_request(:get,
|
78
|
-
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
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
79
|
to_return(:status => 200, :body => success_response, :headers => {})
|
80
80
|
end
|
81
|
-
|
82
|
-
it
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
+
|
92
|
+
describe 'everything' do
|
93
|
+
before do
|
94
|
+
success_response = open(File.expand_path(File.dirname(__FILE__) + '/./fixtures/200.json')).read
|
95
|
+
stub_request(:get, 'https://coderwall.com/me.json').
|
96
|
+
with(:headers => {'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Ruby'}).
|
97
|
+
to_return(:status => 200, :body => success_response, :headers => {})
|
98
|
+
|
99
|
+
@coder_wall = @client.get_everything_for('me')
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'returns a coderwall object' do
|
103
|
+
@coder_wall.must_be_instance_of CoderWally::CoderWall
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'has a user object' do
|
107
|
+
@coder_wall.user.must_be_instance_of CoderWally::User
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'has a collection of badges' do
|
111
|
+
@coder_wall.badges.count.must_equal 11
|
112
|
+
@coder_wall.badges.first.must_be_instance_of CoderWally::Badge
|
89
113
|
end
|
90
114
|
end
|
91
115
|
|
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.6
|
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-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- ".coveralls.yml"
|
78
78
|
- ".gitignore"
|
79
|
+
- ".ruby-version"
|
79
80
|
- ".travis.yml"
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|
@@ -86,6 +87,7 @@ files:
|
|
86
87
|
- lib/coder_wally.rb
|
87
88
|
- lib/coder_wally/badge.rb
|
88
89
|
- lib/coder_wally/client.rb
|
90
|
+
- lib/coder_wally/coder_wall.rb
|
89
91
|
- lib/coder_wally/user.rb
|
90
92
|
- lib/coder_wally/version.rb
|
91
93
|
- test/coder_wally_test.rb
|