technicalpickles-le-git 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Josh Nichols
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,28 @@
1
+ h1. Le Git
2
+
3
+ bq. French for "Ruby wrapper around the Github API (v2)".
4
+
5
+ Le Git provides a Ruby wrapper around the "The Github API":http://develop.github.com using "rest-client":http://rdoc.info/projects/adamwiggins/rest-client and "happymapper":http://rdoc.info/projects/jnunemaker/happymapper.
6
+
7
+ h2. Example usage
8
+
9
+ <pre>
10
+ require 'rubygems'
11
+ require 'le_git'
12
+
13
+ >> user = Github::User.find("dancroak")
14
+ => #<Github::User:0x110655c @followers=50, @location="Boston", @repos=18, @language="Ruby", @created=#<DateTime: 42413926183/17280,0,2299161>, type"user", fullname"Dan Croak", actions35, name"dancroak", pushed#<DateTime: 106054886255767/43200000,0,2299161, @username="dancroak", @score=3.8655705, @id="user-198">
15
+
16
+ >> repository = user.repositories.last
17
+ => #<Github::Repository:0x301100 @private=false, @forks=0, @url="http://github.com/dancroak/le-git", @homepage="", @watchers=1, @name="le-git", @description="Ruby wrapper for the GitHub API v2.", @fork=true, @owner="dancroak">
18
+
19
+ >> repository.commits.first
20
+ => #<Github::Commit:0x12db33c @message="updating Repository model to use v2 API. associated User & Repository models. filled out complete API for User.", @tree="d27ed042222fe8a55681e1af260e3eb2847e9f33", @url="http://github.com/dancroak/le-git/commit/1f0111c91344062052f65922171d220a06810d4a", @id="1f0111c91344062052f65922171d220a06810d4a">
21
+ </pre>
22
+
23
+ h2. Maintainers
24
+
25
+ Running the test suite requires:
26
+
27
+ sudo gem install rest-client happymapper fakeweb jeremymcanally-context jeremymcanally-matchy jeremymcanally-pending thoughtbot-quietbacktrace redgreen rcov
28
+
data/lib/le_git.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'happymapper'
2
+ require 'rest_client'
3
+
4
+ module Github
5
+ autoload :User, 'le_git/user'
6
+ autoload :Repository, 'le_git/repository'
7
+ autoload :Commit, 'le_git/commit'
8
+ autoload :ApiResources, 'le_git/resources'
9
+ end
@@ -0,0 +1,18 @@
1
+ module Github
2
+ class Commit
3
+ include HappyMapper
4
+
5
+ element :message, String
6
+ element :url, String
7
+ element :id, String
8
+ element :tree, String
9
+
10
+ def self.master(repo_owner, repo_name)
11
+ xml = list_commits_resource(repo_owner, repo_name).get
12
+ parse(xml)
13
+ end
14
+
15
+ protected
16
+ extend ApiResources
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ module Github
2
+ class Repository
3
+ include HappyMapper
4
+
5
+ element :description, String
6
+ element :name, String
7
+ element :private, Boolean
8
+ element :url, String
9
+ element :fork, Boolean
10
+ element :watchers, Integer
11
+ element :forks, Integer
12
+ element :owner, String
13
+ element :homepage, String
14
+
15
+ def self.user(name)
16
+ xml = show_repo_resource(name).get
17
+ parse(xml)
18
+ end
19
+
20
+ def commits(branch = "master")
21
+ Github::Commit.master(owner, name)
22
+ end
23
+
24
+ protected
25
+ extend ApiResources
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ module Github
2
+ class User
3
+ include HappyMapper
4
+
5
+ element :score, Float
6
+ element :name, String
7
+ element :actions, Integer
8
+ element :language, String
9
+ element :followers, Integer
10
+ element :username, String
11
+ element :type, String
12
+ element :fullname, String
13
+ element :repos, Integer
14
+ element :id, String
15
+ element :pushed, DateTime
16
+ element :created, DateTime
17
+ element :location, String
18
+
19
+ def self.find(username)
20
+ xml = search_user_resource(username).get
21
+ users = parse(xml)
22
+ users.first
23
+ end
24
+
25
+ def repositories
26
+ Github::Repository.user(name)
27
+ end
28
+
29
+ protected
30
+ extend ApiResources
31
+ end
32
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'le_git'
@@ -0,0 +1,79 @@
1
+ require File.join(File.dirname(__FILE__), '/test_helper.rb')
2
+
3
+ class GithubCommitTest < Test::Unit::TestCase
4
+ context "given a repository, master commits" do
5
+ setup do
6
+ uri = "http://github.com:80/api/v2/xml/commits/list/dancroak/le-git/master"
7
+ fixture_path = File.join(File.dirname(__FILE__),
8
+ 'fixtures',
9
+ 'master_commits.xml')
10
+
11
+ FakeWeb.register_uri(uri, :response => fixture_path)
12
+
13
+ begin
14
+ @commits = Github::Commit.master("dancroak", "le-git")
15
+ rescue # can't figure out Net::HTTPBadResponse: wrong status line
16
+ @commits = Github::Commit.parse(File.read(fixture_path))
17
+ end
18
+ end
19
+
20
+ test "size" do
21
+ @commits.size.should == 30
22
+ end
23
+
24
+ context "first commit" do
25
+ setup do
26
+ @commit = @commits.first
27
+ end
28
+
29
+ test "#message" do
30
+ @commit.message.should == "updating Repository model to use v2 API. associated User & Repository models. filled out complete API for User."
31
+ end
32
+
33
+ test "#parents size" do
34
+ pending "how to do arrays?" do
35
+ @commit.parents.size.should == 1
36
+ @commits.parents.first.id.should == "690c79a261ed5b078c08742b796cb3056f685698"
37
+ end
38
+ end
39
+
40
+ test "#url" do
41
+ @commit.url.should == "http://github.com/dancroak/le-git/commit/1f0111c91344062052f65922171d220a06810d4a"
42
+ end
43
+
44
+ test "#author" do
45
+ pending "how to do arrays?" do
46
+ @commit.author.name.should == "Dan Croak"
47
+ @commit.author.email.should == "dcroak@thoughtbot.com"
48
+ end
49
+ end
50
+
51
+ test "#id" do
52
+ @commit.id.should == "1f0111c91344062052f65922171d220a06810d4a"
53
+ end
54
+
55
+ test "#commited_date" do
56
+ pending "HappyMapper can't handle nodes with dashes" do
57
+ @commit.committed_date.should == Date.parse("2009-05-25T19:11:27-07:00")
58
+ end
59
+ end
60
+
61
+ test "#authored_date" do
62
+ pending "HappyMapper can't handle nodes with dashes" do
63
+ @commit.authored_date.should == Date.parse("2009-05-25T19:11:27-07:00")
64
+ end
65
+ end
66
+
67
+ test "#tree" do
68
+ @commit.tree.should == "d27ed042222fe8a55681e1af260e3eb2847e9f33"
69
+ end
70
+
71
+ test "#committer" do
72
+ pending "how to do arrays?" do
73
+ @commit.committer.name.should == "Dan Croak"
74
+ @commit.committer.email.should == "dcroak@thoughtbot.com"
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,104 @@
1
+ require File.join(File.dirname(__FILE__), '/test_helper.rb')
2
+
3
+ class GithubRepositoryTest < Test::Unit::TestCase
4
+ context "a Github::Repository found via user" do
5
+ setup do
6
+ fixture_path = File.join(File.dirname(__FILE__),
7
+ 'fixtures',
8
+ 'user_repositories.xml')
9
+ FakeWeb.register_uri('http://github.com/api/v2/xml/repos/show/dancroak',
10
+ :response => fixture_path)
11
+
12
+ @repositories = Github::Repository.user("dancroak")
13
+ end
14
+
15
+ test "size" do
16
+ @repositories.size.should == 19
17
+ end
18
+
19
+ context "first" do
20
+ setup do
21
+ @repository = @repositories.first
22
+ end
23
+
24
+ test "#description" do
25
+ @repository.description.should == "Rails plugin. Force major browsers (IE, Firefox, Safari) to reload a page, even when triggered by 'back' button."
26
+ end
27
+
28
+ test "#name" do
29
+ @repository.name.should == "no_cache"
30
+ end
31
+
32
+ test "#private" do
33
+ @repository.private.should == false
34
+ end
35
+
36
+ test "#url" do
37
+ @repository.url.should == "http://github.com/dancroak/no_cache"
38
+ end
39
+
40
+ test "#fork" do
41
+ @repository.fork.should == false
42
+ end
43
+
44
+ test "#watchers" do
45
+ @repository.watchers.should == 10
46
+ end
47
+
48
+ test "#forks" do
49
+ @repository.forks.should == 0
50
+ end
51
+
52
+ test "#owner" do
53
+ @repository.owner.should == "dancroak"
54
+ end
55
+
56
+ test "#homepage" do
57
+ @repository.homepage.should == "http://giantrobots.thoughtbot.com"
58
+ end
59
+
60
+ context "master commits" do
61
+ setup do
62
+ uri = "http://github.com:80/api/v2/xml/commits/list/dancroak/le-git/master"
63
+ fixture_path = File.join(File.dirname(__FILE__),
64
+ 'fixtures',
65
+ 'master_commits.xml')
66
+
67
+ FakeWeb.register_uri(uri, :response => fixture_path)
68
+
69
+ begin
70
+ @commits = @repository.commits
71
+ rescue # can't figure out Net::HTTPBadResponse: wrong status line
72
+ @commits = Github::Commit.parse(File.read(fixture_path))
73
+ end
74
+ end
75
+
76
+ test "size" do
77
+ @commits.size.should == 30
78
+ end
79
+
80
+ context "first commit" do
81
+ setup do
82
+ @commit = @commits.first
83
+ end
84
+
85
+ test "#message" do
86
+ @commit.message.should == "updating Repository model to use v2 API. associated User & Repository models. filled out complete API for User."
87
+ end
88
+
89
+ test "#url" do
90
+ @commit.url.should == "http://github.com/dancroak/le-git/commit/1f0111c91344062052f65922171d220a06810d4a"
91
+ end
92
+
93
+ test "#id" do
94
+ @commit.id.should == "1f0111c91344062052f65922171d220a06810d4a"
95
+ end
96
+
97
+ test "#tree" do
98
+ @commit.tree.should == "d27ed042222fe8a55681e1af260e3eb2847e9f33"
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,123 @@
1
+ require File.join(File.dirname(__FILE__), '/test_helper.rb')
2
+
3
+ class GithubUserTest < Test::Unit::TestCase
4
+ context "A Github::User" do
5
+ setup do
6
+ fixture_path = File.join(File.dirname(__FILE__), 'fixtures', 'user.xml')
7
+ FakeWeb.register_uri('http://github.com/api/v2/xml/user/search/dancroak',
8
+ :response => fixture_path)
9
+
10
+ @user = Github::User.find('dancroak')
11
+ end
12
+
13
+ test "#score" do
14
+ @user.score.should == 3.8653853
15
+ end
16
+
17
+ test "#name" do
18
+ @user.name.should == "dancroak"
19
+ end
20
+
21
+ test "#actions" do
22
+ @user.actions.should == 35
23
+ end
24
+
25
+ test "#language" do
26
+ @user.language.should == "Ruby"
27
+ end
28
+
29
+ test "#followers" do
30
+ @user.followers.should == 50
31
+ end
32
+
33
+ test "#username" do
34
+ @user.username.should == "dancroak"
35
+ end
36
+
37
+ test "#type" do
38
+ @user.type.should == "user"
39
+ end
40
+
41
+ test "#fullname" do
42
+ @user.fullname.should == "Dan Croak"
43
+ end
44
+
45
+ test "#repos" do
46
+ @user.repos.should == 18
47
+ end
48
+
49
+ test "#id" do
50
+ @user.id.should == "user-198"
51
+ end
52
+
53
+ test "#pushed" do
54
+ @user.pushed.to_s.should == DateTime.new(2009, 5, 22, 17, 15, 11).to_s
55
+ end
56
+
57
+ test "#created" do
58
+ @user.created.to_s.should == DateTime.new(2008, 2, 13, 2, 48, 35).to_s
59
+ end
60
+
61
+ test "#location" do
62
+ @user.location.should == "Boston"
63
+ end
64
+
65
+ context "GETing #repositories" do
66
+ setup do
67
+ fixture_path = File.join(File.dirname(__FILE__),
68
+ 'fixtures',
69
+ 'user_repositories.xml')
70
+ FakeWeb.register_uri('http://github.com/api/v2/xml/repos/show/dancroak',
71
+ :response => fixture_path)
72
+
73
+ @repositories = @user.repositories
74
+ end
75
+
76
+ test "size" do
77
+ @repositories.size.should == 19
78
+ end
79
+
80
+ context "first" do
81
+ setup do
82
+ @repository = @repositories.first
83
+ end
84
+
85
+ test "#description" do
86
+ @repository.description.should == "Rails plugin. Force major browsers (IE, Firefox, Safari) to reload a page, even when triggered by 'back' button."
87
+ end
88
+
89
+ test "#name" do
90
+ @repository.name.should == "no_cache"
91
+ end
92
+
93
+ test "#private" do
94
+ @repository.private.should == false
95
+ end
96
+
97
+ test "#url" do
98
+ @repository.url.should == "http://github.com/dancroak/no_cache"
99
+ end
100
+
101
+ test "#fork" do
102
+ @repository.fork.should == false
103
+ end
104
+
105
+ test "#watchers" do
106
+ @repository.watchers.should == 10
107
+ end
108
+
109
+ test "#forks" do
110
+ @repository.forks.should == 0
111
+ end
112
+
113
+ test "#owner" do
114
+ @repository.owner.should == "dancroak"
115
+ end
116
+
117
+ test "#homepage" do
118
+ @repository.homepage.should == "http://giantrobots.thoughtbot.com"
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,20 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'fake_web'
4
+ require 'quietbacktrace'
5
+ require 'redgreen'
6
+
7
+ FakeWeb.allow_net_connect = false
8
+
9
+ CONTEXT_NOISE = %w(context)
10
+
11
+ #backtrace_cleaner = QuietBacktrace::BacktraceCleaner.new
12
+ #backtrace_cleaner.add_silencer { |line| line.include?(CONTEXT_NOISE) }
13
+
14
+ require 'context'
15
+ require 'matchy'
16
+ require 'pending'
17
+
18
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib') )
19
+ require 'le_git'
20
+
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: technicalpickles-le-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Josh Nichols
8
+ - Dan Croak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-05-25 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rest-client
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: happymapper
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ version:
36
+ description: Ruby wrapper around Github API v2
37
+ email: josh@technicalpickles.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - LICENSE
44
+ - README.textile
45
+ files:
46
+ - LICENSE
47
+ - README.textile
48
+ - lib/le_git.rb
49
+ - lib/le_git/commit.rb
50
+ - lib/le_git/repository.rb
51
+ - lib/le_git/user.rb
52
+ - rails/init.rb
53
+ has_rdoc: false
54
+ homepage: http://github.com/dancroak/le-git
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.2.0
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Ruby wrapper around Github API v2
79
+ test_files:
80
+ - test/github_commit_test.rb
81
+ - test/github_repository_test.rb
82
+ - test/github_user_test.rb
83
+ - test/test_helper.rb