Expand all

mw.widgets.APIResultsProvider

API results provider.

Constructor

new mw.widgets.APIResultsProvider(apiurl, [config]) #

Create an instance of mw.widgets.APIResultsProvider.

Parameters:

Name Type Attributes Description
apiurl string

The URL to the api

config Object optional

Configuration options

Properties:
Name Type Description
fetchLimit number

The default number of results to fetch

lang string

The language of the API

offset number

Initial offset, if relevant, to call results from

ajaxSettings Object

The settings for the ajax call

staticParams Object

The data parameters that are static and should always be sent to the API request, as opposed to user parameters.

userParams Object

Initial user parameters to be sent as data to the API request. These can change per request, like the search query term or sizing parameters for images, etc.

Mixes in:
Source:

Methods

getAPIurl() → {string} #

Get API URL.

getAjaxSettings() → {Object} #

Get the default ajax settings.

Source:

Returns:

Ajax settings

Type
Object
Get the default ajax settings.

getDefaultFetchLimit() → {number} #

Get fetch limit or 'page' size. This is the number of results per request.

Source:

Returns:

limit

Type
number
Get fetch limit or 'page' size.

getLang() → {string} #

Get provider API language.

Source:

Returns:

Provider API language

Type
string
Get provider API language.

getOffset() → {number} #

Get result offset.

Source:

Returns:

Offset Results offset for the upcoming request

Type
number
Get result offset.

getResults(howMany) → {jQuery.Promise} #

Get results from the source.

Parameters:

Name Type Description
howMany number

Number of results to ask for

Source:

Returns:

Promise that is resolved into an array of available results, or is rejected if no results are available.

Type
jQuery.Promise
Get results from the source.

getStaticParams() → {Object} #

Get the static, non-changing data parameters sent to the API.

Source:

Returns:

Data parameters

Type
Object
Get the static, non-changing data parameters sent to the API.

getUserParams() → {Object} #

Get the user-inputted dynamic data parameters sent to the API.

Source:

Returns:

Data parameters

Type
Object
Get the user-inputted dynamic data parameters sent to the API.

isDepleted() → {boolean} #

Check whether the provider is depleted and has no more results to hand off.

Source:

Returns:

The provider is depleted

Type
boolean

Check whether the provider is depleted and has no more results to hand off.

reset() #

Reset the provider.

setAPIurl(apiurl) #

Set API URL.

Parameters:

Name Type Description
apiurl string

API URL

Source:
Set API URL.

setAjaxSettings(settings) #

Set the default ajax settings.

Parameters:

Name Type Description
settings Object

Ajax settings

Source:
Set the default ajax settings.

setDefaultFetchLimit(limit) #

Set limit.

Parameters:

Name Type Description
limit number

Default number of results to fetch from the API

Source:
Set limit.

setLang(lang) #

Set provider API language.

Parameters:

Name Type Description
lang string

Provider API language

Source:
Set provider API language.

setOffset(offset) #

Set result offset.

Parameters:

Name Type Description
offset number

Results offset for the upcoming request

Source:
Set result offset.

setUserParams(params) #

Set the data parameters sent to the API.

Parameters:

Name Type Description
params Object

User defined data parameters

Source:
Set the data parameters sent to the API.

toggleDepleted(isDepleted) #

Toggle depleted state.

Parameters:

Name Type Description
isDepleted boolean

The provider is depleted

Source:
Toggle depleted state.