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 URI
API_BASE_URI
Base URI of the Bitbucket API.static URI
AUTHORIZATION_ENDPOINT_URI
Authorization endpoint URI.static URI
TOKEN_ENDPOINT_URI
Token endpoint URI.
-
Constructor Summary
Constructors Constructor Description BitbucketClient()
Constructs this object with a newClientBuilder
object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTokenRefreshListener(TokenRefreshListener listener)
Adds a token refresh listener.JsonObject
get(URI link)
Gets a JSON object by a link.<T> T
get(URI link, String[] mediaTypes, Class<T> type)
Gets a media object by a link.String
getAccessToken()
Returns the access token.Instant
getAccessTokenExpiry()
Returns the time when the access token expires.String
getClientId()
Returns the client identifier for OAuth.static BitbucketClient
getDefaultInstance()
Returns the defaultBitbucketClient
object.String
getRefreshToken()
Returns the refresh token.BitbucketRepository
getRepository(String ownerName, String name)
Returns a repository resource for a repository.JsonObject
getResource(String path, Map<String,Object> values)
Gets a JSON object from a resource.BitbucketAccount
getTeam(String name)
Returns an account resource for a team.BitbucketAccount
getUser(String name)
Returns an account resource for a user.void
login(String username, String password)
Logs in with resource owner password credentials.void
loginWithAuthorizationCode(String code, URI redirectionUri)
Logs in with an authorization code.void
logout()
Logs out.JsonObject
post(URI uri, Entity<?> entity)
Makes a (@code POST} request to a URI.void
removeTokenRefreshListener(TokenRefreshListener listener)
Removes a token refresh listener.Collection<BitbucketRepository>
repositories(String ownerName)
Returns aCollection
view of the repositories of an account.void
setAccessToken(String newValue)
Sets the access token.void
setAccessTokenExpiry(Instant newValue)
Sets the time when the access token expires.void
setClientId(String newValue)
Sets the client identifier for OAuth.void
setClientSecret(String newValue)
Sets the client secret for OAuth.static void
setDefaultInstance(BitbucketClient newValue)
Sets the defaultBitbucketClient
object.void
setRefreshToken(String newValue)
Sets the refresh token.
-
-
-
Constructor Detail
-
BitbucketClient
public BitbucketClient()
Constructs this object with a newClientBuilder
object.
-
-
Method Detail
-
getDefaultInstance
public static BitbucketClient getDefaultInstance()
Returns the defaultBitbucketClient
object.- Returns:
- the default
BitbucketClient
object
-
setDefaultInstance
public static void setDefaultInstance(BitbucketClient newValue)
Sets the defaultBitbucketClient
object.- Parameters:
newValue
-BitbucketClient
object
-
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;
null
otherwise
-
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;
null
otherwise
-
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,
null
otherwise
-
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:
getRepository
in 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:Bitbucket
Returns aCollection
view of the repositories of an account.- Specified by:
repositories
in interfaceBitbucket
- Parameters:
ownerName
- the name of an account- Returns:
- a
Collection
view of the repositories of an account
-
-