hubruby 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -5,3 +5,7 @@
5
5
  === 0.0.4 2010-09-03
6
6
 
7
7
  * Refactorings and Specifications
8
+
9
+ === 0.1.0 2011-07-31
10
+
11
+ * Initial support to the GitHub API v3
data/Rakefile CHANGED
@@ -1,24 +1,25 @@
1
- require 'rubygems'
2
- gem 'hoe', '>= 2.1.0'
3
- require 'hoe'
4
- require 'fileutils'
5
- require './lib/hubruby'
6
-
7
- Hoe.plugin :newgem
8
- # Hoe.plugin :website
9
- # Hoe.plugin :cucumberfeatures
10
-
11
- # Generate all the Rake tasks
12
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
- $hoe = Hoe.spec 'hubruby' do
14
- self.developer 'Diógenes Falcão', 'diogenes {d-o-t} araujo {at} gmail.com'
15
- self.rubyforge_name = self.name
16
- self.extra_deps = [['httparty','= 0.6.1']]
17
- self.version = '0.0.4'
18
- end
19
-
20
- require 'newgem/tasks'
21
- Dir['tasks/**/*.rake'].each { |t| load t }
22
-
23
- # remove_task :default
24
- task :default => [:spec]
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/hubruby'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'hubruby' do
14
+ self.summary = 'A simple Ruby library to access the current GitHub API (v3)'
15
+ self.developer 'Diógenes Falcão', 'diogenes {d-o-t} araujo {at} gmail.com'
16
+ self.rubyforge_name = self.name
17
+ self.extra_deps = [['httparty','= 0.6.1']]
18
+ self.version = '0.1.0'
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # remove_task :default
25
+ task :default => [:spec]
data/TODO CHANGED
@@ -1,8 +0,0 @@
1
- TODO
2
-
3
- Support to following URLs:
4
- * /user/search/ <-- Search users by query
5
- * /repos/show/#{username}/#{repo}/languages
6
- * /repos/show/#{username}/#{repo}/contributors
7
- * /repos/show/#{username}/#{repo}/collaborators
8
- * /repos/search/#{escaped query}
data/hubruby.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{hubruby}
5
- s.version = "0.0.4"
5
+ s.version = "0.1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Di\303\263genes Falc\303\243o"]
9
- s.date = %q{2010-09-03}
9
+ s.date = %q{2011-07-31}
10
10
  s.description = %q{A simple Ruby library for accessing the current GitHub API (v2).}
