Package org.vx68k.bitbucket.api.client
Class BitbucketClient
- java.lang.Object
-
- org.vx68k.bitbucket.api.client.BitbucketClient
-
- All Implemented Interfaces:
Serializable,Bitbucket
public class BitbucketClient extends Object implements Bitbucket, Serializable
Bitbucket API client.- Since:
- 5.0
- Author:
- Kaz Nishimura
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static URIAPI_BASE_URIBase URI of the Bitbucket API.static URIAUTHORIZATION_ENDPOINT_URIAuthorization endpoint URI.static URITOKEN_ENDPOINT_URIToken endpoint URI.
-
Constructor Summary
Constructors Constructor Description BitbucketClient()Constructs this object with a newClientBuilderobject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTokenRefreshListener(TokenRefreshListener listener)Adds a token refresh listener.JsonObjectget(URI link)Gets a JSON object by a link.<T> Tget(URI link, String[] mediaTypes, Class<T> type)Gets a media object by a link.StringgetAccessToken()Returns the access token.InstantgetAccessTokenExpiry()Returns the time when the access token expires.StringgetClientId()Returns the client identifier for OAuth.static BitbucketClientgetDefaultInstance()Returns the defaultBitbucketClientobject.StringgetRefreshToken()Returns the refresh token.BitbucketRepositorygetRepository(String ownerName, String name)Returns a repository resource for a repository.JsonObjectgetResource(String path, Map<String,Object> values)Gets a JSON object from a resource.BitbucketAccountgetTeam(String name)Returns an account resource for a team.BitbucketAccountgetUser(String name)Returns an account resource for a user.voidlogin(String username, String password)Logs in with resource owner password credentials.voidloginWithAuthorizationCode(String code, URI redirectionUri)Logs in with an authorization code.voidlogout()Logs out.JsonObjectpost(URI uri, Entity<?> entity)Makes a (@code POST} request to a URI.voidremoveTokenRefreshListener(TokenRefreshListener listener)Removes a token refresh listener.Collection<BitbucketRepository>repositories(String ownerName)Returns aCollectionview of the repositories of an account.voidsetAccessToken(String newValue)Sets the access token.voidsetAccessTokenExpiry(Instant newValue)Sets the time when the access token expires.voidsetClientId(String newValue)Sets the client identifier for OAuth.voidsetClientSecret(String newValue)Sets the client secret for OAuth.static voidsetDefaultInstance(BitbucketClient newValue)Sets the defaultBitbucketClientobject.voidsetRefreshToken(String newValue)Sets the refresh token.
-
-
-
Constructor Detail
-
BitbucketClient
public BitbucketClient()
Constructs this object with a newClientBuilderobject.
-
-
Method Detail
-
getDefaultInstance
public static BitbucketClient getDefaultInstance()
Returns the defaultBitbucketClientobject.- Returns:
- the default
BitbucketClientobject
-
setDefaultInstance
public static void setDefaultInstance(BitbucketClient newValue)
Sets the defaultBitbucketClientobject.- Parameters:
newValue-BitbucketClientobject
-
getClientId
public final String getClientId()
Returns the client identifier for OAuth.- Returns:
- the client identifier
-
setClientId
public final void setClientId(String newValue)
Sets the client identifier for OAuth.- Parameters:
newValue- a new value of the client identifier
-
setClientSecret
public final void setClientSecret(String newValue)
Sets the client secret for OAuth.- Parameters:
newValue- a new value of the client secret.
-
getAccessToken
public final String getAccessToken()
Returns the access token.- Returns:
- the access token
-
setAccessToken
public final void setAccessToken(String newValue)
Sets the access token.- Parameters:
newValue- new value of the access token
-
getRefreshToken
public final String getRefreshToken()
Returns the refresh token.- Returns:
- the refresh token
-
setRefreshToken
public final void setRefreshToken(String newValue)
Sets the refresh token.- Parameters:
newValue- a new value of the refresh token
-
getAccessTokenExpiry
public final Instant getAccessTokenExpiry()
Returns the time when the access token expires.- Returns:
- the time when the access token expires
-
setAccessTokenExpiry
public final void setAccessTokenExpiry(Instant newValue)
Sets the time when the access token expires.- Parameters:
newValue- new value of the time when the access token expires
-
addTokenRefreshListener
public final void addTokenRefreshListener(TokenRefreshListener listener)
Adds a token refresh listener.- Parameters:
listener- a token refresh listener
-
removeTokenRefreshListener
public final void removeTokenRefreshListener(TokenRefreshListener listener)
Removes a token refresh listener.- Parameters:
listener- a token refresh listener
-
loginWithAuthorizationCode
public final void loginWithAuthorizationCode(String code, URI redirectionUri)
Logs in with an authorization code.- Parameters:
code- an authorization coderedirectionUri- a redirection URI
-
login
public final void login(String username, String password)
Logs in with resource owner password credentials.- Parameters:
username- a usernamepassword- a password
-
logout
public final void logout()
Logs out.
-
get
public final JsonObject get(URI link)
Gets a JSON object by a link.- Parameters:
link- the URI for a link- Returns:
- a JSON object if one was found;
nullotherwise
-
get
public final <T> T get(URI link, String[] mediaTypes, Class<T> type)
Gets a media object by a link.- Type Parameters:
T- return type- Parameters:
link- the URI for a linkmediaTypes- acceptable MIME media typestype- the type of the media object to return- Returns:
- media object if one was found;
nullotherwise
-
post
public final JsonObject post(URI uri, Entity<?> entity)
Makes a (@code POST} request to a URI.- Parameters:
uri- a URIentity- an entity to post- Returns:
- a JSON object
-
getResource
public final JsonObject getResource(String path, Map<String,Object> values)
Gets a JSON object from a resource.- Parameters:
path- path of the resource with templatesvalues- template values, ornull- Returns:
- JSON object if found,
nullotherwise
-
getUser
public final BitbucketAccount getUser(String name)
Returns an account resource for a user.This implementation gets the user resource remotely from Bitbucket Cloud.
-
getTeam
public final BitbucketAccount getTeam(String name)
Returns an account resource for a team.This implementation gets the team resource remotely from Bitbucket Cloud.
-
getRepository
public final BitbucketRepository getRepository(String ownerName, String name)
Returns a repository resource for a repository.This implementation gets the repository resource remotely from Bitbucket Cloud.
- Specified by:
getRepositoryin interfaceBitbucket- Parameters:
ownerName- the owner name of a repositoryname- the name of a repository- Returns:
- a repository resource for a repository
-
repositories
public final Collection<BitbucketRepository> repositories(String ownerName)
Description copied from interface:BitbucketReturns aCollectionview of the repositories of an account.- Specified by:
repositoriesin interfaceBitbucket- Parameters:
ownerName- the name of an account- Returns:
- a
Collectionview of the repositories of an account
-
-