github-v3-api 0.2.0 → 0.3.0

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "github-v3-api"
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Wilger"]
12
- s.date = "2011-12-05"
12
+ s.date = "2012-01-20"
13
13
  s.description = "Ponies"
14
14
  s.email = "johnwilger@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -14,6 +14,18 @@ class GitHubV3API
14
14
  api.list_repos(login)
15
15
  end
16
16
 
17
+ # Returns an array of GitHubV3API::User instances representing the users
18
+ # who are members of the organization
19
+ def members
20
+ api.list_members(login)
21
+ end
22
+
23
+ # Returns an array of GitHubV3API::User instances representing the users
24
+ # who are public members of the organization
25
+ def public_members
26
+ api.list_public_members(login)
27
+ end
28
+
17
29
  private
18
30
 
19
31
  def natural_key
@@ -49,5 +49,26 @@ class GitHubV3API
49
49
  GitHubV3API::Repo.new(@connection.repos, repo_data)
50
50
  end
51
51
  end
52
+
53
+ # Returns an array of GitHubV3API::User instances representing the members
54
+ # who belong to the specified organization.
55
+ #
56
+ # +org_login+:: the string ID of the organization, e.g. "github"
57
+ def list_members(org_login)
58
+ @connection.get("/orgs/#{org_login}/members").map do |user_data|
59
+ GitHubV3API::User.new(@connection.users, user_data)
60
+ end
61
+ end
62
+
63
+ # Returns an array of GitHubV3API::User instances representing the members
64
+ # who belong to the specified organization who have publicly identified
65
+ # themselves as members of this organization.
66
+ #
67
+ # +org_login+:: the string ID of the organization, e.g. "github"
68
+ def list_public_members(org_login)
69
+ @connection.get("/orgs/#{org_login}/public_members").map do |user_data|
70
+ GitHubV3API::User.new(@connection.users, user_data)
71
+ end
72
+ end
52
73
  end
53
74
  end
@@ -11,6 +11,18 @@ class GitHubV3API
11
11
  owner['login']
12
12
  end
13
13
 
14
+ def list_collaborators
15
+ api.list_collaborators(owner_login, name)
16
+ end
17
+
18
+ def list_watchers
19
+ api.list_watchers(owner_login, name)
20
+ end
21
+
22
+ def list_forks
23
+ api.list_forks(owner_login, name)
24
+ end
25
+
14
26
  private
15
27
 
16
28
  def natural_key
@@ -43,5 +43,39 @@ class GitHubV3API
43
43
  rescue RestClient::ResourceNotFound
44
44
  raise NotFound, "The repository #{user}/#{repo_name} does not exist or is not visible to the user."
45
45
  end
46
+
47
+ # Returns an array of GitHubV3API::User instances for the collaborators of the
48
+ # specified +user+ and +repo_name+.
49
+ #
50
+ # +user+:: the string ID of the user, e.g. "octocat"
51
+ # +repo_name+:: the string ID of the repository, e.g. "hello-world"
52
+ def list_collaborators(user, repo_name)
53
+ @connection.get("/repos/#{user}/#{repo_name}/collaborators").map do |user_data|
54
+ GitHubV3API::User.new(@connection.users, user_data)
55
+ end
56
+ end
57
+
58
+ # Returns an array of GitHubV3API::User instances containing the users who are
59
+ # watching the repository specified by +user+ and +repo_name+.
60
+ #
61
+ # +user+:: the string ID of the user, e.g. "octocat"
62
+ # +repo_name+:: the string ID of the repository, e.g. "hello-world"
63
+ def list_watchers(user, repo_name)
64
+ @connection.get("/repos/#{user}/#{repo_name}/watchers").map do |user_data|
65
+ GitHubV3API::User.new(@connection.users, user_data)
66
+ end
67
+ end
68
+
69
+ # Returns an array of GitHubV3API::Repo instances containing the repositories
70
+ # which were forked from the repository specified by +user+ and +repo_name+.
71
+ #
72
+ # +user+:: the string ID of the user, e.g. "octocat"
73
+ # +repo_name+:: the string ID of the repository, e.g. "hello-world"
74
+ def list_forks(user, repo_name)
75
+ @connection.get("/repos/#{user}/#{repo_name}/forks").map do |repo_data|
76
+ GitHubV3API::Repo.new(self, repo_data)
77
+ end
78
+ end
79
+
46
80
  end
47
81
  end
data/spec/org_spec.rb CHANGED
@@ -44,4 +44,25 @@ describe GitHubV3API::Org do
44
44
  org.repos.should == [:repo1, :repo2]