11
11
  s.email = ["diogenes {d-o-t} araujo {at} gmail.com"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
@@ -15,25 +15,25 @@ Gem::Specification.new do |s|
15
15
  s.rdoc_options = ["--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{hubruby}
18
- s.rubygems_version = %q{1.3.6}
18
+ s.rubygems_version = %q{1.3.7}
19
19
  s.summary = %q{A simple Ruby library for accessing the current GitHub API (v2).}
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
23
  s.specification_version = 3
24
24
 
25
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
26
  s.add_runtime_dependency(%q<httparty>, ["= 0.6.1"])
27
27
  s.add_development_dependency(%q<rubyforge>, [">= 2.0.4"])
28
- s.add_development_dependency(%q<hoe>, [">= 2.6.1"])
28
+ s.add_development_dependency(%q<hoe>, [">= 2.6.2"])
29
29
  else
30
30
  s.add_dependency(%q<httparty>, ["= 0.6.1"])
31
31
  s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
32
- s.add_dependency(%q<hoe>, [">= 2.6.1"])
32
+ s.add_dependency(%q<hoe>, [">= 2.6.2"])
33
33
  end
34
34
  else
35
35
  s.add_dependency(%q<httparty>, ["= 0.6.1"])
36
36
  s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
37
- s.add_dependency(%q<hoe>, [">= 2.6.1"])
37
+ s.add_dependency(%q<hoe>, [">= 2.6.2"])
38
38
  end
39
39
  end
@@ -1,49 +1,73 @@
1
1
  module GitHub
2
2
  module Finders
3
3
  def user(login)
4
- j = json("/user/show/#{login}", :user)
4
+ j = json("/users/#{login}")
5
5
  User.from_hash(j)
6
6
  end
7
7
 
8
8
  def following(login)
9
- l = json("/user/show/#{login}/following", :users)
9
+ l = json("/users/#{login}/following")
10
10
  User.users_from_logins(l)
11
11
  end
12
12
 
13
13
  def followers(login)
14
- l = json("/user/show/#{login}/followers", :users)
14
+ l = json("/users/#{login}/followers")
15
15
  User.users_from_logins(l)
16
16
  end
17
17
 
18
18
  def repositories(login)
19
- j = json("/repos/show/#{login}", :repositories)
19
+ j = json("/users/#{login}/repos")
20
20
  Repository.repositories_from_hashes(j)
21
21
  end
22
22
 
23
23
  def watched(login)
24
- j = json("/repos/watched/#{login}", :repositories)
24
+ j = json("/users/#{login}/watched")
25
25
  Repository.repositories_from_hashes(j)
26
26
  end
27
27
 
28
28
  def repository(login, repository_name)
29
- j = json("/repos/show/#{login}/#{repository_name}", :repository)
29
+ j = json("/repos/#{login}/#{repository_name}")
30
30
  Repository.from_hash(j)
31
31
  end
32
32
 
33
33
  def branches(login, repository_name)
34
- json("/repos/show/#{login}/#{repository_name}/branches", :branches)
34
+ json("/repos/#{login}/#{repository_name}/branches")
35
35
  end
36
36
 
37
- def network(login, repository_name)
38
- j = json("/repos/show/#{login}/#{repository_name}/network", :network)
37
+ def forks(login, repository_name)
38
+ j = json("/repos/#{login}/#{repository_name}/forks")
39
39
  Repository.repositories_from_hashes(j)
40
40
  end
41
41
 
42
+ def commits(login, repository_name, branch = 'master')
43
+ h = json("/repos/#{login}/#{repository_name}/commits/#{branch}")
44
+ Commit.commits_from_hashes(h, Repository.new(:owner => login, :name => repository_name))
45
+ end
46
+
47
+ def commit(login, repository_name, commit_id)
48
+ h = json("/repos/#{login}/#{repository_name}/commits/#{commit_id}")
49
+ Commit.from_hash(h, Repository.new(:owner => login, :name => repository_name))
50
+ end
51
+
52
+ def user_organizations(login)
53
+ h = json("/users/#{login}/orgs")
54
+ h.map {|o| Organization.from_hash(o) }
55
+ end
56
+
57
+ def organization_public_repositories(organization_name)
58
+ h = json("/orgs/#{organization_name}/repos")
59
+ h.map {|r| Repository.from_hash(r) }
60
+ end
61
+
62
+ def organization_public_members(organization_name)
63
+ h = json("/orgs/#{organization_name}/members")
64
+ h.map {|u| User.from_hash(u) }
65
+ end
66
+
42
67
  private
43
68
 
44
- def json(path, resource)
45
- response = HTTParty.get('https://github.com/api/v2/json' << path).parsed_response
46
- response[resource.to_s]
69
+ def json(path)
70
+ HTTParty.get('https://api.github.com' << path).parsed_response
47
71
  end
48
72
  end # Finders
49
73
  end # GitHub
@@ -1,23 +1,25 @@
1
- require 'ostruct'
1
+ require 'github/models/base_model'
2
2
 
3
3
  module GitHub
4
- class Repository < OpenStruct
5
- def self.from_hash(h)
6
- new(h)
4
+ class Repository < BaseModel
5
+ def self.repositories_from_hashes(h)
6
+ h.map { |repository_attrs| from_hash(repository_attrs) }
7
7
  end
8
8
 
9
- def self.repositories_from_hashes(h)
10
- h.inject([]) do |repositories, repository_attrs|
11
- repositories << from_hash(repository_attrs)
12
- end
9
+ def owner
10
+ @owner ||= GitHub::User.new(@table[:owner])
13
11
  end
14
12
 
15
13
  def branches
16
- @branches ||= GitHub.branches(self.owner, self.name)
14
+ @branches ||= GitHub.branches(self.owner.login, self.name)
15
+ end
16
+
17
+ def forks
18
+ @forks ||= GitHub.forks(self.owner.login, self.name)
17
19
  end
18
20
 
19
- def network
20
- @network ||= GitHub.network(self.owner, self.name)
21
+ def commit(id)
22
+ GitHub.commit(owner.login, self.name, id)
21
23
  end
22
24
  end
23
25
  end
@@ -1,15 +1,9 @@
1
- require 'ostruct'
1
+ require 'github/models/base_model'
2
2
 
3
3
  module GitHub
4
- class User < OpenStruct
5
- def self.from_hash(h)
6
- new(h)
7
- end
8
-
4
+ class User < BaseModel
9
5
  def self.users_from_logins(logins)
10
- logins.inject([]) do |users, login|
11
- users << from_hash(:login => login)
12
- end
6
+ logins.map { |l| from_hash(:login => l) }
13
7
  end
14
8
 
15
9
  def following
@@ -27,5 +21,9 @@ module GitHub
27
21
  def watched
28
22
  @watched ||= GitHub.watched(self.login)
29
23
  end
24
+
25
+ def organizations
26
+ @organizations ||= GitHub.user_organizations(self.login)
27
+ end
30
28
  end
31
29
  end
data/lib/hubruby.rb CHANGED
@@ -5,7 +5,7 @@ require 'rubygems'
5
5
  require 'httparty'
6
6
 
7
7
  module Hubruby
8
- VERSION = '0.0.4'
8
+ VERSION = '0.1.0'
9
9
 
10
10
  def self.require_all
11
11
  Dir[File.join(File.dirname(__FILE__), %W(github ** *.rb))].each do |f|
@@ -29,7 +29,15 @@ describe GitHub do
29
29
  subject.should respond_to(:branches)
30
30
  end
31
31
 
32
- it "should be able to find the network of a repository" do
33
- subject.should respond_to(:network)
32
+ it "should be able to find the forks of a repository" do
33
+ subject.should respond_to(:forks)
34
+ end
35
+
36
+ it "should be able to find the last commits of a repository branch" do
37
+ subject.should respond_to(:commits)
38
+ end
39
+
40
+ it "should be able to find a commit" do
41
+ subject.should respond_to(:commit)
34
42
  end
35
43
  end
@@ -1,24 +1,35 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe GitHub::Repository do
4
- it "should be instantiable from a hash" do
5
- subject.class.should respond_to(:from_hash)
4
+ subject { GitHub::Repository.new(:name => 'hubruby', :owner => 'diogenes') }
6
5
 
6
+ it "can be instantiated from a hash" do
7
7
  hash = {:name => 'hubruby', :owner => 'diogenes'}
8
8
 
9
9
  repo = GitHub::Repository.from_hash(hash)
10
10
  repo.name.should be_eql 'hubruby'
11
11
  end
12
12
 
13
- it "should be instantiable as a collection from a hash" do
14
- subject.class.should respond_to(:repositories_from_hashes)
13
+ it "should be instantiable from a hash collection" do
14
+ h = [
15
+ {:name => 'hubruby', :owner => 'diogenes'},
16
+ {:name => 'coletivo', :owner => 'diogenes'}
17
+ ]
18
+
19
+ repos = GitHub::Repository.repositories_from_hashes(h)
20
+ repos.should have(2).repositories
21
+ end
22
+
23
+ it "can show its branches" do
24
+ subject.branches.should_not be_empty
15
25
  end
16
26
 
17
- it "should be able to show your branches" do
18
- subject.should respond_to(:branches)
27
+ it "can show its forks" do
28
+ subject.forks.should_not be_empty
19
29
  end
20
30
 
21
- it "should be able to show your network" do
22
- subject.should respond_to(:network)
31
+ it "should be able to find a commit by id" do
32
+ initial_commit_id = '1ec7f79c34e3008e93b7b9210282a743f83db86d'
33
+ subject.commit(initial_commit_id).should_not be_nil
23
34
  end
24
35
  end
@@ -1,39 +1,33 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe GitHub::User do
4
- it "should be instantiable from a hash" do
5
- subject.class.should respond_to(:from_hash)
4
+ subject { GitHub::User.new(:login => 'diogenes') }
6
5
 
7
- hash = {:name => 'Diógenes Falcão', :login => 'diogenes'}
6
+ it 'should be instantiable from a hash' do
7
+ h = {:name => 'Diógenes Falcão', :login => 'diogenes'}
8
8
 
9
- user = GitHub::User.from_hash(hash)
10
- user.login.should be_eql "diogenes"
9
+ user = GitHub::User.from_hash(h)
10
+ user.login.should be_eql 'diogenes'
11
11
  end
12
12
 
13
- it "should be instantiable as a collection from a list of logins" do
14
- subject.class.should respond_to(:users_from_logins)
15
-
16
- logins = ['guy1', 'guy2']
17
-
18
- users = GitHub::User.users_from_logins(logins)
19
- users.first.login.should be_eql 'guy1'
20
- users.last.login.should be_eql 'guy2'
21
- users.size.should be_eql 2
13
+ it 'should be instantiable from a list of logins' do
14
+ users = GitHub::User.users_from_logins(['guy1', 'guy2'])
15
+ users.should have(2).users
22
16
  end
23
17
 
24
- it "should be able to show your following users" do
25
- subject.should respond_to(:following)
18
+ it 'should be able to show its following users' do
19
+ subject.following.should_not be_empty
26
20
  end
27
21
 
28
- it "should be able to show your followers users" do
29
- subject.should respond_to(:followers)
22
+ it 'should be able to show its followers users' do
23
+ subject.followers.should_not be_empty
30
24
  end
31
25
 
32
- it "should be able to show your repositories" do
33
- subject.should respond_to(:repositories)
26
+ it 'should be able to show its repositories' do
27
+ subject.repositories.should_not be_empty
34
28
  end
35
29
 
36
- it "should be able to show your watched repositories" do
37
- subject.should respond_to(:watched)
30
+ it 'should be able to show its watched repositories' do
31
+ subject.watched.should_not be_empty
38
32
  end
39
33
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubruby
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
8
+ - 1
7
9
  - 0
8
- - 4
9
- version: 0.0.4
10
+ version: 0.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - "Di\xC3\xB3genes Falc\xC3\xA3o"
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-09-03 00:00:00 -03:00
18
+ date: 2011-07-31 00:00:00 -03:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: httparty
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - "="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 5
27
30
  segments:
28
31
  - 0
29
32
  - 6
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: rubyforge
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 7
41
46
  segments:
42
47
  - 2
43
48
  - 0
@@ -49,14 +54,16 @@ dependencies:
49
54
  name: hoe
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 19
55
62
  segments:
56
63
  - 2
57
64
  - 6
58
- - 1
59
- version: 2.6.1
65
+ - 2
66
+ version: 2.6.2
60
67
  type: :development
61
68
  version_requirements: *id003
62
69
  description: A simple Ruby library for accessing the current GitHub API (v2).
@@ -101,25 +108,29 @@ rdoc_options:
101
108
  require_paths:
102
109
  - lib
103
110
  required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
104
112
  requirements:
105
113
  - - ">="
106
114
  - !ruby/object:Gem::Version
115
+ hash: 3
107
116
  segments:
108
117
  - 0
109
118
  version: "0"
110
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
111
121
  requirements:
112
122
  - - ">="
113
123
  - !ruby/object:Gem::Version
124
+ hash: 3
114
125
  segments:
115
126
  - 0
116
127
  version: "0"
117
128
  requirements: []
118
129
 
119
130
  rubyforge_project: hubruby
120
- rubygems_version: 1.3.6
131
+ rubygems_version: 1.3.7
121
132
  signing_key:
122
133
  specification_version: 3
123
- summary: A simple Ruby library for accessing the current GitHub API (v2).
134
+ summary: A simple Ruby library to access the current GitHub API (v3)
124
135
  test_files: []
125
136