public class Api
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
METHOD_GET
Parameter to
setupRequest(int, RequestBuilder), performs GET request. |
static int |
METHOD_POST
Parameter to
setupRequest(int, RequestBuilder), performs POST request. |
| Constructor and Description |
|---|
Api(java.lang.String domain)
Create an Api object with given only hostname.
|
Api(java.lang.String domain,
boolean useSecure)
Create an Api object with given only hostname and whether to use HTTPS or not.
|
Api(java.lang.String domain,
boolean useSecure,
java.lang.String endpointPath)
Create an Api object with given only hostname, whether to use HTTPS or not, and endpoint path.
|
Api(java.lang.String domain,
boolean useSecure,
java.lang.String endpointPath,
java.util.HashMap<java.lang.String,java.lang.String> customHeaders)
Create an Api object
|
Api(java.lang.String domain,
java.util.HashMap<java.lang.String,java.lang.String> customHeaders)
Create an Api object with given only hostname and custom headers.
|
Api(java.lang.String domain,
java.lang.String userAgent)
Create an Api object with given only hostname and user agent.
|
Api(java.lang.String domain,
java.lang.String userAgent,
java.util.HashMap<java.lang.String,java.lang.String> customHeaders)
Create an Api object with given only hostname, custom headers, and user agent.
|
| Modifier and Type | Method and Description |
|---|---|
RequestBuilder |
action(java.lang.String action)
Start building a request for a particular action.
|
java.net.URL |
getApiUrl()
Returns the full Url to which API requests are directed.
|
void |
processHeaders(ApiResult result) |
static void |
setConnectionFactory(com.github.kevinsawicki.http.HttpRequest.ConnectionFactory factory)
Set the connection factory used to construct connections.
|
void |
setHeaderCheckListener(OnHeaderCheckListener listener) |
ApiResult |
setupRequest(int method,
RequestBuilder requestBuilder)
Sets up the HTTP request that needs to be made to produce results for this API query.
|
public static final int METHOD_GET
setupRequest(int, RequestBuilder), performs GET request.public static final int METHOD_POST
setupRequest(int, RequestBuilder), performs POST request.public Api(java.lang.String domain)
domain - Domain name of the MediaWiki API to connect topublic Api(java.lang.String domain, java.lang.String userAgent)
domain - Domain name of the MediaWiki API to connect touserAgent - Custom User-Agent to simplify identification of consuming applicationpublic Api(java.lang.String domain, java.lang.String userAgent, java.util.HashMap<java.lang.String,java.lang.String> customHeaders)
domain - Domain name of the MediaWiki API to connect touserAgent - Custom User-Agent to simplify identification of consuming applicationcustomHeaders - Any extra headers to send with each request, e.g. User-Agent.public Api(java.lang.String domain, java.util.HashMap<java.lang.String,java.lang.String> customHeaders)
domain - Domain name of the MediaWiki API to connect tocustomHeaders - Any extra headers to send with each request, e.g. User-Agent.public Api(java.lang.String domain, boolean useSecure)
domain - Domain name of the MediaWiki API to connect touseSecure - true to use https, false to use httppublic Api(java.lang.String domain, boolean useSecure, java.lang.String endpointPath)
domain - Domain name of the MediaWiki API to connect touseSecure - true to use https, false to use httpendpointPath - Path to the api.php file. Require preceding slash.public Api(java.lang.String domain, boolean useSecure, java.lang.String endpointPath, java.util.HashMap<java.lang.String,java.lang.String> customHeaders)
domain - Domain name of the MediaWiki API to connect touseSecure - true to use https, false to use httpendpointPath - Path to the api.php file. Require preceding slash.customHeaders - Any extra headers to send with each request, e.g. User-Agent.public java.net.URL getApiUrl()
public RequestBuilder action(java.lang.String action)
action - The action to start building
a request for.RequestBuilder instance that can be used to add parameters & execute the request.public ApiResult setupRequest(int method, RequestBuilder requestBuilder) throws ApiException
ApiResult.asArray() or
ApiResult.asObject() to get the response.
In the case of a GET request, the actual network transaction will only occur when you query
the returned ApiResult object. However, for a POST request, the network transaction
will occur immediately in this function, hence the possibility of an ApiExceptionmethod - HTTP method to use when performing the requestrequestBuilder - The requestBuilder to use to construct the requestApiResult object which can be used to get the result of this query.ApiException - Thrown in the case of a network error.public static void setConnectionFactory(com.github.kevinsawicki.http.HttpRequest.ConnectionFactory factory)
factory - The factory used to construct HTTP connectionspublic void setHeaderCheckListener(OnHeaderCheckListener listener)
public void processHeaders(ApiResult result)