45
45
  end
46
46
  end
47
+
48
+ describe '#members'do
49
+ it 'returns an array of User objects who are members of this org' do
50
+ api = mock(GitHubV3API::OrgsAPI)
51
+ api.should_receive(:list_members).with('github').and_return([:user1, :user2])
52
+
53
+ org = GitHubV3API::Org.new_with_all_data(api, 'login' => 'github')
54
+ org.members.should == [:user1, :user2]
55
+ end
56
+ end
57
+
58
+ describe '#public_members'do
59
+ it 'returns an array of User objects who are public members of this org' do
60
+ api = mock(GitHubV3API::OrgsAPI)
61
+ api.should_receive(:list_public_members).with('github').and_return([:user1, :user2])
62
+
63
+ org = GitHubV3API::Org.new_with_all_data(api, 'login' => 'github')
64
+ org.public_members.should == [:user1, :user2]
65
+ end
66
+ end
67
+
47
68
  end
@@ -39,4 +39,39 @@ describe GitHubV3API::OrgsAPI do
39
39
  api.list_repos('github').should == [:repo1, :repo2]
40
40
  end
41
41
  end
42
+
43
+ describe '#list_members' do
44
+ it 'returns the list of members for the specified org' do
45
+ connection = mock(GitHubV3API, :users => :users_api)
46
+ connection.should_receive(:get).once.with('/orgs/github/members') \
47
+ .and_return([:user_hash1, :user_hash2])
48
+
49
+ GitHubV3API::User.should_receive(:new).with(:users_api, :user_hash1) \
50
+ .and_return(:user1)
51
+
52
+ GitHubV3API::User.should_receive(:new).with(:users_api, :user_hash2) \
53
+ .and_return(:user2)
54
+
55
+ api = GitHubV3API::OrgsAPI.new(connection)
56
+ api.list_members('github').should == [:user1, :user2]
57
+ end
58
+ end
59
+
60
+ describe '#list_public_members' do
61
+ it 'returns the list of public members for the specified org' do
62
+ connection = mock(GitHubV3API, :users => :users_api)
63
+ connection.should_receive(:get).once.with('/orgs/github/public_members') \
64
+ .and_return([:user_hash1, :user_hash2])
65
+
66
+ GitHubV3API::User.should_receive(:new).with(:users_api, :user_hash1) \
67
+ .and_return(:user1)
68
+
69
+ GitHubV3API::User.should_receive(:new).with(:users_api, :user_hash2) \
70
+ .and_return(:user2)
71
+
72
+ api = GitHubV3API::OrgsAPI.new(connection)
73
+ api.list_public_members('github').should == [:user1, :user2]
74
+ end
75
+ end
76
+
42
77
  end
data/spec/repo_spec.rb CHANGED
@@ -40,4 +40,41 @@ describe GitHubV3API::Repo do
40
40
  repo.owner_login.should == 'octocat'
41
41
  end
42
42
  end
43
+
44
+ describe '#list_collaborators' do
45
+ it 'returns an array of User objects who are collaborating on this repo' do
46
+ api = mock(GitHubV3API::ReposAPI)
47
+ api.should_receive(:list_collaborators).once.with(
48
+ 'octocat', 'hello-world').and_return([:user1, :user2, :user3])
49
+
50
+ repo = GitHubV3API::Repo.new(api, 'name' => 'hello-world',
51
+ 'owner' => {'login' => 'octocat'})
52
+ repo.list_collaborators.should == [:user1, :user2, :user3]
53
+ end
54
+ end
55
+
56
+ describe '#list_watchers' do
57
+ it 'returns an array of User objects who are watching this repo' do
58
+ api = mock(GitHubV3API::ReposAPI)
59
+ api.should_receive(:list_watchers).once.with(
60
+ 'octocat', 'hello-world').and_return([:user1, :user2, :user3])
61
+
62
+ repo = GitHubV3API::Repo.new(api, 'name' => 'hello-world',
63
+ 'owner' => {'login' => 'octocat'})
64
+ repo.list_watchers.should == [:user1, :user2, :user3]
65
+ end
66
+ end
67
+
68
+ describe '#list_forks' do
69
+ it 'returns an array of Repo objects which were forked from this repo' do
70
+ api = mock(GitHubV3API::ReposAPI)
71
+ api.should_receive(:list_forks).once.with(
72
+ 'octocat', 'hello-world').and_return([:repo1, :repo2, :repo3])
73
+
74
+ repo = GitHubV3API::Repo.new(api, 'name' => 'hello-world',
75
+ 'owner' => {'login' => 'octocat'})
76
+ repo.list_forks.should == [:repo1, :repo2, :repo3]
77
+ end
78
+ end
79
+
43
80
  end
