ruby-github 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +22 -0
- data/README +35 -0
- data/lib/ruby-github.rb +81 -0
- metadata +64 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
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
ADDED
@@ -0,0 +1,35 @@
|
|
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
|
data/lib/ruby-github.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
class GitHub
|
6
|
+
def self.grab(user, repo=nil, branch=nil, commit=nil) #:nodoc:
|
7
|
+
url = "http://github.com/api/v1/json/#{user}"
|
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
|
21
|
+
|
22
|
+
# Fetches the commits for a given repository.
|
23
|
+
def self.commits(user,repository,branch="master")
|
24
|
+
self.grab(user,repository,branch).commits
|
25
|
+
end
|
26
|
+
|
27
|
+
# Fetches a single commit for a repository.
|
28
|
+
def self.commit(user,repository,commit)
|
29
|
+
self.grab(user,repository,nil,commit).commit
|
30
|
+
end
|
31
|
+
end
|
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
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def id
|
55
|
+
self["id"] ? self["id"] : super
|
56
|
+
end
|
57
|
+
|
58
|
+
def [](key)
|
59
|
+
key = key.to_s
|
60
|
+
super
|
61
|
+
end
|
62
|
+
|
63
|
+
def []=(key,value)
|
64
|
+
key = key.to_s
|
65
|
+
super
|
66
|
+
end
|
67
|
+
|
68
|
+
def method_missing(method_name, *args)
|
69
|
+
if (match = method_name.to_s.match(/(.*)=$/)) && args.size == 1
|
70
|
+
self[match[1]] = args.first
|
71
|
+
elsif keys.include?(method_name.to_s)
|
72
|
+
self[method_name]
|
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
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-github
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Bleigh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-04-02 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
description:
|
25
|
+
email: michael@intridea.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
32
|
+
- LICENSE
|
33
|
+
files:
|
34
|
+
- lib/ruby-github.rb
|
35
|
+
- README
|
36
|
+
- LICENSE
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://intridea.com/tags/ruby-github
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.1.0
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: A simple Ruby library for accessing information through the GitHub API.
|
63
|
+
test_files: []
|
64
|
+
|