Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (44 sloc) 1.04 KB
require 'rubygems'
require 'open-uri'
require 'json'
require 'uri'
module GitHub
module User
class Repos
def initialize(user)
@username = user
@repositories = nil
end
def username
return @username
end
def repositories
if @repositories
return @repositories
end
url = URI.parse("http://github.com/api/v2/json/repos/show/" + @username)
text = open(url).read
response = JSON.parse( text )
@repositories = response["repositories"]
@repositories
end
def fetch(name)
repositories.find{|r| r['name'] == name }
end
end
end
module Search
class Repos
def initialize(repo)
@repositories = nil
url = URI.parse("http://github.com/api/v2/json/repos/search/" + repo.gsub(' ','%20'))
text = open(url).read
response = JSON.parse( text )
@repositories = response["repositories"]
end
def list
@repositories
end
end
end
end