Skip to content
This repository was archived by the owner on Apr 5, 2022. It is now read-only.

Commit 7a2be8e

Browse files
committed
Merge pull request #1 from williewheeler/repo-watchers
Repo watchers
2 parents 3510865 + fcb2170 commit 7a2be8e

18 files changed

+2288
-10
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.classpath
2+
.project
3+
.settings
14
.DS_Store
25
build
36
**/build

spring-social-github/src/main/java/org/springframework/social/github/api/GitHub.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,48 @@
2727
* referring to the user for whom the access token has been issued.
2828
*
2929
* @author Craig Walls
30+
* @author Willie Wheeler ([email protected])
3031
*/
3132
public interface GitHub extends ApiBinding {
3233

3334
/**
3435
* Retrieves the user's GitHub profile ID.
3536
*
3637
* @return the user's GitHub profile ID.
38+
* @deprecated Move to {@link UserOperations}
3739
*/
40+
@Deprecated
3841
String getProfileId();
3942

4043
/**
4144
* Retrieves the user's GitHub profile details.
4245
*
4346
* @return the user's GitHub profile
47+
* @deprecated Move to {@link UserOperations}
4448
*/
49+
@Deprecated
4550
GitHubUserProfile getUserProfile();
4651

4752
/**
4853
* Retrieve the URL to the user's GitHub profile.
4954
*
5055
* @return the URL to the user's GitHub profile.
56+
* @deprecated Move to {@link UserOperations}
5157
*/
58+
@Deprecated
5259
String getProfileUrl();
53-
}
60+
61+
/**
62+
* Returns the portion of the GitHub API containing the repo operations.
63+
*
64+
* @return repo operations
65+
*/
66+
RepoOperations repoOperations();
67+
68+
/**
69+
* Returns the portion of the GitHub API containing the user operations.
70+
*
71+
* @return user operations
72+
*/
73+
UserOperations userOperations();
74+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.social.github.api;
17+
18+
import java.io.Serializable;
19+
20+
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
21+
22+
/**
23+
* A GitHub repository commit.
24+
*
25+
* @author Willie Wheeler ([email protected])
26+
*/
27+
@SuppressWarnings("serial")
28+
@JsonIgnoreProperties(ignoreUnknown = true)
29+
public class GitHubCommit implements Serializable {
30+
private String sha;
31+
private String url;
32+
private GitHubUser committer;
33+
private GitHubUser author;
34+
35+
public String getSha() { return sha; }
36+
37+
public void setSha(String sha) { this.sha = sha; }
38+
39+
public String getUrl() { return url; }
40+
41+
public void setUrl(String url) { this.url = url; }
42+
43+
/**
44+
* @return user who committed the patch, perhaps on behalf of a separate
45+
* author (e.g., Willie authors code, issues a pull request, and
46+
* Craig commits it)
47+
*/
48+
public GitHubUser getCommitter() { return committer; }
49+
50+
public void setCommitter(GitHubUser committer) { this.committer = committer; }
51+
52+
public GitHubUser getAuthor() { return author; }
53+
54+
/**
55+
* @param author user who wrote the patch
56+
*/
57+
public void setAuthor(GitHubUser author) { this.author = author; }
58+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.social.github.api;
17+
18+
import java.io.Serializable;
19+
20+
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
21+
import org.codehaus.jackson.annotate.JsonProperty;
22+
23+
/**
24+
* A GitHub repository user.
25+
*
26+
* @author Willie Wheeler ([email protected])
27+
*/
28+
@SuppressWarnings("serial")
29+
@JsonIgnoreProperties(ignoreUnknown = true)
30+
public class GitHubUser implements Serializable {
31+
private Long id;
32+
private String url;
33+
private String login;
34+
private String avatarUrl;
35+
private String gravatarId;
36+
37+
public Long getId() { return id; }
38+
39+
public void setId(Long id) { this.id = id; }
40+
41+
public String getUrl() { return url; }
42+
43+
public void setUrl(String url) { this.url = url; }
44+
45+
/**
46+
* @return watcher's GitHub login
47+
*/
48+
public String getLogin() { return login; }
49+
50+
public void setLogin(String login) { this.login = login; }
51+
52+
@JsonProperty("avatar_url")
53+
public String getAvatarUrl() { return avatarUrl; }
54+
55+
public void setAvatarUrl(String avatarUrl) { this.avatarUrl = avatarUrl; }
56+
57+
@JsonProperty("gravatar_id")
58+
public String getGravatarId() { return gravatarId; }
59+
60+
public void setGravatarId(String gravatarId) { this.gravatarId = gravatarId; }
61+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.social.github.api;
17+
18+
import java.util.List;
19+
20+
/**
21+
* Interface defining the operations for working with GitHub repositories.
22+
*
23+
* @author Willie Wheeler ([email protected])
24+
*/
25+
public interface RepoOperations {
26+
27+
/**
28+
* Public operation to return a list of collaborators for the given repository.
29+
*
30+
* @param user GitHub user
31+
* @param repo GitHub repository
32+
* @return list of collaborators
33+
*/
34+
List<GitHubUser> getCollaborators(String user, String repo);
35+
36+
/**
37+
* Public operation to return a list of commits for the given repository.
38+
*
39+
* @param user GitHub user
40+
* @param repo GitHub repository
41+
* @return list of commits
42+
*/
43+
List<GitHubCommit> getCommits(String user, String repo);
44+
45+
/**
46+
* Public operation to return a list of watchers for the given repository.
47+
*
48+
* @param user GitHub user
49+
* @param repo GitHub repository
50+
* @return list of watchers
51+
*/
52+
List<GitHubUser> getWatchers(String user, String repo);
53+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.social.github.api;
17+
18+
import java.util.List;
19+
20+
/**
21+
* Interface defining the operations for working with GitHub users.
22+
*
23+
* @author Willie Wheeler ([email protected])
24+
*/
25+
public interface UserOperations {
26+
27+
/**
28+
* Public operation to return a given user's followers.
29+
*
30+
* @param user GitHub user
31+
* @return list of followers
32+
*/
33+
public List<GitHubUser> getFollowers(String user);
34+
35+
/**
36+
* Public operation to return the users that a given user is following.
37+
*
38+
* @param user GitHub user
39+
* @return list of users the given user is following
40+
*/
41+
public List<GitHubUser> getFollowing(String user);
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2011 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.social.github.api.impl;
17+
18+
import org.springframework.social.MissingAuthorizationException;
19+
20+
/**
21+
* <p>
22+
* Based on <code>AbstractTwitterOperations</code>, by Keith Donald.
23+
* </p>
24+
*
25+
* @author Willie Wheeler ([email protected])
26+
*/
27+
class AbstractGitHubOperations {
28+
private final boolean isAuthorized;
29+
30+
public AbstractGitHubOperations(boolean isAuthorized) {
31+
this.isAuthorized = isAuthorized;
32+
}
33+
34+
protected void requireAuthorization() {
35+
if (!isAuthorized) {
36+
throw new MissingAuthorizationException();
37+
}
38+
}
39+
40+
// Using String here instead of URI so I can include braces in the path. See, e.g., RepoTemplate. [WLW]
41+
protected String buildUri(String path) {
42+
// return URIBuilder.fromUri(API_URL_BASE + path).build();
43+
return API_URL_BASE + path;
44+
}
45+
46+
// GitHub API v3
47+
private static final String API_URL_BASE = "https://api.github.com/";
48+
}

0 commit comments

Comments
 (0)