Skip to content

Commit 1f619f3

Browse files
authored
Merge pull request hub4j#611 from PauloMigAlmeida/master
Implement Meta endpoint
2 parents e41a341 + fd436cf commit 1f619f3

6 files changed

Lines changed: 707 additions & 13 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.kohsuke.github;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.util.ArrayList;
6+
import java.util.Collections;
7+
import java.util.List;
8+
9+
/**
10+
* Class that wraps the list of GitHub's IP addresses.
11+
*
12+
* @author Paulo Miguel Almeida
13+
*
14+
* @see GitHub#getMeta()
15+
* @see <a href="https://developer.github.com/v3/meta/#meta">Get Meta</a>
16+
*/
17+
18+
public class GHMeta {
19+
20+
@JsonProperty("verifiable_password_authentication")
21+
private boolean verifiablePasswordAuthentication;
22+
private List<String> hooks;
23+
private List<String> git;
24+
private List<String> web;
25+
private List<String> api;
26+
private List<String> pages;
27+
private List<String> importer = new ArrayList<>();
28+
29+
public boolean isVerifiablePasswordAuthentication() {
30+
return verifiablePasswordAuthentication;
31+
}
32+
33+
public List<String> getHooks() {
34+
return Collections.unmodifiableList(hooks);
35+
}
36+
37+
public List<String> getGit() {
38+
return Collections.unmodifiableList(git);
39+
}
40+
41+
public List<String> getWeb() {
42+
return Collections.unmodifiableList(web);
43+
}
44+
45+
public List<String> getApi() {
46+
return Collections.unmodifiableList(api);
47+
}
48+
49+
public List<String> getPages() {
50+
return Collections.unmodifiableList(pages);
51+
}
52+
53+
public List<String> getImporter() {
54+
return Collections.unmodifiableList(importer);
55+
}
56+
}

src/main/java/org/kohsuke/github/GitHub.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
import com.fasterxml.jackson.databind.DeserializationFeature;
2727
import com.fasterxml.jackson.databind.MapperFeature;
2828
import com.fasterxml.jackson.databind.ObjectMapper;
29-
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
3029
import com.fasterxml.jackson.databind.introspect.VisibilityChecker.Std;
3130
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
3231
import org.apache.commons.codec.Charsets;
3332
import org.apache.commons.codec.binary.Base64;
3433
import org.apache.commons.io.IOUtils;
35-
import org.apache.commons.lang3.StringUtils;
3634

3735
import javax.annotation.CheckForNull;
3836
import javax.annotation.Nonnull;
@@ -266,7 +264,7 @@ public static GitHub offline() {
266264

267265
/**
268266
* Is this an anonymous connection
269-
*
267+
*
270268
* @return {@code true} if operations that require authentication will fail.
271269
*/
272270
public boolean isAnonymous() {
@@ -275,7 +273,7 @@ public boolean isAnonymous() {
275273

276274
/**
277275
* Is this an always offline "connection".
278-
*
276+
*
279277
* @return {@code true} if this is an always offline "connection".
280278
*/
281279
public boolean isOffline() {
@@ -764,7 +762,7 @@ public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String acces
764762

765763
/**
766764
* Returns a list of all authorizations.
767-
*
765+
*
768766
* @see <a href="https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations">List your
769767
* authorizations</a>
770768
*/
@@ -802,6 +800,20 @@ public boolean isCredentialValid() {
802800
}
803801
}
804802

803+
/**
804+
* Provides a list of GitHub's IP addresses.
805+
*
806+
* @see <a href="https://developer.github.com/v3/meta/#meta">Get Meta</a>
807+
*
808+
* @return an instance of {@link GHMeta}
809+
* @throws IOException
810+
* if the credentials supplied are invalid or if you're trying to access it as a GitHub App via the JWT
811+
* authentication
812+
*/
813+
public GHMeta getMeta() throws IOException {
814+
return retrieve().to("/meta", GHMeta.class);
815+
}
816+
805817
GHUser intern(GHUser user) throws IOException {
806818
if (user == null)
807819
return user;
@@ -866,7 +878,7 @@ public void checkApiUrlValidity() throws IOException {
866878
* Checks if a GitHub Enterprise server is configured in private mode.
867879
*
868880
* In private mode response looks like:
869-
*
881+
*
870882
* <pre>
871883
* $ curl -i https://github.mycompany.com/api/v3/
872884
* HTTP/1.1 401 Unauthorized
@@ -955,7 +967,7 @@ public GHNotificationStream listNotifications() {
955967

956968
/**
957969
* This provides a dump of every public repository, in the order that they were created.
958-
*
970+
*
959971
* @see <a href="https://developer.github.com/v3/repos/#list-all-public-repositories">documentation</a>
960972
*/
961973
public PagedIterable<GHRepository> listAllPublicRepositories() {

0 commit comments

Comments
 (0)