coder_wally 0.1.0 → 0.1.1
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/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +11 -0
- data/.ruby-version +1 -1
- data/README.md +2 -1
- data/bin/coder_wally +1 -1
- data/circle.yml +6 -0
- data/coder_wally.gemspec +1 -0
- data/lib/coder_wally/account.rb +3 -3
- data/lib/coder_wally/api.rb +32 -32
- data/lib/coder_wally/badge.rb +13 -13
- data/lib/coder_wally/builder.rb +1 -1
- data/lib/coder_wally/client.rb +28 -27
- data/lib/coder_wally/coder_wall.rb +13 -13
- data/lib/coder_wally/user.rb +14 -14
- data/lib/coder_wally/version.rb +2 -1
- data/lib/coder_wally.rb +0 -1
- data/test/account_test.rb +2 -2
- data/test/coder_wally_test.rb +47 -31
- data/test/test_helper.rb +1 -1
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09158bbcb126bc9fbb9fcfd4eaff98d646017548
|
4
|
+
data.tar.gz: 7dc0e8d397038d0f315263dcd530a7ace464775d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0b7f1da6275413792bd7d23d20d430c803d191ce6643b0d00eba7c7b03ba72e06bef77a546bf06be64be0582591f1209c0eae552bd344c348cfe48eb4244e22
|
7
|
+
data.tar.gz: cf18c3a4a70e483dabb092eca36a8f5ba7005fb633db642ffd139d81c5579f5fa662044a7225d27b484cc5c98962d8bb7f91fa9442bb19390f70ce65abe4c7c0
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-02-06 22:59:06 +0000 using RuboCop version 0.29.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 2
|
9
|
+
# Configuration parameters: AllowURI, URISchemes.
|
10
|
+
Metrics/LineLength:
|
11
|
+
Max: 111
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.1.
|
1
|
+
ruby-2.1.3
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# CoderWally
|
2
2
|
|
3
|
+
[](https://circleci.com/gh/gregstewart/coder_wally)
|
4
|
+
|
3
5
|
[](http://badge.fury.io/rb/coder_wally)
|
4
|
-
[](https://travis-ci.org/gregstewart/coder_wally)
|
5
6
|
[](https://coveralls.io/r/gregstewart/coder_wally)
|
6
7
|
[](https://codeclimate.com/github/gregstewart/coder_wally)
|
7
8
|
[](https://gemnasium.com/gregstewart/coder_wally)
|
data/bin/coder_wally
CHANGED
data/circle.yml
ADDED
data/coder_wally.gemspec
CHANGED
data/lib/coder_wally/account.rb
CHANGED
@@ -5,9 +5,9 @@ module CoderWally
|
|
5
5
|
# Dynamically create account properties
|
6
6
|
def initialize(collection_of_accounts)
|
7
7
|
collection_of_accounts.each do |account, value|
|
8
|
-
singleton_class.class_eval
|
9
|
-
|
8
|
+
singleton_class.class_eval { attr_accessor "#{account}" }
|
9
|
+
instance_variable_set("@#{account}", value)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
data/lib/coder_wally/api.rb
CHANGED
@@ -11,50 +11,50 @@ module CoderWally
|
|
11
11
|
|
12
12
|
begin
|
13
13
|
JSON.parse(json.read)
|
14
|
-
rescue JSON::ParserError
|
14
|
+
rescue JSON::ParserError
|
15
15
|
raise InvalidJson, 'Received invalid json in response'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
|
-
# Dispatch the request
|
21
|
-
def send_request(url)
|
22
|
-
begin
|
23
|
-
open(url)
|
24
|
-
rescue OpenURI::HTTPError => error
|
25
|
-
handle_user_not_found_error(error)
|
26
|
-
handle_server_error(error)
|
27
|
-
end
|
28
|
-
end
|
29
20
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
21
|
+
# Dispatch the request
|
22
|
+
def send_request(url)
|
23
|
+
open(url)
|
24
|
+
rescue OpenURI::HTTPError => error
|
25
|
+
handle_user_not_found_error(error)
|
26
|
+
handle_server_error(error)
|
27
|
+
end
|
34
28
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
# Parse status code from error
|
30
|
+
def get_status_code(error)
|
31
|
+
error.io.status[0]
|
32
|
+
end
|
39
33
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
# Raise server error
|
35
|
+
def handle_server_error(error)
|
36
|
+
fail ServerError, 'Server error' if get_status_code(error) == '500'
|
37
|
+
end
|
44
38
|
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
# Raise user not found error
|
40
|
+
def handle_user_not_found_error(error)
|
41
|
+
fail UserNotFoundError, 'User not found' if get_status_code(error) == '404'
|
42
|
+
end
|
48
43
|
|
49
|
-
|
50
|
-
|
44
|
+
# Build user URI from username and api url
|
45
|
+
def uri_for_user(username)
|
46
|
+
fail ArgumentError, 'Please provide a username' if username.empty?
|
51
47
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
48
|
+
URI.parse(api_url % username)
|
49
|
+
end
|
50
|
+
|
51
|
+
# The URL of the API we'll use.
|
52
|
+
def api_url
|
53
|
+
'https://coderwall.com/%s.json'
|
54
|
+
end
|
56
55
|
end
|
57
56
|
end
|
57
|
+
|
58
58
|
# Handles user not found exception
|
59
59
|
class UserNotFoundError < StandardError
|
60
60
|
end
|
@@ -64,4 +64,4 @@ class ServerError < StandardError
|
|
64
64
|
end
|
65
65
|
# Handles bad JSON
|
66
66
|
class InvalidJson < StandardError
|
67
|
-
end
|
67
|
+
end
|
data/lib/coder_wally/badge.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# All code in the gem is namespaced under this module.
|
2
2
|
module CoderWally
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
3
|
+
# Stores Badge properties
|
4
|
+
class Badge
|
5
|
+
# Object properties
|
6
|
+
attr_reader :name, :badge, :description, :created
|
7
|
+
|
8
|
+
# Initialise object with a hash of values
|
9
|
+
def initialize(hashed_badge)
|
10
|
+
@name = hashed_badge.fetch('name')
|
11
|
+
@badge = hashed_badge.fetch('badge')
|
12
|
+
@description = hashed_badge.fetch('description')
|
13
|
+
@created = hashed_badge.fetch('created')
|
15
14
|
end
|
16
|
-
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/coder_wally/builder.rb
CHANGED
data/lib/coder_wally/client.rb
CHANGED
@@ -1,34 +1,35 @@
|
|
1
1
|
module CoderWally
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
# Client to access the API
|
3
|
+
class Client
|
4
|
+
# Instantiate class
|
5
|
+
def initialize
|
6
|
+
@api = API.new
|
7
|
+
@builder = Builder.new
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# Get user details for given user and return a `User` object
|
17
|
-
def get_details_for username
|
18
|
-
coder_wall = build_coder_wall_from_response(username)
|
19
|
-
coder_wall.user
|
20
|
-
end
|
10
|
+
# Get badges for given user and return has collection of `Badge`s
|
11
|
+
def get_badges_for(username)
|
12
|
+
coder_wall = build_coder_wall_from_response(username)
|
13
|
+
coder_wall.badges
|
14
|
+
end
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
# Get user details for given user and return a `User` object
|
17
|
+
def get_details_for(username)
|
18
|
+
coder_wall = build_coder_wall_from_response(username)
|
19
|
+
coder_wall.user
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get all the information available for a given user,
|
23
|
+
# returns a `CoderWall` object
|
24
|
+
def get_everything_for(username)
|
25
|
+
build_coder_wall_from_response(username)
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
# Builds a CoderWall object
|
29
|
+
def build_coder_wall_from_response(username)
|
30
|
+
json_response = @api.fetch(username)
|
30
31
|
|
31
|
-
|
32
|
-
end
|
32
|
+
@builder.build(json_response)
|
33
33
|
end
|
34
|
+
end
|
34
35
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# All code in the gem is namespaced under this module.
|
2
2
|
module CoderWally
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
# Stores all CoderWall attributes
|
4
|
+
class CoderWall
|
5
|
+
# :badges is the collection of user badges
|
6
|
+
# :user is the `User` object
|
7
|
+
# :accounts is the `Account` object
|
8
|
+
attr_reader :badges, :user, :accounts
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
10
|
+
# Instantiate the class with data
|
11
|
+
def initialize(badges, user, accounts)
|
12
|
+
@badges = badges
|
13
|
+
@user = user
|
14
|
+
@accounts = accounts
|
16
15
|
end
|
17
|
-
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/coder_wally/user.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# All code in the gem is namespaced under this module.
|
2
2
|
module CoderWally
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
3
|
+
# Stores user properties
|
4
|
+
class User
|
5
|
+
# Object properties
|
6
|
+
attr_reader :name, :username, :location, :team, :endorsements
|
7
|
+
|
8
|
+
# Initialise object with a hash of values
|
9
|
+
def initialize(name, username, location, team, endorsements)
|
10
|
+
@name = name
|
11
|
+
@username = username
|
12
|
+
@location = location
|
13
|
+
@team = team
|
14
|
+
@endorsements = endorsements
|
16
15
|
end
|
17
|
-
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/coder_wally/version.rb
CHANGED
data/lib/coder_wally.rb
CHANGED
data/test/account_test.rb
CHANGED
@@ -3,11 +3,11 @@ require 'coder_wally/account'
|
|
3
3
|
|
4
4
|
describe 'Account' do
|
5
5
|
it 'creates an account object with dynamic attributes' do
|
6
|
-
json_parsed = {'github' => 'gregstewart', 'twitter' => '_greg_stewart_'}
|
6
|
+
json_parsed = { 'github' => 'gregstewart', 'twitter' => '_greg_stewart_' }
|
7
7
|
|
8
8
|
account = CoderWally::Account.new(json_parsed)
|
9
9
|
|
10
10
|
account.github.must_equal 'gregstewart'
|
11
11
|
account.twitter.must_equal '_greg_stewart_'
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
data/test/coder_wally_test.rb
CHANGED
@@ -4,15 +4,19 @@ require 'coder_wally'
|
|
4
4
|
describe 'Coder Wally' do
|
5
5
|
before do
|
6
6
|
@client = CoderWally::Client.new
|
7
|
+
@accept_encoding = 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
|
8
|
+
@success_fixture = File.dirname(__FILE__) + '/./fixtures/200.json'
|
7
9
|
end
|
8
10
|
|
9
11
|
describe 'user badges' do
|
10
12
|
describe 'valid user' do
|
11
13
|
before do
|
12
|
-
success_response = open(File.expand_path(
|
13
|
-
stub_request(:get, 'https://coderwall.com/me.json')
|
14
|
-
with(:
|
15
|
-
|
14
|
+
success_response = open(File.expand_path(@success_fixture)).read
|
15
|
+
stub_request(:get, 'https://coderwall.com/me.json')
|
16
|
+
.with(headers: { 'Accept' => '*/*',
|
17
|
+
'Accept-Encoding' => @accept_encoding,
|
18
|
+
'User-Agent' => 'Ruby' })
|
19
|
+
.to_return(status: 200, body: success_response, headers: {})
|
16
20
|
end
|
17
21
|
|
18
22
|
it 'returns a hash of badges' do
|
@@ -29,64 +33,75 @@ describe 'Coder Wally' do
|
|
29
33
|
describe 'invalid user' do
|
30
34
|
it 'throws an exception when no user is passed in' do
|
31
35
|
err = -> { @client.get_badges_for }.must_raise ArgumentError
|
32
|
-
err.message.must_match
|
36
|
+
err.message.must_match(/wrong number/)
|
33
37
|
end
|
34
38
|
|
35
39
|
it 'throws an exception when empty string is passed in' do
|
36
40
|
err = -> { @client.get_badges_for '' }.must_raise ArgumentError
|
37
|
-
err.message.must_match
|
41
|
+
err.message.must_match(/Please provide a username/)
|
38
42
|
end
|
39
43
|
|
40
44
|
describe 'not found' do
|
41
45
|
before do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
not_found_fixture = File.dirname(__FILE__) + '/./fixtures/404.json'
|
47
|
+
not_found_response = open(File.expand_path(not_found_fixture)).read
|
48
|
+
stub_request(:get, 'https://coderwall.com/me.json')
|
49
|
+
.with(headers: { 'Accept' => '*/*',
|
50
|
+
'Accept-Encoding' => @accept_encoding,
|
51
|
+
'User-Agent' => 'Ruby' })
|
52
|
+
.to_return(status: 404, body: not_found_response, headers: {})
|
46
53
|
end
|
47
54
|
|
48
55
|
it 'throws a UserNotFoundError when the user is not found' do
|
49
56
|
err = -> { @client.get_badges_for('me') }.must_raise UserNotFoundError
|
50
|
-
err.message.must_match
|
57
|
+
err.message.must_match(/User not found/)
|
51
58
|
end
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
55
62
|
describe 'service throws an error' do
|
56
63
|
before do
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
64
|
+
empty_fixture = File.dirname(__FILE__) + '/./fixtures/empty.json'
|
65
|
+
server_error = open(File.expand_path(empty_fixture)).read
|
66
|
+
stub_request(:get, 'https://coderwall.com/me.json')
|
67
|
+
.with(headers: { 'Accept' => '*/*',
|
68
|
+
'Accept-Encoding' => @accept_encoding,
|
69
|
+
'User-Agent' => 'Ruby' })
|
70
|
+
.to_return(status: 500, body: server_error, headers: {})
|
61
71
|
end
|
62
72
|
|
63
73
|
it 'throws a ServerError when the server response is 500' do
|
64
74
|
err = -> { @client.get_badges_for('me') }.must_raise ServerError
|
65
|
-
err.message.must_match
|
75
|
+
err.message.must_match(/Server error/)
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
69
79
|
describe 'bad data' do
|
70
80
|
before do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
81
|
+
bad_json_fixture = File.dirname(__FILE__) + '/./fixtures/bad.json'
|
82
|
+
bad_data = open(File.expand_path(bad_json_fixture)).read
|
83
|
+
stub_request(:get, 'https://coderwall.com/me.json')
|
84
|
+
.with(headers: { 'Accept' => '*/*',
|
85
|
+
'Accept-Encoding' => @accept_encoding,
|
86
|
+
'User-Agent' => 'Ruby' })
|
87
|
+
.to_return(status: 200, body: bad_data, headers: {})
|
75
88
|
end
|
76
89
|
|
77
90
|
it 'throws a InvalidJson exception when bad JSON is returned' do
|
78
91
|
err = -> { @client.get_badges_for('me') }.must_raise InvalidJson
|
79
|
-
err.message.must_match
|
92
|
+
err.message.must_match(/invalid json/)
|
80
93
|
end
|
81
94
|
end
|
82
95
|
end
|
83
96
|
|
84
97
|
describe 'user details' do
|
85
98
|
before do
|
86
|
-
success_response = open(File.expand_path(
|
87
|
-
stub_request(:get, 'https://coderwall.com/me.json')
|
88
|
-
with(:
|
89
|
-
|
99
|
+
success_response = open(File.expand_path(@success_fixture)).read
|
100
|
+
stub_request(:get, 'https://coderwall.com/me.json')
|
101
|
+
.with(headers: { 'Accept' => '*/*',
|
102
|
+
'Accept-Encoding' => @accept_encoding,
|
103
|
+
'User-Agent' => 'Ruby' })
|
104
|
+
.to_return(status: 200, body: success_response, headers: {})
|
90
105
|
end
|
91
106
|
|
92
107
|
it 'returns a user' do
|
@@ -102,10 +117,12 @@ describe 'Coder Wally' do
|
|
102
117
|
|
103
118
|
describe 'everything' do
|
104
119
|
before do
|
105
|
-
success_response = open(File.expand_path(
|
106
|
-
stub_request(:get, 'https://coderwall.com/me.json')
|
107
|
-
with(:
|
108
|
-
|
120
|
+
success_response = open(File.expand_path(@success_fixture)).read
|
121
|
+
stub_request(:get, 'https://coderwall.com/me.json')
|
122
|
+
.with(headers: { 'Accept' => '*/*',
|
123
|
+
'Accept-Encoding' => @accept_encoding,
|
124
|
+
'User-Agent' => 'Ruby' })
|
125
|
+
.to_return(status: 200, body: success_response, headers: {})
|
109
126
|
|
110
127
|
@coder_wall = @client.get_everything_for('me')
|
111
128
|
end
|
@@ -127,5 +144,4 @@ describe 'Coder Wally' do
|
|
127
144
|
@coder_wall.accounts.must_be_instance_of CoderWally::Account
|
128
145
|
end
|
129
146
|
end
|
130
|
-
|
131
|
-
end
|
147
|
+
end
|
data/test/test_helper.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.1
|
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-02-
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: A simple gem to fetch user badges from Coder Wall
|
70
84
|
email:
|
71
85
|
- gregs@tcias.co.uk
|
@@ -76,6 +90,8 @@ extra_rdoc_files: []
|
|
76
90
|
files:
|
77
91
|
- ".coveralls.yml"
|
78
92
|
- ".gitignore"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".rubocop_todo.yml"
|
79
95
|
- ".ruby-version"
|
80
96
|
- ".travis.yml"
|
81
97
|
- Gemfile
|
@@ -83,6 +99,7 @@ files:
|
|
83
99
|
- README.md
|
84
100
|
- Rakefile
|
85
101
|
- bin/coder_wally
|
102
|
+
- circle.yml
|
86
103
|
- coder_wally.gemspec
|
87
104
|
- lib/coder_wally.rb
|
88
105
|
- lib/coder_wally/account.rb
|
@@ -120,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
137
|
version: '0'
|
121
138
|
requirements: []
|
122
139
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.2.2
|
124
141
|
signing_key:
|
125
142
|
specification_version: 4
|
126
143
|
summary: A simple gem to fetch user badges from Coder Wall
|