Class GitHub
- java.lang.Object
-
- com.mooltiverse.oss.nyx.services.github.GitHub
-
- All Implemented Interfaces:
GitService
public class GitHub extends Object implements GitService
The entry point to the GitHub service.
-
-
Field Summary
Fields Modifier and Type Field Description static StringAPI_BASE_URLThe API base URL, as per GitHub API
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GitHubSessionauthenticateWithToken(String token)Authenticates by using the given token (Personal Access Token, OAuth)URIgetBaseURI()Returns the API base URI for the service instance.static GitHubinstance()Returns an instance using the default API URI (API_BASE_URL).static GitHubinstance(String apiURI)Returns an instance using the given API URI.static GitHubinstance(URI apiURI)Returns an instance using the given API URI.booleanping()Tries to contact the remote server to verify it's reachable and healthy.booleansupports(GitServiceFeature feature)Safely checks if the underlying implementation supports the given operation.
-
-
-
Field Detail
-
API_BASE_URL
public static final String API_BASE_URL
The API base URL, as per GitHub API- See Also:
- Constant Field Values
-
-
Method Detail
-
instance
public static GitHub instance() throws GitTransportException
Returns an instance using the default API URI (API_BASE_URL).- Returns:
- an instance using the default API URI.
- Throws:
GitTransportException- if the default URI can't be reached or does not expose valid APIs
-
instance
public static GitHub instance(String apiURI) throws GitTransportException
Returns an instance using the given API URI.- Parameters:
apiURI- the API URI, which is usually the endpoint to a private or on premises installation- Returns:
- an instance using the given API URI
- Throws:
GitTransportException- if the given URI can't be reached or does not expose valid APIsNullPointerException- if the given URI isnullIllegalArgumentException- if the given URI is illegal (i.e. empty or malformed)
-
instance
public static GitHub instance(URI apiURI) throws GitTransportException
Returns an instance using the given API URI.- Parameters:
apiURI- the API URI, which is usually the endpoint to a private or on premises installation- Returns:
- an instance using the given API URI
- Throws:
GitTransportException- if the given URI can't be reached or does not expose valid APIsNullPointerException- if the given URI isnullIllegalArgumentException- if the given URI is illegal (i.e. empty or malformed)
-
supports
public boolean supports(GitServiceFeature feature)
Safely checks if the underlying implementation supports the given operation. If this method returnstruethen the underlying class will not raise anyUnsupportedOperationExceptionwhen invoking the specific methods.- Specified by:
supportsin interfaceGitService- Parameters:
feature- the feature to check for support.- Returns:
trueif the operation is supported,falseotherwise
-
getBaseURI
public URI getBaseURI()
Returns the API base URI for the service instance.- Specified by:
getBaseURIin interfaceGitService- Returns:
- the API base URI for the service instance
-
ping
public boolean ping()
Tries to contact the remote server to verify it's reachable and healthy. Please note that this method sends unauthenticated requests that may fail because of rate limits so use it with care.- Specified by:
pingin interfaceGitService- Returns:
trueif the operation succeeds,falseotherwise
-
authenticateWithToken
public GitHubSession authenticateWithToken(String token) throws GitTransportException, GitAuthenticationException
Authenticates by using the given token (Personal Access Token, OAuth)- Specified by:
authenticateWithTokenin interfaceGitService- Parameters:
token- the token to use for authentication.- Returns:
- a session object that can be used to perform operations as an authenticated user
- Throws:
GitTransportException- if a transport related error occurs while communicating with the serverGitAuthenticationException- if authentication fails
-
-