coder_wally 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.travis.yml +3 -0
- data/README.md +16 -2
- data/Rakefile +1 -1
- data/bin/coder_wally +3 -1
- data/coder_wally.gemspec +1 -0
- data/lib/coder_wally/badge.rb +15 -0
- data/lib/coder_wally/client.rb +38 -0
- data/lib/coder_wally/version.rb +1 -1
- data/lib/coder_wally.rb +2 -43
- data/test/coder_wally_test.rb +18 -16
- data/test/test_helper.rb +3 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c19b110b50c0f07411b0d0400449649565e2975
|
4
|
+
data.tar.gz: 18e744906436350a32deac74aaccf3bccf233a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f11d10151bceca3d68de3a447149bb2b49df0ec988493ee417560771c6236ec43a1084b2fec7ab1e7bc48c1ba2c448baf765e01a341768a40e49f1370c3c80c8
|
7
|
+
data.tar.gz: 6ecf02798f6e642b6cbaf3ab20446e0a9127be3aa5d5974af6c4fab93f9c72a90d06cb3fceb4ccc3d64048fd055476f13e60a020be49ae2e82bb74073cb6ef38
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
# CoderWally
|
1
|
+
# CoderWally
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/coder_wally.svg)](http://badge.fury.io/rb/coder_wally)
|
4
|
+
[![Build Status](https://travis-ci.org/gregstewart/coder_wally.svg?branch=master)](https://travis-ci.org/gregstewart/coder_wally)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/gregstewart/coder_wally/badge.svg)](https://coveralls.io/r/gregstewart/coder_wally)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/gregstewart/coder_wally/badges/gpa.svg)](https://codeclimate.com/github/gregstewart/coder_wally)
|
7
|
+
[![Dependency Status](https://gemnasium.com/gregstewart/coder_wally.svg)](https://gemnasium.com/gregstewart/coder_wally)
|
8
|
+
[![Inline docs](https://inch-ci.org/github/gregstewart/coder_wally.svg?branch=master)](https://inch-ci.org/github/gregstewart/coder_wally)
|
2
9
|
|
3
10
|
A very very simple Gem to fetch user badges from Coder Wall
|
4
11
|
|
@@ -20,10 +27,17 @@ Or install it yourself as:
|
|
20
27
|
|
21
28
|
## Usage
|
22
29
|
|
23
|
-
|
30
|
+
After installing the Gem, you can for now you can invoke it
|
31
|
+
(remember to replace <username> with you a valid username) from the command line
|
32
|
+
using:
|
24
33
|
|
25
34
|
ruby -Ilib bin/coder_wally <username>
|
26
35
|
|
36
|
+
In your code:
|
37
|
+
|
38
|
+
client = CoderWally::Client.new
|
39
|
+
client.get_badges_for <username>
|
40
|
+
|
27
41
|
## Contributing
|
28
42
|
|
29
43
|
1. Fork it ( https://github.com/gregstewart/coder_wally/fork )
|
data/Rakefile
CHANGED
data/bin/coder_wally
CHANGED
data/coder_wally.gemspec
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
# All code in the gem is namespaced under this module.
|
2
|
+
module CoderWally
|
3
|
+
class Badge
|
4
|
+
# Object properties
|
5
|
+
attr_reader :name, :badge, :description, :created
|
6
|
+
|
7
|
+
# Initialise object with a hash of values
|
8
|
+
def initialize(hashed_badge)
|
9
|
+
@name = hashed_badge.fetch("name")
|
10
|
+
@badge = hashed_badge.fetch("badge")
|
11
|
+
@description = hashed_badge.fetch("description")
|
12
|
+
@created = hashed_badge.fetch("created")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module CoderWally
|
5
|
+
class Client
|
6
|
+
# The URL of API we'll use.
|
7
|
+
def api_url
|
8
|
+
"https://coderwall.com/%s.json"
|
9
|
+
end
|
10
|
+
# Build user URI from username and apii url
|
11
|
+
def uri_for_user username
|
12
|
+
URI.parse(api_url % username)
|
13
|
+
end
|
14
|
+
# Dispatch the request
|
15
|
+
def send_request url
|
16
|
+
begin
|
17
|
+
open(url)
|
18
|
+
rescue OpenURI::HTTPError => error
|
19
|
+
raise UserNotFoundError, "User not found" if error.io.status[0] == "404"
|
20
|
+
raise ServerError, "Server error" if error.io.status[0] == "500"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
# Get bnadges for given user and return has of `Badge`s
|
24
|
+
def get_badges_for username
|
25
|
+
raise(ArgumentError, "Plesae provide a username") if username.empty?
|
26
|
+
|
27
|
+
json_response = JSON.load(send_request(uri_for_user(username)))
|
28
|
+
|
29
|
+
json_response["badges"].map { |badge| Badge.new(badge) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class UserNotFoundError < StandardError
|
35
|
+
end
|
36
|
+
|
37
|
+
class ServerError < StandardError
|
38
|
+
end
|
data/lib/coder_wally/version.rb
CHANGED
data/lib/coder_wally.rb
CHANGED
@@ -1,44 +1,3 @@
|
|
1
1
|
require "coder_wally/version"
|
2
|
-
|
3
|
-
require "
|
4
|
-
require "json"
|
5
|
-
|
6
|
-
# All code in the gem is namespaced under this module.
|
7
|
-
module CoderWally
|
8
|
-
# The URL of API we'll use.
|
9
|
-
Url = "https://coderwall.com/%s.json"
|
10
|
-
|
11
|
-
class Badge
|
12
|
-
attr_reader :name, :badge, :description, :created
|
13
|
-
|
14
|
-
def initialize(hashed_badge)
|
15
|
-
@name = hashed_badge.fetch("name")
|
16
|
-
@badge = hashed_badge.fetch("badge")
|
17
|
-
@description = hashed_badge.fetch("description")
|
18
|
-
@created = hashed_badge.fetch("created")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def CoderWally.get_badges_for username
|
23
|
-
raise(ArgumentError, "Plesae provide a username") if username.empty?
|
24
|
-
url = URI.parse(Url % username)
|
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
|
-
|
35
|
-
response["badges"].map { |badge| Badge.new(badge) }
|
36
|
-
#
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class UserNotFoundError < StandardError
|
41
|
-
end
|
42
|
-
|
43
|
-
class ServerError < StandardError
|
44
|
-
end
|
2
|
+
require "coder_wally/badge"
|
3
|
+
require "coder_wally/client"
|
data/test/coder_wally_test.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require "minitest/autorun"
|
2
|
-
|
3
2
|
require "coder_wally"
|
4
|
-
require "webmock/minitest"
|
5
3
|
|
6
4
|
describe "Coder Wally" do
|
5
|
+
before do
|
6
|
+
@client = CoderWally::Client.new
|
7
|
+
end
|
8
|
+
|
7
9
|
it "has a default api url" do
|
8
|
-
"https://coderwall.com/%s.json".must_equal
|
10
|
+
"https://coderwall.com/%s.json".must_equal @client.api_url
|
9
11
|
end
|
10
12
|
|
11
13
|
describe "user badges" do
|
@@ -18,7 +20,7 @@ describe "Coder Wally" do
|
|
18
20
|
end
|
19
21
|
|
20
22
|
it "returns a hash of badges" do
|
21
|
-
badges =
|
23
|
+
badges = @client.get_badges_for('me')
|
22
24
|
|
23
25
|
badges.count.must_equal 11
|
24
26
|
badges.first.name.must_equal "Lab"
|
@@ -30,25 +32,25 @@ describe "Coder Wally" do
|
|
30
32
|
|
31
33
|
describe "invalid user" do
|
32
34
|
it "throws an exception when no user is passed in" do
|
33
|
-
err = ->{
|
35
|
+
err = ->{ @client.get_badges_for }.must_raise ArgumentError
|
34
36
|
err.message.must_match /wrong number/
|
35
37
|
end
|
36
38
|
|
37
39
|
it "throws an exception when empty string is passed in" do
|
38
|
-
err = ->{
|
40
|
+
err = ->{ @client.get_badges_for "" }.must_raise ArgumentError
|
39
41
|
err.message.must_match /Plesae provide a username/
|
40
42
|
end
|
41
43
|
|
42
44
|
describe "not found" do
|
43
45
|
before do
|
44
46
|
not_found_response = open(File.expand_path(File.dirname(__FILE__) + "/./fixtures/404.json")).read
|
45
|
-
|
46
|
-
|
47
|
-
|
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 => {})
|
48
50
|
end
|
49
51
|
|
50
52
|
it "throws a UserNotFoundError when the user is not found" do
|
51
|
-
err = ->{
|
53
|
+
err = ->{ @client.get_badges_for('me')}.must_raise UserNotFoundError
|
52
54
|
err.message.must_match /User not found/
|
53
55
|
end
|
54
56
|
end
|
@@ -57,15 +59,15 @@ describe "Coder Wally" do
|
|
57
59
|
describe "service throws an error" do
|
58
60
|
before do
|
59
61
|
server_error = open(File.expand_path(File.dirname(__FILE__) + "/./fixtures/empty.json")).read
|
60
|
-
|
61
|
-
|
62
|
-
|
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 => {})
|
63
65
|
end
|
64
66
|
|
65
67
|
it "throws a ServerError when the user is not found" do
|
66
|
-
|
67
|
-
|
68
|
-
|
68
|
+
err = ->{ @client.get_badges_for('me')}.must_raise ServerError
|
69
|
+
err.message.must_match /Server error/
|
70
|
+
end
|
69
71
|
end
|
70
72
|
end
|
71
73
|
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.0.
|
4
|
+
version: 0.0.4
|
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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.20.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: A simple gem to fetch user badges from Coder Wall
|
56
70
|
email:
|
57
71
|
- gregs@tcias.co.uk
|
@@ -60,7 +74,9 @@ executables:
|
|
60
74
|
extensions: []
|
61
75
|
extra_rdoc_files: []
|
62
76
|
files:
|
77
|
+
- ".coveralls.yml"
|
63
78
|
- ".gitignore"
|
79
|
+
- ".travis.yml"
|
64
80
|
- Gemfile
|
65
81
|
- LICENSE.txt
|
66
82
|
- README.md
|
@@ -68,6 +84,8 @@ files:
|
|
68
84
|
- bin/coder_wally
|
69
85
|
- coder_wally.gemspec
|
70
86
|
- lib/coder_wally.rb
|
87
|
+
- lib/coder_wally/badge.rb
|
88
|
+
- lib/coder_wally/client.rb
|
71
89
|
- lib/coder_wally/version.rb
|
72
90
|
- test/coder_wally_test.rb
|
73
91
|
- test/fixtures/200.json
|