Skip to content

Commit 1e95d51

Browse files
author
Sam Davies
committed
Implement Projects#list
- Tests partially completed - See: piotrmurach#289
1 parent fb31976 commit 1e95d51

File tree

10 files changed

+144
-3
lines changed

10 files changed

+144
-3
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ group :development do
1111
gem 'vcr', '~> 2.6'
1212
gem 'webmock', '~> 1.17.3'
1313
gem 'yard', '~> 0.8.7'
14+
gem 'pry'
1415
end
1516

1617
group :metrics do

lib/github_api/client/repos.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Client::Repos < API
1515
'keys',
1616
'merging',
1717
'pages',
18+
'projects',
1819
'pub_sub_hubbub',
1920
'releases',
2021
'statistics',
@@ -71,6 +72,9 @@ class Client::Repos < API
7172
# Access to Repos::Pages API
7273
namespace :pages
7374

75+
# Access to Repos::Projects API
76+
namespace :projects
77+
7478
# Access to Repos::PubSubHubbub API
7579
namespace :pubsubhubbub, full_name: :pub_sub_hubbub
7680

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
module Github
4+
class Client::Repos::Projects < API
5+
OPTIONS = {
6+
headers: {
7+
ACCEPT => 'application/vnd.github.inertia-preview+json'
8+
}
9+
}
10+
11+
# List a repo's projects
12+
#
13+
# @example
14+
# github = Github.new
15+
# github.repos.projects.list owner: 'owner-name', repo: 'repo-name'
16+
#
17+
# @example
18+
# github = Github.new
19+
# github.repos.projects.list state: 'open', owner: 'owner-name', repo: 'repo-name'
20+
#
21+
# @example
22+
# github.repos.projects.list owner: 'owner-name', repo: 'repo-name' { |cbr| .. }
23+
#
24+
# @return [Array]
25+
#
26+
# @api public
27+
def list(*args)
28+
arguments(args, required: [:owner, :repo])
29+
30+
params = arguments.params
31+
params['options'] = OPTIONS
32+
33+
response = get_request("/repos/#{arguments.owner}/#{arguments.repo}/projects", params)
34+
return response unless block_given?
35+
response.each { |el| yield el }
36+
end
37+
alias :all :list
38+
end
39+
end

lib/github_api/client/users/followers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Client::Users::Followers < API
55

66
# List a user's followers
77
#
8-
# @xample
8+
# @example
99
# github = Github.new
1010
# github.users.followers.list 'user-name'
1111
# github.users.followers.list 'user-name' { |user| ... }

lib/github_api/params_hash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ParamsHash < DelegateClass(Hash)
99
include Normalizer
1010
include MimeType
1111

12-
REQUEST_PARAMS = [:accept, :media, :data, :raw, :content_type, :headers]
12+
REQUEST_PARAMS = [:accept, :media, :data, :raw, :content_type, :headers, :options]
1313

1414
def initialize(hash)
1515
super(normalize!(Hash[hash]))

spec/fixtures/repos/projects.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
{
3+
"owner_url": "https://api.github.com/repos/samphilipd/github",
4+
"url": "https://api.github.com/projects/513163",
5+
"html_url": "https://github.com/samphilipd/github/projects/1",
6+
"columns_url": "https://api.github.com/projects/513163/columns",
7+
"id": 513163,
8+
"name": "Implement new APIs",
9+
"body": "Implement new APIs as per:\r\n\r\nhttps://github.com/piotrmurach/github/issues/289\r\n\r\n\r\n projects\r\n reactions\r\n issues.timeline\r\n migration\r\n orgs.outside_collaborators\r\n orgs.blocking\r\n pull_requests.review_requests\r\n users.gpg_keys\r\n users.blocking\r\n repos.invitations\r\n repos.traffic\r\n repos.community\r\n",
10+
"number": 1,
11+
"state": "open",
12+
"creator": {
13+
"login": "samphilipd",
14+
"id": 4147639,
15+
"avatar_url": "https://avatars0.githubusercontent.com/u/4147639?v=3",
16+
"gravatar_id": "",
17+
"url": "https://api.github.com/users/samphilipd",
18+
"html_url": "https://github.com/samphilipd",
19+
"followers_url": "https://api.github.com/users/samphilipd/followers",
20+
"following_url": "https://api.github.com/users/samphilipd/following{/other_user}",
21+
"gists_url": "https://api.github.com/users/samphilipd/gists{/gist_id}",
22+
"starred_url": "https://api.github.com/users/samphilipd/starred{/owner}{/repo}",
23+
"subscriptions_url": "https://api.github.com/users/samphilipd/subscriptions",
24+
"organizations_url": "https://api.github.com/users/samphilipd/orgs",
25+
"repos_url": "https://api.github.com/users/samphilipd/repos",
26+
"events_url": "https://api.github.com/users/samphilipd/events{/privacy}",
27+
"received_events_url": "https://api.github.com/users/samphilipd/received_events",
28+
"type": "User",
29+
"site_admin": false
30+
},
31+
"created_at": "2017-04-05T08:38:38Z",
32+
"updated_at": "2017-04-05T08:40:06Z"
33+
}
34+
]

spec/github/client/repos/collaborators/list_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
expect { subject.list }.to raise_error(ArgumentError)
2424
end
2525

26-
it "failse to get resource with missing arguments" do
26+
it "fails to get resource with missing arguments" do
2727
expect { subject.list user }.to raise_error(ArgumentError)
2828
end
2929

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'pry'
5+
6+
describe Github::Client::Repos::Projects, '#list' do
7+
let(:user) { 'samphilipd' }
8+
let(:repo) { 'github' }
9+
let(:request_path) { "/repos/#{user}/#{repo}/projects" }
10+
11+
before {
12+
stub_get(request_path)
13+
.with(headers: {'Accept'=>'application/vnd.github.inertia-preview+json'})
14+
.to_return(
15+
body: body,
16+
status: status,
17+
headers: {
18+
content_type: "application/json; charset=utf-8"
19+
}
20+
)
21+
}
22+
23+
after { reset_authentication_for(subject) }
24+
25+
context "resource found" do
26+
let(:body) { fixture('repos/projects.json') }
27+
let(:status) { 200 }
28+
29+
it { should respond_to :all }
30+
31+
it { expect { subject.list }.to raise_error(ArgumentError) }
32+
33+
it "should fail to get resource without username" do
34+
expect { subject.list user }.to raise_error(ArgumentError)
35+
end
36+
37+
it "should get the resources" do
38+
subject.list user, repo
39+
a_get(request_path).should have_been_made
40+
end
41+
42+
it_should_behave_like 'an array of resources' do
43+
let(:requestable) { subject.list user, repo }
44+
end
45+
46+
it "should get project information" do
47+
projects = subject.list user, repo
48+
projects.first.name.should == 'Implement new APIs'
49+
end
50+
51+
it "should yield to a block" do
52+
yielded = []
53+
result = subject.list(user, repo) { |obj| yielded << obj }
54+
yielded.should == result
55+
end
56+
end
57+
58+
it_should_behave_like 'request failure' do
59+
let(:requestable) { subject.list user, repo }
60+
end
61+
end # list

spec/github/client/repos/projects_spec.rb

Whitespace-only changes.

spec/integration/repos_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@
3434

3535
its(:pubsubhubbub) { should be_a Github::Client::Repos::PubSubHubbub }
3636

37+
its(:projects) { should be_a Github::Client::Repos::Projects }
38+
3739
end # Github::Repos

0 commit comments

Comments
 (0)