Created
January 17, 2009 23:17
-
-
Save spejman/48486 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'json' | |
require 'net/http' | |
class GitHub | |
def initialize(username) | |
@username = username | |
end | |
def data | |
url = "http://github.com/api/v1/json/#{username}" | |
resp = Net::HTTP.get_response(URI.parse(url)) | |
data = resp.body | |
result = JSON.parse(data) | |
return result | |
end | |
def username | |
@username | |
end | |
def repositories | |
repos = [] | |
data['user']['repositories'].each { |key, value| repos << key['name'] } | |
return repos | |
end | |
def name | |
data['user']['name'] | |
end | |
end | |
if ARGV.size == 1 | |
GitHub.new(ARGV[0]).repositories.each do |repo| | |
puts "[#{repo}]" | |
if !File.exist?(repo) | |
puts "=> Cloning" | |
system "git clone -q [email protected]:#{ARGV[0]}/#{repo}.git" | |
else | |
puts "=> Pulling & Pushing" | |
system "cd #{repo} && git pull && git push" | |
end | |
end | |
else | |
puts "=> Please provide your GitHub username" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
require 'github' | |
class TestGitHub < Test::Unit::TestCase | |
def setup | |
@github = GitHub.new('fesplugas') | |
end | |
def test_should_return_name | |
assert_equal "Francesc Esplugas", @github.name | |
end | |
def test_should_return_repositories_list | |
assert @github.repositories.include?('typus') | |
end | |
def test_error | |
@github = GitHub.new('fesplugues') | |
assert_raise JSON::ParserError do | |
@github.data | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment