coderwall_ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/LICENCE +7 -0
- data/README.md +5 -0
- data/Rakefile +8 -0
- data/bin/coderwall +22 -0
- data/coderwall_ruby.gemspec +27 -0
- data/lib/coderwall_ruby.rb +5 -0
- data/lib/coderwall_ruby/user.rb +25 -0
- data/lib/coderwall_ruby/version.rb +3 -0
- data/spec/fixtures/coderwall_ruby_cassettes/user.yml +62 -0
- data/spec/lib/coderwall_ruby/user_spec.rb +51 -0
- data/spec/spec_helper.rb +15 -0
- metadata +128 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENCE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2013 Gareth Rees
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/coderwall
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
bin_file = Pathname.new(__FILE__).realpath
|
5
|
+
$:.unshift File.expand_path('../../lib', bin_file)
|
6
|
+
require 'coderwall_ruby'
|
7
|
+
|
8
|
+
|
9
|
+
if ARGV[0].nil?
|
10
|
+
puts '--> Please provide a username'
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
if ARGV[1].nil?
|
15
|
+
puts '--> please provide an attribute'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
user = ARGV[0]
|
20
|
+
attribute = ARGV[1]
|
21
|
+
|
22
|
+
puts CoderwallRuby::User.new(user).send(attribute)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coderwall_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'coderwall_ruby'
|
8
|
+
gem.version = CoderwallRuby::VERSION
|
9
|
+
gem.authors = ['Gareth Rees']
|
10
|
+
gem.email = ['gareth@garethrees.co.uk']
|
11
|
+
gem.description = %q{Simple wrapper around Coderwall User API}
|
12
|
+
gem.summary = %q{Simple wrapper around Coderwall User API}
|
13
|
+
gem.homepage = ''
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency 'httparty'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'minitest'
|
23
|
+
gem.add_development_dependency 'webmock'
|
24
|
+
gem.add_development_dependency 'vcr'
|
25
|
+
gem.add_development_dependency 'turn'
|
26
|
+
gem.add_development_dependency 'rake'
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CoderwallRuby
|
2
|
+
class User
|
3
|
+
include HTTParty
|
4
|
+
base_uri 'https://coderwall.com'
|
5
|
+
|
6
|
+
attr_accessor :username
|
7
|
+
|
8
|
+
def initialize(username)
|
9
|
+
self.username = username
|
10
|
+
end
|
11
|
+
|
12
|
+
def profile
|
13
|
+
self.class.get "/#{ username }.json"
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(name, *args, &block)
|
17
|
+
if profile.has_key?(name.to_s)
|
18
|
+
profile[name.to_s]
|
19
|
+
else
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://coderwall.com/garethrees.json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Age:
|
16
|
+
- '0'
|
17
|
+
Cache-Control:
|
18
|
+
- public
|
19
|
+
Content-Type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
Date:
|
22
|
+
- Wed, 13 Feb 2013 15:20:12 GMT
|
23
|
+
Etag:
|
24
|
+
- ! '"3e9206313e0b6a4534b8e6ed11d9fa2f"'
|
25
|
+
Last-Modified:
|
26
|
+
- Mon, 11 Feb 2013 09:49:52 GMT
|
27
|
+
Status:
|
28
|
+
- 200 OK
|
29
|
+
Strict-Transport-Security:
|
30
|
+
- max-age=31536000
|
31
|
+
Vary:
|
32
|
+
- Accept-Encoding
|
33
|
+
X-Content-Digest:
|
34
|
+
- adec88819d3d46c60ad9f887a41d9fbc372bf15c
|
35
|
+
X-Rack-Cache:
|
36
|
+
- miss, ignore, store
|
37
|
+
X-Runtime:
|
38
|
+
- '0.908905'
|
39
|
+
X-Ua-Compatible:
|
40
|
+
- IE=Edge,chrome=1
|
41
|
+
Content-Length:
|
42
|
+
- '2168'
|
43
|
+
Connection:
|
44
|
+
- keep-alive
|
45
|
+
body:
|
46
|
+
encoding: US-ASCII
|
47
|
+
string: ! '{"username":"garethrees","name":"Gareth Rees","location":"Cardiff,
|
48
|
+
Wales UK","endorsements":0,"team":"50623342351e400015000003","accounts":{"github":"garethrees"},"badges":[{"name":"Forked","description":"Have
|
49
|
+
a project valued enough to be forked by someone else","created":"2012-12-06T03:54:46Z","badge":"https://d3levm2kxut31z.cloudfront.net/assets/badges/forked1-ccde995368958c2e041acd64d8e4445f.png"},{"name":"Altruist","description":"Increase
|
50
|
+
developer well-being by sharing at least 20 open source projects","created":"2012-11-23T11:53:50Z","badge":"https://d3levm2kxut31z.cloudfront.net/assets/badges/altrustic-ac4b637a6c9fb3801257550f0a870acc.png"},{"name":"Ashcat","description":"Make
|
51
|
+
Ruby on Rails better for everyone by getting a commit accepted","created":"2012-09-22T23:55:31Z","badge":"https://d3levm2kxut31z.cloudfront.net/assets/badges/moongoose-rails-b4e511081713da757173baec27d48cb4.png"},{"name":"Walrus","description":"The
|
52
|
+
walrus is no stranger to variety. Use at least 4 different languages throughout
|
53
|
+
all your repos","created":"2012-03-08T20:40:30Z","badge":"https://d3levm2kxut31z.cloudfront.net/assets/badges/walrus-a0bb4ddb2394171b632edc953930518d.png"},{"name":"Raven","description":"Have
|
54
|
+
at least one original repo where some form of shell script is the dominant
|
55
|
+
language","created":"2012-02-08T02:09:56Z","badge":"https://d3levm2kxut31z.cloudfront.net/assets/badges/raven-e70b246059a7fce7ff778a1d935bf72f.png"},{"name":"Mongoose
|
56
|
+
3","description":"Have at least three original repos where Ruby is the dominant
|
57
|
+
language","created":"2011-06-23T00:26:00Z","badge":"https://d3levm2kxut31z.cloudfront.net/assets/badges/mongoose3-f4d6bb5a6f9e8ada6c1959f05f36c583.png"},{"name":"Charity","description":"Fork
|
58
|
+
and commit to someone''s open source project in need","created":"2011-05-27T09:34:47Z","badge":"https://d3levm2kxut31z.cloudfront.net/assets/badges/charity-6c70c329d56fa13fcab3f07b26f0b178.png"},{"name":"Mongoose","description":"Have
|
59
|
+
at least one original repo where Ruby is the dominant language","created":"2011-05-27T09:34:46Z","badge":"https://d3levm2kxut31z.cloudfront.net/assets/badges/mongoose-e0e4cbd12d67a2c7ff946cce1fda8881.png"}]}'
|
60
|
+
http_version:
|
61
|
+
recorded_at: Wed, 13 Feb 2013 15:20:16 GMT
|
62
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe CoderwallRuby::User do
|
4
|
+
|
5
|
+
it 'can make HTTP requests' do
|
6
|
+
CoderwallRuby::User.must_include HTTParty
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'communicates with coderwall' do
|
10
|
+
CoderwallRuby::User.base_uri.must_equal 'https://coderwall.com'
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'GET profile' do
|
14
|
+
|
15
|
+
let(:user) { CoderwallRuby::User.new('garethrees') }
|
16
|
+
|
17
|
+
before do
|
18
|
+
VCR.insert_cassette 'user', :record => :new_episodes
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
VCR.eject_cassette
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'must respond to profile' do
|
26
|
+
user.must_respond_to :profile
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'parses the API response from JSON to a hash' do
|
30
|
+
user.profile.must_be_instance_of Hash
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'performs the request and gets the profile data' do
|
34
|
+
user.profile['username'].must_equal 'garethrees'
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'dynamic attributes' do
|
38
|
+
|
39
|
+
it 'returns the attribute value if present in the profile' do
|
40
|
+
user.name.must_equal 'Gareth Rees'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'raises a NoMethodError if an attribute is not present' do
|
44
|
+
lambda { user.dolen }.must_raise NoMethodError
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../lib/coderwall_ruby'
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'turn'
|
5
|
+
require 'vcr'
|
6
|
+
require 'webmock/minitest'
|
7
|
+
|
8
|
+
Turn.config do |c|
|
9
|
+
c.format = :dot
|
10
|
+
end
|
11
|
+
|
12
|
+
VCR.configure do |c|
|
13
|
+
c.cassette_library_dir = 'spec/fixtures/coderwall_ruby_cassettes'
|
14
|
+
c.hook_into :webmock
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coderwall_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gareth Rees
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: &70237032820160 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70237032820160
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: minitest
|
27
|
+
requirement: &70237032819740 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70237032819740
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: webmock
|
38
|
+
requirement: &70237032819320 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70237032819320
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: vcr
|
49
|
+
requirement: &70237032818900 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70237032818900
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: turn
|
60
|
+
requirement: &70237032818420 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70237032818420
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: &70237032817880 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70237032817880
|
80
|
+
description: Simple wrapper around Coderwall User API
|
81
|
+
email:
|
82
|
+
- gareth@garethrees.co.uk
|
83
|
+
executables:
|
84
|
+
- coderwall
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- .gitignore
|
89
|
+
- Gemfile
|
90
|
+
- LICENCE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- bin/coderwall
|
94
|
+
- coderwall_ruby.gemspec
|
95
|
+
- lib/coderwall_ruby.rb
|
96
|
+
- lib/coderwall_ruby/user.rb
|
97
|
+
- lib/coderwall_ruby/version.rb
|
98
|
+
- spec/fixtures/coderwall_ruby_cassettes/user.yml
|
99
|
+
- spec/lib/coderwall_ruby/user_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
homepage: ''
|
102
|
+
licenses: []
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 1.8.15
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: Simple wrapper around Coderwall User API
|
125
|
+
test_files:
|
126
|
+
- spec/fixtures/coderwall_ruby_cassettes/user.yml
|
127
|
+
- spec/lib/coderwall_ruby/user_spec.rb
|
128
|
+
- spec/spec_helper.rb
|