coder_wally 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/coder_wally +2 -3
- data/coder_wally.gemspec +5 -5
- data/lib/coder_wally/builder.rb +4 -4
- data/lib/coder_wally/client.rb +25 -9
- data/lib/coder_wally/coder_wall.rb +4 -4
- data/lib/coder_wally/user.rb +11 -7
- data/lib/coder_wally/version.rb +1 -1
- data/test/coder_wally_test.rb +51 -12
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84448d05d51d8fedf698a7bdf9163c7fdc450db6
|
4
|
+
data.tar.gz: 241c66da1f41c0c09403c4d6ef809525a28e0a2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da39a27e989de4e8b652da155a028bc50e9796166ba0396496c1bc6076f0bdfe080245bbad174b3a4c663742830bbb8cef834346567f09557aa67594f500f4e2
|
7
|
+
data.tar.gz: eec5c75161b05440442b05c335e756c691b4e395badd2edce5b81261d6468f4aee0fe6815306c149c363b58abcc70368bf9da5bed0dbb2f29090f7977dd4437e
|
data/bin/coder_wally
CHANGED
data/coder_wally.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
-
spec.add_development_dependency 'rake', '~> 10.
|
23
|
-
spec.add_development_dependency 'webmock', '~>1.
|
24
|
-
spec.add_development_dependency 'coveralls', '~>0.
|
25
|
-
spec.add_development_dependency 'rubocop', '~>0.29.
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7.12'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.4.2'
|
23
|
+
spec.add_development_dependency 'webmock', '~>1.21.0'
|
24
|
+
spec.add_development_dependency 'coveralls', '~>0.8.0'
|
25
|
+
spec.add_development_dependency 'rubocop', '~>0.29.1'
|
26
26
|
end
|
data/lib/coder_wally/builder.rb
CHANGED
@@ -22,16 +22,16 @@ module CoderWally
|
|
22
22
|
|
23
23
|
# parse user information from data
|
24
24
|
def parse_user(data)
|
25
|
-
|
25
|
+
badges = parse_badges(data['badges'])
|
26
|
+
accounts = parse_accounts(data['accounts'])
|
27
|
+
User.new(data, badges, accounts)
|
26
28
|
end
|
27
29
|
|
28
30
|
# build CoderWall object from API response
|
29
31
|
def build(response)
|
30
|
-
badges = parse_badges(response['badges'])
|
31
|
-
accounts = parse_accounts(response['accounts'])
|
32
32
|
user = parse_user(response)
|
33
33
|
|
34
|
-
CoderWall.new
|
34
|
+
CoderWall.new user
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/coder_wally/client.rb
CHANGED
@@ -2,34 +2,50 @@ module CoderWally
|
|
2
2
|
# Client to access the API
|
3
3
|
class Client
|
4
4
|
# Instantiate class
|
5
|
-
def initialize
|
5
|
+
def initialize(username)
|
6
6
|
@api = API.new
|
7
7
|
@builder = Builder.new
|
8
|
+
@coder_wall = build_coder_wall_from_response(username)
|
8
9
|
end
|
9
10
|
|
10
11
|
# Get badges for given user and return has collection of `Badge`s
|
11
|
-
def get_badges_for(username)
|
12
|
-
|
13
|
-
coder_wall.badges
|
12
|
+
def get_badges_for(*username)
|
13
|
+
deprecation_message("get_badges_for(#{username})",'user.badges')
|
14
|
+
@coder_wall.user.badges
|
14
15
|
end
|
15
16
|
|
16
17
|
# Get user details for given user and return a `User` object
|
17
|
-
def get_details_for(username)
|
18
|
-
|
19
|
-
coder_wall.user
|
18
|
+
def get_details_for(*username)
|
19
|
+
deprecation_message("get_details_for(#{username})",'user.details')
|
20
|
+
@coder_wall.user.details
|
20
21
|
end
|
21
22
|
|
22
23
|
# Get all the information available for a given user,
|
23
24
|
# returns a `CoderWall` object
|
24
|
-
def get_everything_for(username)
|
25
|
-
|
25
|
+
def get_everything_for(*username)
|
26
|
+
deprecation_message("get_everything_for(#{username})",'user')
|
27
|
+
@coder_wall
|
26
28
|
end
|
27
29
|
|
30
|
+
# Get all the information for a given user
|
31
|
+
# Returns a user object
|
32
|
+
def user
|
33
|
+
@coder_wall.user
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
28
38
|
# Builds a CoderWall object
|
29
39
|
def build_coder_wall_from_response(username)
|
30
40
|
json_response = @api.fetch(username)
|
31
41
|
|
32
42
|
@builder.build(json_response)
|
33
43
|
end
|
44
|
+
|
45
|
+
# displaying a warning message that the API method is deprecated
|
46
|
+
def deprecation_message(old, new)
|
47
|
+
warn "[DEPRECATION] `#{old}` is deprecated. Please use `#{new}` instead."
|
48
|
+
end
|
49
|
+
|
34
50
|
end
|
35
51
|
end
|
@@ -3,15 +3,15 @@ module CoderWally
|
|
3
3
|
# Stores all CoderWall attributes
|
4
4
|
class CoderWall
|
5
5
|
# :badges is the collection of user badges
|
6
|
-
# :user is the `User` object
|
6
|
+
# :user is the `User` object (with badges and accounts)
|
7
7
|
# :accounts is the `Account` object
|
8
8
|
attr_reader :badges, :user, :accounts
|
9
9
|
|
10
10
|
# Instantiate the class with data
|
11
|
-
def initialize(
|
12
|
-
@badges = badges
|
11
|
+
def initialize(user)
|
13
12
|
@user = user
|
14
|
-
@
|
13
|
+
@badges = user.badges
|
14
|
+
@accounts = user.accounts
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/coder_wally/user.rb
CHANGED
@@ -3,15 +3,19 @@ module CoderWally
|
|
3
3
|
# Stores user properties
|
4
4
|
class User
|
5
5
|
# Object properties
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :badges, :accounts, :details
|
7
7
|
|
8
8
|
# Initialise object with a hash of values
|
9
|
-
def initialize(data)
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
|
14
|
-
|
9
|
+
def initialize(data, badges, accounts)
|
10
|
+
@badges = badges
|
11
|
+
@accounts = accounts
|
12
|
+
@details = {
|
13
|
+
name: data['name'],
|
14
|
+
username: data['username'],
|
15
|
+
location: data['location'],
|
16
|
+
team: data['team'],
|
17
|
+
endorsements: data['endorsements']
|
18
|
+
}
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
data/lib/coder_wally/version.rb
CHANGED
data/test/coder_wally_test.rb
CHANGED
@@ -3,7 +3,6 @@ require 'coder_wally'
|
|
3
3
|
|
4
4
|
describe 'Coder Wally' do
|
5
5
|
before do
|
6
|
-
@client = CoderWally::Client.new
|
7
6
|
@accept_encoding = 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
|
8
7
|
@success_fixture = File.dirname(__FILE__) + '/./fixtures/200.json'
|
9
8
|
end
|
@@ -17,6 +16,7 @@ describe 'Coder Wally' do
|
|
17
16
|
'Accept-Encoding' => @accept_encoding,
|
18
17
|
'User-Agent' => 'Ruby' })
|
19
18
|
.to_return(status: 200, body: success_response, headers: {})
|
19
|
+
@client = CoderWally::Client.new('me')
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'returns a hash of badges' do
|
@@ -32,12 +32,12 @@ describe 'Coder Wally' do
|
|
32
32
|
|
33
33
|
describe 'invalid user' do
|
34
34
|
it 'throws an exception when no user is passed in' do
|
35
|
-
err = -> {
|
35
|
+
err = -> { CoderWally::Client.new() }.must_raise ArgumentError
|
36
36
|
err.message.must_match(/wrong number/)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'throws an exception when empty string is passed in' do
|
40
|
-
err = -> {
|
40
|
+
err = -> { CoderWally::Client.new('') }.must_raise ArgumentError
|
41
41
|
err.message.must_match(/Please provide a username/)
|
42
42
|
end
|
43
43
|
|
@@ -53,7 +53,7 @@ describe 'Coder Wally' do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'throws a UserNotFoundError when the user is not found' do
|
56
|
-
err = -> {
|
56
|
+
err = -> { CoderWally::Client.new('me') }.must_raise UserNotFoundError
|
57
57
|
err.message.must_match(/User not found/)
|
58
58
|
end
|
59
59
|
end
|
@@ -71,7 +71,7 @@ describe 'Coder Wally' do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'throws a ServerError when the server response is 500' do
|
74
|
-
err = -> {
|
74
|
+
err = -> { CoderWally::Client.new('me') }.must_raise ServerError
|
75
75
|
err.message.must_match(/Server error/)
|
76
76
|
end
|
77
77
|
end
|
@@ -88,7 +88,7 @@ describe 'Coder Wally' do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'throws a InvalidJson exception when bad JSON is returned' do
|
91
|
-
err = -> {
|
91
|
+
err = -> { CoderWally::Client.new('me') }.must_raise InvalidJson
|
92
92
|
err.message.must_match(/invalid json/)
|
93
93
|
end
|
94
94
|
end
|
@@ -102,16 +102,16 @@ describe 'Coder Wally' do
|
|
102
102
|
'Accept-Encoding' => @accept_encoding,
|
103
103
|
'User-Agent' => 'Ruby' })
|
104
104
|
.to_return(status: 200, body: success_response, headers: {})
|
105
|
+
@client = CoderWally::Client.new('me')
|
105
106
|
end
|
106
107
|
|
107
108
|
it 'returns a user' do
|
108
109
|
user = @client.get_details_for('me')
|
109
|
-
|
110
|
-
user.
|
111
|
-
user.
|
112
|
-
user.
|
113
|
-
user.
|
114
|
-
user.endorsements.must_be_kind_of Integer
|
110
|
+
user[:name].must_equal 'Greg Stewart'
|
111
|
+
user[:username].must_equal 'gregstewart'
|
112
|
+
user[:location].must_equal 'London, UK'
|
113
|
+
user[:team].must_be_nil
|
114
|
+
user[:endorsements].must_be_kind_of Integer
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -124,6 +124,7 @@ describe 'Coder Wally' do
|
|
124
124
|
'User-Agent' => 'Ruby' })
|
125
125
|
.to_return(status: 200, body: success_response, headers: {})
|
126
126
|
|
127
|
+
@client = CoderWally::Client.new('me')
|
127
128
|
@coder_wall = @client.get_everything_for('me')
|
128
129
|
end
|
129
130
|
|
@@ -144,4 +145,42 @@ describe 'Coder Wally' do
|
|
144
145
|
@coder_wall.accounts.must_be_instance_of CoderWally::Account
|
145
146
|
end
|
146
147
|
end
|
148
|
+
|
149
|
+
describe 'client' do
|
150
|
+
before do
|
151
|
+
success_response = open(File.expand_path(@success_fixture)).read
|
152
|
+
stub_request(:get, 'https://coderwall.com/me.json')
|
153
|
+
.with(headers: { 'Accept' => '*/*',
|
154
|
+
'Accept-Encoding' => @accept_encoding,
|
155
|
+
'User-Agent' => 'Ruby' })
|
156
|
+
.to_return(status: 200, body: success_response, headers: {})
|
157
|
+
|
158
|
+
@client = CoderWally::Client.new('me')
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'exposes a user object' do
|
162
|
+
@client.user.must_be_instance_of CoderWally::User
|
163
|
+
end
|
164
|
+
|
165
|
+
describe 'user' do
|
166
|
+
it 'has a badges collection' do
|
167
|
+
@client.user.badges.count.must_equal 11
|
168
|
+
@client.user.badges.first.must_be_instance_of CoderWally::Badge
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'has an accounts property' do
|
172
|
+
@client.user.accounts.must_be_instance_of CoderWally::Account
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'returns a users details' do
|
176
|
+
details = @client.user.details
|
177
|
+
|
178
|
+
details[:name].must_equal 'Greg Stewart'
|
179
|
+
details[:username].must_equal 'gregstewart'
|
180
|
+
details[:location].must_equal 'London, UK'
|
181
|
+
details[:team].must_be_nil
|
182
|
+
details[:endorsements].must_be_kind_of Integer
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
147
186
|
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.
|
4
|
+
version: 1.0.0
|
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-
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,70 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.7.12
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.7.12
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 10.4.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 10.4.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: webmock
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.21.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.21.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: coveralls
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.8.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.8.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.29.
|
75
|
+
version: 0.29.1
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.29.
|
82
|
+
version: 0.29.1
|
83
83
|
description: A simple gem to fetch user badges from Coder Wall
|
84
84
|
email:
|
85
85
|
- gregs@tcias.co.uk
|