ruby-github 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/Manifest.txt +5 -0
- data/README.txt +62 -0
- data/Rakefile +13 -0
- data/lib/ruby-github.rb +40 -64
- metadata +36 -13
- data/LICENSE +0 -22
- data/README +0 -35
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
== Ruby-GitHub
|
2
|
+
|
3
|
+
= DESCRIPTION:
|
4
|
+
|
5
|
+
Ruby-GitHub is a simple wrapper library for the evolving GitHub API.
|
6
|
+
|
7
|
+
= INSTALLATION:
|
8
|
+
|
9
|
+
RubyGem:
|
10
|
+
|
11
|
+
sudo gem install ruby-github
|
12
|
+
|
13
|
+
GitHub Clone:
|
14
|
+
|
15
|
+
git clone git://github.com/mbleigh/ruby-github.git
|
16
|
+
|
17
|
+
= DEPENDENCIES:
|
18
|
+
|
19
|
+
* Requires the 'json' gem
|
20
|
+
* Requires the 'mash' gem
|
21
|
+
|
22
|
+
= SYNOPSIS:
|
23
|
+
|
24
|
+
require 'ruby-github'
|
25
|
+
|
26
|
+
user = GitHub::API.user('mbleigh')
|
27
|
+
user.name # => "Michael Bleigh"
|
28
|
+
user.repositories # => array of repositories
|
29
|
+
user.repositories.last.name # => "ruby-github"
|
30
|
+
user.repositories.last.url # => "http://GitHub::API.com/mbleigh/ruby-github"
|
31
|
+
user.repositories.last.commits # => requests array of commits (see below)
|
32
|
+
|
33
|
+
commits = GitHub::API.commits('mbleigh','ruby-github')
|
34
|
+
commits.first.message # => "Moved GitHub::API.rb to ruby-GitHub::API.rb..."
|
35
|
+
commits.first.id # => "1d8c21062e11bb1ecd51ab840aa13d906993f3f7"
|
36
|
+
|
37
|
+
# these two lines are equivalent
|
38
|
+
commit = commits.first.detailed
|
39
|
+
commit = GitHub::API.commit('mbleigh', 'ruby-github', '1d8c21062e11bb1ecd51ab840aa13d906993f3f7')
|
40
|
+
|
41
|
+
commit.message # => "Moved GitHub::API.rb to ruby-GitHub::API.rb..."
|
42
|
+
commit.added.collect{|c| c.filename} # => ["init.rb", "lib/ruby-GitHub::API.rb"]
|
43
|
+
|
44
|
+
Note that the information is less complete in the 'commits' pull
|
45
|
+
than in the pull for an individual commit. calling 'detailed' on
|
46
|
+
a commit retreived from a 'commits' call will make a 'commit' call
|
47
|
+
for that specific commit.
|
48
|
+
|
49
|
+
Here's a one-liner that uses all parts of the Ruby-GitHub library:
|
50
|
+
|
51
|
+
latest_commit_filenames = GitHub::API.user('mbleigh').repositories.first.commits.first.detailed.modified.collect(&:filename)
|
52
|
+
|
53
|
+
= RESOURCES:
|
54
|
+
|
55
|
+
* GitHub Project: http://GitHub::API.com/mbleigh/ruby-github
|
56
|
+
* E-Mail: michael@intridea.com
|
57
|
+
|
58
|
+
= KNOWN ISSUES/FUTURE DEVELOPMENT:
|
59
|
+
|
60
|
+
Right now this library isn't spec'ed out, that's the top priority moving forward. It
|
61
|
+
will likely also have to evolve substantially as the GitHub API becomes more mature.
|
62
|
+
If you have any questions or requests, don't hesitate to e-mail me!
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/ruby-github.rb'
|
6
|
+
|
7
|
+
Hoe.new('ruby-github', GitHub::VERSION) do |p|
|
8
|
+
p.developer('Michael Bleigh', 'michael@example.com')
|
9
|
+
p.remote_rdoc_dir = ''
|
10
|
+
p.extra_deps = ["mash >= 0.0.2", "json"]
|
11
|
+
end
|
12
|
+
|
13
|
+
# vim: syntax=Ruby
|
data/lib/ruby-github.rb
CHANGED
@@ -1,81 +1,57 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'json'
|
3
3
|
require 'open-uri'
|
4
|
+
require 'mash'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
if repo
|
10
|
-
url += "/#{repo}"
|
11
|
-
url += commit ? "/commit/#{commit}" : "/commits/#{branch}"
|
12
|
-
end
|
13
|
-
|
14
|
-
GitHub::Hash.new(JSON.parse(open(url).read),user,repo)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Fetches information about the specified user name.
|
18
|
-
def self.user(user)
|
19
|
-
self.grab(user).user
|
20
|
-
end
|
6
|
+
module GitHub
|
7
|
+
VERSION = "0.0.2"
|
8
|
+
class API
|
9
|
+
BASE_URL = "http://github.com/api/v1/json"
|
21
10
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
# Fetches information about the specified user name.
|
12
|
+
def self.user(user)
|
13
|
+
url = BASE_URL + "/#{user}"
|
14
|
+
GitHub::User.new(JSON.parse(open(url).read)["user"])
|
15
|
+
end
|
26
16
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
class GitHub::Hash < Hash #:nodoc: all
|
34
|
-
def initialize(hash = nil, user = nil, repo = nil, obj = nil)
|
35
|
-
super(obj)
|
36
|
-
|
37
|
-
@user = user
|
38
|
-
@repo = repo
|
39
|
-
|
40
|
-
if hash && hash.is_a?(Hash)
|
41
|
-
hash.each do |k,v|
|
42
|
-
v = ::GitHub::Hash.new(v,user,repo,obj) if v.is_a?(Hash) && !v.is_a?(::GitHub::Hash)
|
43
|
-
if v.is_a?(Array)
|
44
|
-
v = v.collect{|potential_hash|
|
45
|
-
potential_hash = ::GitHub::Hash.new(potential_hash,user,repo,obj) if potential_hash.is_a?(Hash) && !potential_hash.is_a?(::GitHub::Hash)
|
46
|
-
potential_hash
|
47
|
-
}
|
48
|
-
end
|
49
|
-
self[k] = v
|
50
|
-
end
|
17
|
+
# Fetches the commits for a given repository.
|
18
|
+
def self.commits(user,repository,branch="master")
|
19
|
+
url = BASE_URL + "/#{user}/#{repository}/commits/#{branch}"
|
20
|
+
JSON.parse(open(url).read)["commits"].collect{ |c|
|
21
|
+
GitHub::Commit.new(c.merge(:user => user, :repository => repository))
|
22
|
+
}
|
51
23
|
end
|
52
|
-
end
|
53
24
|
|
54
|
-
|
55
|
-
|
25
|
+
# Fetches a single commit for a repository.
|
26
|
+
def self.commit(user,repository,commit)
|
27
|
+
url = BASE_URL + "/#{user}/#{repository}/commit/#{commit}"
|
28
|
+
GitHub::Commit.new(JSON.parse(open(url).read).merge(:user => user, :repository => repository))
|
29
|
+
end
|
56
30
|
end
|
57
31
|
|
58
|
-
|
59
|
-
|
60
|
-
|
32
|
+
class Repository < Mash
|
33
|
+
def commits
|
34
|
+
::GitHub::API.commits(user,name)
|
35
|
+
end
|
61
36
|
end
|
62
37
|
|
63
|
-
|
64
|
-
|
65
|
-
|
38
|
+
class User < Mash
|
39
|
+
def initialize(hash = nil)
|
40
|
+
@user = hash["login"] if hash
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
def repositories=(repo_array)
|
45
|
+
puts self.inspect
|
46
|
+
self["repositories"] = repo_array.collect{|r| ::GitHub::Repository.new(r.merge(:user => login || @user))}
|
47
|
+
end
|
66
48
|
end
|
67
49
|
|
68
|
-
|
69
|
-
if
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
elsif method_name.to_s == "commits" && self["name"] && self["url"]
|
74
|
-
GitHub.commits(@user, name)
|
75
|
-
elsif method_name.to_s == "detailed" && self["id"] && self["message"]
|
76
|
-
GitHub.commit(@user,@repo,self["id"])
|
77
|
-
else
|
78
|
-
super
|
50
|
+
class Commit < Mash
|
51
|
+
# if a method only available to a detailed commit is called,
|
52
|
+
# automatically fetch it from the API
|
53
|
+
def detailed
|
54
|
+
::GitHub::API.commit(user,repository,id)
|
79
55
|
end
|
80
56
|
end
|
81
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,9 +9,18 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-04-
|
12
|
+
date: 2008-04-12 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mash >= 0.0.2
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
15
24
|
- !ruby/object:Gem::Dependency
|
16
25
|
name: json
|
17
26
|
version_requirement:
|
@@ -21,24 +30,38 @@ dependencies:
|
|
21
30
|
- !ruby/object:Gem::Version
|
22
31
|
version: "0"
|
23
32
|
version:
|
24
|
-
|
25
|
-
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: hoe
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.5.1
|
41
|
+
version:
|
42
|
+
description: Ruby-GitHub is a simple wrapper library for the evolving GitHub API.
|
43
|
+
email:
|
44
|
+
- michael@example.com
|
26
45
|
executables: []
|
27
46
|
|
28
47
|
extensions: []
|
29
48
|
|
30
49
|
extra_rdoc_files:
|
31
|
-
-
|
32
|
-
-
|
50
|
+
- History.txt
|
51
|
+
- Manifest.txt
|
52
|
+
- README.txt
|
33
53
|
files:
|
54
|
+
- History.txt
|
55
|
+
- Manifest.txt
|
56
|
+
- README.txt
|
57
|
+
- Rakefile
|
34
58
|
- lib/ruby-github.rb
|
35
|
-
- README
|
36
|
-
- LICENSE
|
37
59
|
has_rdoc: true
|
38
|
-
homepage:
|
60
|
+
homepage:
|
39
61
|
post_install_message:
|
40
|
-
rdoc_options:
|
41
|
-
|
62
|
+
rdoc_options:
|
63
|
+
- --main
|
64
|
+
- README.txt
|
42
65
|
require_paths:
|
43
66
|
- lib
|
44
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -55,10 +78,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
78
|
version:
|
56
79
|
requirements: []
|
57
80
|
|
58
|
-
rubyforge_project:
|
81
|
+
rubyforge_project: ruby-github
|
59
82
|
rubygems_version: 1.1.0
|
60
83
|
signing_key:
|
61
84
|
specification_version: 2
|
62
|
-
summary:
|
85
|
+
summary: Ruby-GitHub is a simple wrapper library for the evolving GitHub API.
|
63
86
|
test_files: []
|
64
87
|
|
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2008 Michael Bleigh and Intridea, Inc.
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person
|
4
|
-
obtaining a copy of this software and associated documentation
|
5
|
-
files (the "Software"), to deal in the Software without
|
6
|
-
restriction, including without limitation the rights to use,
|
7
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
copies of the Software, and to permit persons to whom the
|
9
|
-
Software is furnished to do so, subject to the following
|
10
|
-
conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be
|
13
|
-
included in all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
data/README
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
== Ruby-GitHub
|
2
|
-
|
3
|
-
Ruby-GitHub is a simple wrapper library for the evolving GitHub API.
|
4
|
-
|
5
|
-
= Usage
|
6
|
-
|
7
|
-
require 'ruby-github'
|
8
|
-
|
9
|
-
user = GitHub.user('mbleigh')
|
10
|
-
user.name # => "Michael Bleigh"
|
11
|
-
user.repositories # => array of repositories
|
12
|
-
user.repositories.last.name # => "ruby-github"
|
13
|
-
user.repositories.last.url # => "http://github.com/mbleigh/ruby-github"
|
14
|
-
user.repositories.last.commits # => array of commits (see below)
|
15
|
-
|
16
|
-
commits = GitHub.commits('mbleigh','ruby-github')
|
17
|
-
commits.first.message # => "Moved github.rb to ruby-github.rb..."
|
18
|
-
commits.first.id # => "1d8c21062e11bb1ecd51ab840aa13d906993f3f7"
|
19
|
-
|
20
|
-
# these two lines are equivalent
|
21
|
-
commit = commits.first.detailed
|
22
|
-
commit = GitHub.commit('mbleigh','ruby-github','1d8c21062e11bb1ecd51ab840aa13d906993f3f7')
|
23
|
-
|
24
|
-
commit.message # => "Moved github.rb to ruby-github.rb..."
|
25
|
-
commit.added.collect{|c| c.filename} # => ["init.rb", "lib/ruby-github.rb"]
|
26
|
-
|
27
|
-
Note that the information is less complete in the 'commits' pull
|
28
|
-
than in the pull for an individual commit. calling 'detailed' on
|
29
|
-
a commit retreived from a 'commits' call will make a 'commit' call
|
30
|
-
for that specific commit.
|
31
|
-
|
32
|
-
= Resources
|
33
|
-
|
34
|
-
* GitHub Project: http://github.com/mbleigh/ruby-github
|
35
|
-
* E-Mail: michael@intridea.com
|