Constructor
new Api(api, [options])abstract
#
Properties
cacheprotected
#
options
#
Options object; the exact format and meaning is unspecified and could be different from subclass to subclass.
Properties:
| Type | Description |
|---|---|
| Object |
- Source:
Options object; the exact format and meaning is unspecified and could be different from subclass to subclass.
Methods
apiGetWithMaxAge(params, [ajaxOptions], [maxage]) → {jQuery.Promise}
#
Calls mw.Api.get, with caching parameters.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
params |
Object | Parameters to the API query. |
|
ajaxOptions |
Object |
optional |
ajaxOptions argument for mw.Api.get |
maxage |
number
|
null
|
optional |
Cache the call for this many seconds. Sets both the maxage (client-side) and smaxage (proxy-side) caching parameters. Null means no caching. Undefined means the default caching period is used. |
Returns:
the return value from mw.Api.get
- Type
- jQuery.Promise
- Source:
getCachedPromise(key, getPromise) → {jQuery.Promise}
#
Wraps a caching layer around a function returning a promise; if getCachedPromise has been called with the same key already, it will return the previous result.
Since it is the promise and not the API response that gets cached, this method can ensure that there are no race conditions and multiple calls to the same resource: even if the request is still in progress, separate calls (with the same key) to getCachedPromise will share on the same promise object. The promise is cached even if it is rejected, so if the API request fails, all later calls to getCachedPromise will fail immediately without retrying the request.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | cache key |
getPromise |
function | a function to get the promise on cache miss |
Returns:
- Type
- jQuery.Promise
- Source:
Wraps a caching layer around a function returning a promise; if getCachedPromise has been called with the same key already, it will return the previous result.
getErrorMessage(data) → {string}
#
getQueryPage(data) → {jQuery.Promise}
#
Returns a promise with the specified page from the API result. This is intended to be used as a .then() callback for action=query&prop=(...) APIs.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object |
Returns:
when successful, the first argument will be the page data, when unsuccessful, it will be an error message. The second argument is always the full API response.
- Type
- jQuery.Promise
- Source: