coderwall-ruby-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ coderwall-ruby-api (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ coderwall-ruby-api!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Rafael Fidelis, http://defidelis.com
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ Coderwall Ruby API
2
+ ==================
3
+
4
+ A simple Ruby API for access [Coderwall](http://coderwall.com) user's data.
5
+
6
+ Usage
7
+ =====
8
+ First, install the gem :
9
+
10
+ gem install coderwall-ruby-api
11
+
12
+ Then, play :
13
+
14
+ require 'coderwall'
15
+
16
+ user = Coderwall::User.new('fidelisrafael') # Load user data
17
+ user.username # => 'fidelisrafael'
18
+ user.name # => 'Rafael Fidelis'
19
+
20
+ When you create a Coderwall::User instance, automatically the data is fetched from Coderwall, so if you want to fetch user' data only when it requisited, do this:
21
+
22
+ user = Corderwall::User.new('fidelisrafael',false) # create the object , but don't fetch the user data
23
+
24
+ user.location # => fetch the url and return user location
25
+ user.name # => use the cached user data requisited above
26
+
27
+ #### Differents ways to acess data :
28
+
29
+ user = Coderwall::User.new('fidelisrafael') # Load user data
30
+
31
+ user_badges = user.badges # Method
32
+ user_badges = user[:badges] # Hash notation
33
+ # Other examples
34
+ user_github_account = user.accounts['github']
35
+ user_github_account = user['accounts']['github']
36
+
37
+ # via class methods
38
+ user_badges = Coderwall::User.badges('fidelisrafael')
39
+ user_location = Coderwall::User.location('fidelisrafael')
40
+ # Another examples
41
+ user_badges = Coderwall::User.achievements('fidelisrafael')
42
+ user_github_account = Coderwall::User.accounts('fidelisrafael')['github']
43
+
44
+ License
45
+ =======
46
+ The project is licensed under the MIT license. See LICENSE file for details.
47
+
48
+ Contribute
49
+ ==========
50
+ Please feel free to either fork me or post issues.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/coderwall-ruby-api/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Rafael Fidelis"]
6
+ gem.email = ["rafa_fidelis@yahoo.com.br"]
7
+ gem.description = %q{Simple Coderwall API Interface for Ruby}
8
+ gem.summary = gem.description
9
+ gem.homepage = "https://github.com/fidelisrafael/coderwall-ruby-api"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "coderwall-ruby-api"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Coderwall::VERSION
17
+ end
@@ -0,0 +1,41 @@
1
+ require "coderwall-ruby-api/version"
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module Coderwall
6
+ BASE_URI = "http://coderwall.com/%s.json"
7
+ class User
8
+ def initialize(username, send_request=true)
9
+ username.empty? ? invalid_username : @username = username.to_s
10
+ make_http_request if send_request
11
+ end
12
+ def [](key)
13
+ return @user_data[key.to_s]
14
+ end
15
+ private
16
+ def method_missing(*args)
17
+ make_http_request
18
+ return @user_data[args[0].to_s] || super
19
+ end
20
+ def make_http_request
21
+ @user_data ||= JSON.parse(Net::HTTP.get(URI(BASE_URI % @username))) rescue invalid_username
22
+ end
23
+ def invalid_username
24
+ raise(ArgumentError.new('invalid username'))
25
+ end
26
+ class << self
27
+ def method_missing(*args)
28
+ self.new(args[1]).send(args[0])
29
+ end
30
+ # Hack for Class.name
31
+ # This method overwritten the default class method
32
+ def name(username)
33
+ self.new(username).name
34
+ end
35
+ def achievements_of(username)
36
+ self.badges(username)
37
+ end
38
+ alias :achievements :achievements_of
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Coderwall
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coderwall-ruby-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rafael Fidelis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Simple Coderwall API Interface for Ruby
15
+ email:
16
+ - rafa_fidelis@yahoo.com.br
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - coderwall-ruby-api.gemspec
28
+ - lib/coderwall-ruby-api.rb
29
+ - lib/coderwall-ruby-api/version.rb
30
+ homepage: https://github.com/fidelisrafael/coderwall-ruby-api
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.24
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Simple Coderwall API Interface for Ruby
54
+ test_files: []