public class BasicApiConnection extends ApiConnection
Modifier and Type | Class and Description |
---|---|
protected static class |
BasicApiConnection.HttpCookieWrapper
Wrapper for
HttpCookie . |
apiBaseUrl, ASSERT_PARAMETER, connectTimeout, loggedIn, PARAM_ACTION, PARAM_FORMAT, readTimeout, tokens, URL_TEST_WIKIDATA_API, URL_WIKIDATA_API, URL_WIKIMEDIA_COMMONS_API, URLENCODED_MEDIA_TYPE, username
Modifier | Constructor and Description |
---|---|
|
BasicApiConnection(String apiBaseUrl)
Creates an object to manage a connection to the Web API of a Wikibase
site.
|
protected |
BasicApiConnection(String apiBaseUrl,
List<BasicApiConnection.HttpCookieWrapper> cookies,
String username,
boolean loggedIn,
Map<String,String> tokens,
int connectTimeout,
int readTimeout)
Deserializes an existing BasicApiConnection from JSON.
|
Modifier and Type | Method and Description |
---|---|
void |
clearCookies()
Clears the set of cookies.
|
void |
clientLogin(String username,
String password)
Logs in using the main user credentials.
|
protected void |
confirmClientLogin(String token,
String username,
String password)
Issues a Web API query to confirm that the previous client login attempt was
successful, and sets the internal state of the API connection accordingly
in this case.
|
protected void |
confirmLogin(String token,
String username,
String password)
Issues a Web API query to confirm that the previous login attempt was
successful, and sets the internal state of the API connection accordingly
in this case.
|
protected okhttp3.OkHttpClient.Builder |
getClientBuilder()
Subclasses can customize their own
OkHttpClient.Builder instances. |
List<HttpCookie> |
getCookies()
Returns the map of cookies currently used in this connection.
|
static BasicApiConnection |
getTestWikidataApiConnection()
Creates an API connection to test.wikidata.org.
|
static BasicApiConnection |
getWikidataApiConnection()
Creates an API connection to wikidata.org.
|
static BasicApiConnection |
getWikimediaCommonsApiConnection()
Creates an API connection to commons.wikimedia.org.
|
void |
login(String username,
String password)
Logs in using the specified user credentials.
|
protected void |
login(String username,
String password,
org.wikidata.wdtk.wikibaseapi.BasicApiConnection.ILogin loginFunction)
Login function that contains token logic and a function as parameter
|
void |
logout()
Logs the current user out.
|
checkCredentials, checkErrors, getApiBaseUrl, getConnectTimeout, getCurrentUser, getReadTimeout, getTokens, implodeObjects, isLoggedIn, logWarnings, sendJsonRequest, sendJsonRequest, sendRequest, setConnectTimeout, setReadTimeout
public BasicApiConnection(String apiBaseUrl)
apiBaseUrl
- base URI to the API, e.g.,
"https://www.wikidata.org/w/api.php/"protected BasicApiConnection(String apiBaseUrl, List<BasicApiConnection.HttpCookieWrapper> cookies, String username, boolean loggedIn, Map<String,String> tokens, int connectTimeout, int readTimeout)
apiBaseUrl
- base URL of the API to use, e.g. "https://www.wikidata.org/w/api.php/"cookies
- map of cookies used for this sessionusername
- name of the current userloggedIn
- true if login succeeded.tokens
- map of tokens used for this sessionconnectTimeout
- the maximum time to wait for when establishing a connection, in millisecondsreadTimeout
- the maximum time to wait for a server response once the connection was established, in millisecondsprotected okhttp3.OkHttpClient.Builder getClientBuilder()
ApiConnection
OkHttpClient.Builder
instances.
An example:
return new OkHttpClient.Builder() .connectTimeout(5, TimeUnit.MILLISECONDS) .readTimeout(5, TimeUnit.MILLISECONDS) .cookieJar(...);
getClientBuilder
in class ApiConnection
public static BasicApiConnection getTestWikidataApiConnection()
BasicApiConnection
public static BasicApiConnection getWikidataApiConnection()
BasicApiConnection
public static BasicApiConnection getWikimediaCommonsApiConnection()
BasicApiConnection
public void login(String username, String password) throws LoginFailedException
username
- the name of the user to log inpassword
- the password of the userLoginFailedException
- if the login failed for some reasonpublic void clientLogin(String username, String password) throws LoginFailedException
username
- the name of the main user to log inpassword
- the password of the main userLoginFailedException
- if the login failed for some reasonprotected void login(String username, String password, org.wikidata.wdtk.wikibaseapi.BasicApiConnection.ILogin loginFunction) throws LoginFailedException
username
- the name of the user to log inpassword
- the password of the userloginFunction
- the functional interface to log in withLoginFailedException
- if the login failed for some reasonprotected void confirmLogin(String token, String username, String password) throws IOException, LoginFailedException, MediaWikiApiErrorException
token
- the login token stringusername
- the name of the user that was logged inpassword
- the password used to log inIOException
LoginFailedException
MediaWikiApiErrorException
protected void confirmClientLogin(String token, String username, String password) throws IOException, LoginFailedException, MediaWikiApiErrorException
token
- the login token stringusername
- the name of the main user that was logged inpassword
- the password used to log inIOException
LoginFailedException
MediaWikiApiErrorException
public List<HttpCookie> getCookies()
public void clearCookies() throws IOException, MediaWikiApiErrorException
public void logout() throws IOException, MediaWikiApiErrorException
logout
in class ApiConnection
IOException
MediaWikiApiErrorException
Copyright © 2014–2024 Wikidata Toolkit Developers. Generated from source code published under the Apache License 2.0. For more information, see the Wikidata Toolkit homepage