0
- def self.grab(user, repo=nil, branch=nil, commit=nil) #:nodoc:
0
- url = "http://github.com/api/v1/json/#{user}"
0
- url += commit ? "/commit/#{commit}" : "/commits/#{branch}"
0
- GitHub::Hash.new(JSON.parse(open(url).read),user,repo)
0
- # Fetches information about the specified user name.
0
+ BASE_URL = "http://github.com/api/v1/json"
0
- # Fetches the commits for a given repository.
0
- def self.commits(user,repository,branch="master")
0
- self.grab(user,repository,branch).commits
0
+ # Fetches information about the specified user name.
0
+ url = BASE_URL + "/#{user}"
0
+ GitHub::User.new(JSON.parse(open(url).read)["user"])
0
- # Fetches a single commit for a repository.
0
- def self.commit(user,repository,commit)
0
- self.grab(user,repository,nil,commit).commit
0
-class GitHub::Hash < Hash #:nodoc: all
0
- def initialize(hash = nil, user = nil, repo = nil, obj = nil)
0
- if hash && hash.is_a?(Hash)
0
- v = ::GitHub::Hash.new(v,user,repo,obj) if v.is_a?(Hash) && !v.is_a?(::GitHub::Hash)
0
- v = v.collect{|potential_hash|
0
- potential_hash = ::GitHub::Hash.new(potential_hash,user,repo,obj) if potential_hash.is_a?(Hash) && !potential_hash.is_a?(::GitHub::Hash)
0
+ # Fetches the commits for a given repository.
0
+ def self.commits(user,repository,branch="master")
0
+ url = BASE_URL + "/#{user}/#{repository}/commits/#{branch}"
0
+ JSON.parse(open(url).read)["commits"].collect{ |c|
0
+ GitHub::Commit.new(c.merge(:user => user, :repository => repository))
0
- self["id"] ? self["id"] : super
0
+ # Fetches a single commit for a repository.
0
+ def self.commit(user,repository,commit)
0
+ url = BASE_URL + "/#{user}/#{repository}/commit/#{commit}"
0
+ GitHub::Commit.new(JSON.parse(open(url).read).merge(:user => user, :repository => repository))
0
+ class Repository < Mash
0
+ ::GitHub::API.commits(user,name)
0
+ def initialize(hash = nil)
0
+ @user = hash["login"] if hash
0
+ def repositories=(repo_array)
0
+ self["repositories"] = repo_array.collect{|r| ::GitHub::Repository.new(r.merge(:user => login || @user))}
0
- def method_missing(method_name, *args)
0
- if (match = method_name.to_s.match(/(.*)=$/)) && args.size == 1
0
- self[match[1]] = args.first
0
- elsif keys.include?(method_name.to_s)
0
- elsif method_name.to_s == "commits" && self["name"] && self["url"]
0
- GitHub.commits(@user, name)
0
- elsif method_name.to_s == "detailed" && self["id"] && self["message"]
0
- GitHub.commit(@user,@repo,self["id"])
0
+ # if a method only available to a detailed commit is called,
0
+ # automatically fetch it from the API
0
+ ::GitHub::API.commit(user,repository,id)
0
\ No newline at end of file
Comments
No one has commented yet.