@@ -30,4 +30,52 @@ describe GitHubV3API::ReposAPI do
30
30
  lambda { api.get('octocat', 'hello-world') }.should raise_error(GitHubV3API::NotFound)
31
31
  end
32
32
  end
33
+
34
+ describe "#list_collaborators" do
35
+ it 'returns a list of Users who are collaborating on the specified repo' do
36
+ connection = mock(GitHubV3API)
37
+ connection.should_receive(:get).with(
38
+ '/repos/octocat/hello-world/collaborators').and_return([:user_hash1, :user_hash2])
39
+ connection.should_receive(:users).twice.and_return(:users_api)
40
+ api = GitHubV3API::ReposAPI.new(connection)
41
+
42
+ GitHubV3API::User.should_receive(:new).with(:users_api, :user_hash1).and_return(:user1)
43
+ GitHubV3API::User.should_receive(:new).with(:users_api, :user_hash2).and_return(:user2)
44
+
45
+ collaborators = api.list_collaborators('octocat', 'hello-world')
46
+ collaborators.should == [:user1, :user2]
47
+ end
48
+ end
49
+
50
+ describe "#list_watchers" do
51
+ it 'returns a list of Users who are watching the specified repo' do
52
+ connection = mock(GitHubV3API)
53
+ connection.should_receive(:get).with(
54
+ '/repos/octocat/hello-world/watchers').and_return([:user_hash1, :user_hash2])
55
+ connection.should_receive(:users).twice.and_return(:users_api)
56
+ api = GitHubV3API::ReposAPI.new(connection)
57
+
58
+ GitHubV3API::User.should_receive(:new).with(:users_api, :user_hash1).and_return(:user1)
59
+ GitHubV3API::User.should_receive(:new).with(:users_api, :user_hash2).and_return(:user2)
60
+
61
+ watchers = api.list_watchers('octocat', 'hello-world')
62
+ watchers.should == [:user1, :user2]
63
+ end
64
+ end
65
+
66
+ describe "#list_forks" do
67
+ it 'returns a list of Repos which were forked from the specified repo' do
68
+ connection = mock(GitHubV3API)
69
+ connection.should_receive(:get).with(
70
+ '/repos/octocat/hello-world/forks').and_return([:repo_hash1, :repo_hash2])
71
+ api = GitHubV3API::ReposAPI.new(connection)
72
+
73
+ GitHubV3API::Repo.should_receive(:new).with(api, :repo_hash1).and_return(:fork1)
74
+ GitHubV3API::Repo.should_receive(:new).with(api, :repo_hash2).and_return(:fork2)
75
+
76
+ forks = api.list_forks('octocat', 'hello-world')
77
+ forks.should == [:fork1, :fork2]
78
+ end
79
+ end
80
+
33
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-v3-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-05 00:00:00.000000000Z
12
+ date: 2012-01-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &2168649880 !ruby/object:Gem::Requirement
16
+ requirement: &2173811200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.6.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2168649880
24
+ version_requirements: *2173811200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &2168649400 !ruby/object:Gem::Requirement
27
+ requirement: &2173810720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.5.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2168649400
35
+ version_requirements: *2173810720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2168648920 !ruby/object:Gem::Requirement
38
+ requirement: &2173810240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.3.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2168648920
46
+ version_requirements: *2173810240
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &2168648440 !ruby/object:Gem::Requirement
49
+ requirement: &2173809740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2168648440
57
+ version_requirements: *2173809740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &2168647960 !ruby/object:Gem::Requirement
60
+ requirement: &2173809220 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.6.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2168647960
68
+ version_requirements: *2173809220
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rcov
71
- requirement: &2168663860 !ruby/object:Gem::Requirement
71
+ requirement: &2173808700 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2168663860
79
+ version_requirements: *2173808700
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: reek
82
- requirement: &2168663380 !ruby/object:Gem::Requirement
82
+ requirement: &2173808180 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.2.8
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2168663380
90
+ version_requirements: *2173808180
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: roodi
93
- requirement: &2168662900 !ruby/object:Gem::Requirement
93
+ requirement: &2173807580 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: 2.1.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2168662900
101
+ version_requirements: *2173807580
102
102
  description: Ponies
103
103
  email: johnwilger@gmail.com
104
104
  executables: []
@@ -154,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  segments:
156
156
  - 0
157
- hash: -423517937058714579
157
+ hash: -3441059539014864528
158
158
  required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  none: false
160
160
  requirements: