public
Rubygem
Description: A Ruby library for getting information from the GitHub API.
Homepage: http://mbleigh.lighthouseapp.com/projects/10115-ruby-github
Clone URL: git://github.com/mbleigh/ruby-github.git
0.0.2 - Using Hoe, refactor to use Mash gem and much more structured data.
mbleigh (author)
Sat Apr 12 17:57:41 -0700 2008
commit  b95c073d78b08031a5e6292da83374a6aa0d97d3
tree    fdadc2c3b968e75124283c55eef6304a8c86a90c
parent  99d67633f3194d37bac4d95eb8eb7a716b9c320e
...
1
2
 
 
 
3
...
 
1
2
3
4
5
0
@@ -1 +1,3 @@
0
-/pkg
0
\ No newline at end of file
0
+/pkg
0
+/doc
0
+.DS_Store
0
\ No newline at end of file
...
 
 
1
2
 
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
 
 
 
17
18
19
20
21
 
 
...
1
2
3
 
4
5
6
 
 
 
 
 
 
 
 
 
 
 
 
 
7
8
9
10
11
 
 
 
 
12
13
0
@@ -1,21 +1,13 @@
0
+# -*- ruby -*-
0
+
0
 require 'rubygems'
0
-require 'rake/gempackagetask'
0
+require 'hoe'
0
+require './lib/ruby-github.rb'
0
 
0
-spec = Gem::Specification.new do |s|
0
- s.name = "ruby-github"
0
- s.version = "0.0.1"
0
- s.author = "Michael Bleigh"
0
- s.email = "michael@intridea.com"
0
- s.homepage = "http://www.mbleigh.com/"
0
- s.platform = Gem::Platform::RUBY
0
- s.summary = "A simple Ruby library for accessing information through the GitHub API."
0
- s.files = FileList["{spec,lib}/**/*"].to_a
0
- s.require_path = "lib"
0
- s.has_rdoc = true
0
- s.extra_rdoc_files = %w(README LICENSE)
0
- s.add_dependency "json"
0
+Hoe.new('ruby-github', GitHub::VERSION) do |p|
0
+ p.developer('Michael Bleigh', 'michael@example.com')
0
+ p.remote_rdoc_dir = ''
0
+ p.extra_deps = ["mash >= 0.0.2", "json"]
0
 end
0
-
0
-Rake::GemPackageTask.new(spec) do |pkg|
0
- pkg.need_tar = true
0
-end
0
+
0
+# vim: syntax=Ruby
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
 
 
 
21
22
23
24
25
 
 
 
 
 
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
 
 
 
 
 
51
52
53
54
55
 
 
 
 
 
56
57
58
59
60
 
 
 
 
61
62
63
64
65
 
 
 
 
 
 
 
 
 
 
66
67
68
69
70
71
72
73
74
75
76
77
78
 
 
 
 
 
79
80
81
82
...
1
2
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7
8
9
10
 
 
 
 
11
12
13
14
15
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
18
19
20
21
22
23
 
24
 
 
25
26
27
28
29
30
31
 
 
 
32
33
34
35
36
37
 
 
 
38
39
40
41
42
43
44
45
46
47
48
49
 
 
 
 
 
 
 
 
 
 
 
50
51
52
53
54
55
56
57
58
0
@@ -1,81 +1,57 @@
0
 require 'rubygems'
0
 require 'json'
0
 require 'open-uri'
0
+require 'mash'
0
 
0
-class GitHub
0
- def self.grab(user, repo=nil, branch=nil, commit=nil) #:nodoc:
0
- url = "http://github.com/api/v1/json/#{user}"
0
-
0
- if repo
0
- url += "/#{repo}"
0
- url += commit ? "/commit/#{commit}" : "/commits/#{branch}"
0
- end
0
-
0
- GitHub::Hash.new(JSON.parse(open(url).read),user,repo)
0
- end
0
-
0
- # Fetches information about the specified user name.
0
- def self.user(user)
0
- self.grab(user).user
0
- end
0
+module GitHub
0
+ VERSION = "0.0.2"
0
+ class API
0
+ BASE_URL = "http://github.com/api/v1/json"
0
   
0
- # Fetches the commits for a given repository.
0
- def self.commits(user,repository,branch="master")
0
- self.grab(user,repository,branch).commits
0
- end
0
+ # Fetches information about the specified user name.
0
+ def self.user(user)
0
+ url = BASE_URL + "/#{user}"
0
+ GitHub::User.new(JSON.parse(open(url).read)["user"])
0
+ end
0
   
0
- # Fetches a single commit for a repository.
0
- def self.commit(user,repository,commit)
0
- self.grab(user,repository,nil,commit).commit
0
- end
0
-end
0
-
0
-class GitHub::Hash < Hash #:nodoc: all
0
- def initialize(hash = nil, user = nil, repo = nil, obj = nil)
0
- super(obj)
0
-
0
- @user = user
0
- @repo = repo
0
-
0
- if hash && hash.is_a?(Hash)
0
- hash.each do |k,v|
0
- v = ::GitHub::Hash.new(v,user,repo,obj) if v.is_a?(Hash) && !v.is_a?(::GitHub::Hash)
0
- if v.is_a?(Array)
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
- potential_hash
0
- }
0
- end
0
- self[k] = v
0
- end
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
+ }
0
     end
0
- end
0
   
0
- def id
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
+ end
0
   end
0
   
0
- def [](key)
0
- key = key.to_s
0
- super
0
+ class Repository < Mash
0
+ def commits
0
+ ::GitHub::API.commits(user,name)
0
+ end
0
   end
0
   
0
- def []=(key,value)
0
- key = key.to_s
0
- super
0
+ class User < Mash
0
+ def initialize(hash = nil)
0
+ @user = hash["login"] if hash
0
+ super
0
+ end
0
+
0
+ def repositories=(repo_array)
0
+ puts self.inspect
0
+ self["repositories"] = repo_array.collect{|r| ::GitHub::Repository.new(r.merge(:user => login || @user))}
0
+ end
0
   end
0
   
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
- self[method_name]
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
- else
0
- super
0
+ class Commit < Mash
0
+ # if a method only available to a detailed commit is called,
0
+ # automatically fetch it from the API
0
+ def detailed
0
+ ::GitHub::API.commit(user,repository,id)
0
     end
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.