Skip to content

Commit dd23db9

Browse files
committed
Add repos methods stubs.
1 parent 2458aab commit dd23db9

File tree

5 files changed

+137
-7
lines changed

5 files changed

+137
-7
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ source "http://rubygems.org"
66
# Add dependencies to develop your gem here.
77
# Include everything needed to run rake, tests, features, etc.
88
group :development do
9-
gem "rspec", "~> 2.3.0"
9+
gem "rspec", "~> 2.4.0"
1010
gem "cucumber", ">= 0"
1111
gem "bundler", "~> 1.0.0"
1212
gem "jeweler", "~> 1.6.4"

lib/github/api.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ def initialize
1515
def _validate_user_repo_params
1616

1717
end
18+
19+
def _normalize_params_keys(params)
20+
21+
end
1822
end
1923
end

lib/github/repos.rb

Lines changed: 132 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,58 @@
11
module Repos
2-
2+
3+
DEFAULT_REPO_OPTIONS = {
4+
"homepage" => "https://github.com",
5+
"public" => true,
6+
"has_issues" => true,
7+
"has_wiki" => true,
8+
"has_downloads" => true
9+
}
10+
11+
VALID_REPO_TYPES = [ "all", "public", "private", "member" ]
12+
13+
# List branches
14+
#
315
# GET /repos/:user/:repo/branches
416
def branches(user, repo, params={})
517
_validate_user_repo_params
618
response = get("/repos#{user}/#{repo}", options)
719
end
820

21+
922
def collaborators
1023

1124
end
1225

1326
def commits
1427

1528
end
29+
30+
# Create a new repository for the autheticated user
31+
#
32+
# POST /user/repos
33+
#
34+
# Examples:
35+
# client = Client.new
36+
# client.create(:name => 'my_repo_name')
37+
#
38+
#
39+
# Create a new repository in this organisation. The authenticated user
40+
# must be a member of this organisation
41+
#
42+
# POST /orgs/:org/repos
43+
#
44+
# Examples:
45+
# client = Client.new
46+
# client.create('my-repo-name', :org => 'my-organisation')
47+
#
48+
def create(name, params = {})
49+
DEFAULT_REPO_OPTIONS.merge(params)
50+
if (org = params.delete("org"))
51+
post("/orgs/#{org}/repos", params)
52+
else
53+
post("/user/repos", params)
54+
end
55+
end
1656

1757
# List contributors
1858
#
@@ -25,8 +65,98 @@ def contributors(user, repo, flag=nil)
2565
get("/repos/#{user}/#{repo}/contributors", flag)
2666
end
2767

28-
def tags(params={})
68+
# Provides access to Github::Repos::Downloads
69+
def downloades
70+
71+
end
2972

73+
# Edit a repository
74+
#
75+
# POST /repos/:user/:repo
76+
#
77+
# Examples:
78+
# client = Client.new
79+
# client.edit
80+
#
81+
def edit(user, repo, name, params = {})
82+
post("/repos/#{user}/#{repo}", params)
83+
end
84+
85+
# Provides access to Github::Repos::Forks
86+
def forks
87+
88+
end
89+
90+
# Get a repository
91+
#
92+
# GET /repos/:user/:repo
93+
#
94+
# Examples:
95+
#
96+
# client = Client.new
97+
# client.get_repo('my-username', 'my-repo-name')
98+
#
99+
def get(user, repo)
100+
get("/repos/#{user}/#{repo}") # TODO change request methods CLASH!!!
101+
end
102+
103+
# Provides access to Github::Repos::Keys
104+
def keys
105+
106+
end
107+
108+
# List languages
109+
#
110+
# GET /repos/:user/:repo/languages
111+
def languages(user, repo)
112+
get("/repos/#{user}/#{repo}/languages")
113+
end
114+
115+
# List repositories for the authenticated user
116+
#
117+
# GET /user/repos
118+
#
119+
#
120+
# List public repositories for the specified user.
121+
#
122+
# GET /users/:user/repos
123+
#
124+
# Examples:
125+
# client = Client.new
126+
# client.list(:user => 'username')
127+
#
128+
# List repositories for the specified organisation.
129+
#
130+
# GET /orgs/:org/repos
131+
#
132+
# Examples:
133+
#
134+
def list(params = {})
135+
type = params["type"]
136+
raise ArgumentError, "unkown repository type, only valid are: #{VALID_REPO_TYPES.join(' ')}" if VALID_REPO_TYPES.include?
137+
if (user = params.delete("user"))
138+
get(
139+
elsif (org = params.delete("org"))
140+
get("/users/#{user}/repos", params)
141+
else
142+
get("/user/repos", params)
143+
end
144+
end
145+
146+
147+
# List tags
148+
#
149+
# GET /repos/:user/:repo/tags
150+
#
151+
def tags(params={})
152+
get("/repos/#{user}/#{repo}/tags")
153+
end
154+
155+
# List teams
156+
#
157+
# GET /repos/:user/:repo/teams
158+
def teams(user, repo)
159+
get("/repos/#{user}/#{repo}/teams")
30160
end
31161

32162
end

lib/github/repos/collaborators.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module Github
22
module Repose
33
module Collaborators
44

5-
65
end
76
end
87
end

spec/github_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
22

33
describe "Github" do
4-
it "fails" do
5-
fail "hey buddy, you should probably rename this file and start specing for real"
6-
end
74
end

0 commit comments

Comments
 (0)