Class: ProxAPI

ProxAPI

new ProxAPI(settings)

Initialize an instance of ProxAPI with an optional retry delay and a translate function which must have the following structure :

function(params, handleResults){ 
  // Modify the following line to call the desired API 
  some_api.some_request(some_parameters, function(some_return_values) {
    var proxapiStatus = { quota: false };
    var err = null;

    // Transformation from the API response format to the handleResults format
    // Do something here with the API return values and compute _err_, _results_ and _proxapiStatus_

    //Finally return to ProxAPI
    handleResults(err, results, proxapiStatus); 
  });
}

This function :

  • calls the API with parmaters collected in params object
  • gets the results
  • catch errors and detect quota limits
  • returns to ProxAPI by calling handleResults with the following arguments:
    • err : errors not associated to usage limitations
    • results : API request results
    • proxapiStatus : information about the request, you must set at least proxapiStatus.quota boolean value ( true if the request failed due to usage limitations, false if there wasn't any quota error).
Parameters:
Name Type Description
settings object

Settings of the proxy

Properties
Name Type Description
retryDelay integer

Retry delay in seconds

translate function

Interface beetween ProxAPI and the API, allowing ProxAPI to call the API and to understand the results.

Source:

Members

retryDelay :integer

Retry_delay Retry delay in milliseconds

Type:
  • integer
Default Value:
  • 60000
Source:

Methods

call(params, options, onEnd)

Calls the API and apply a strategy if it encounter a quota limit.
Calls the onEvent method if provided to notice when such cases occur.
Finally calls the onEnd function whith the API results

Parameters:
Name Type Description
params object

Parameters needed by the API calling function. The translate function is called with this same object.

options object

Options

Properties
Name Type Attributes Description
strategy string <optional>

Strategy to apply when a quota limit is reached. Possible values :

  • "retry" : wait for the end of the limited period and retry
  • "abort" : abort the request and return an informative error message
onEvent ProxAPI~onEvent <optional>

Callback function called each time an event occurs

onEnd ProxAPI~onEnd

Callback function called after the API call has been made

Source:

callUntil(untilSettings, params, options, onEnd, resultsopt)

callUntil

Parameters:
Name Type Attributes Description
untilSettings object

Settings for calling the API recursively

Properties
Name Type Description
newParams ProxAPI~newParams

Callback calculating the new parameters for the next API call

aggregate ProxAPI~aggregate

Callback aggregating results of successives API calls

endCondition ProxAPI~endCondition

Callback deciding if more API calls are needed

params object

Parameters needed by the API calling function. The translate function is called with this same object.

options object

Options

Properties
Name Type Attributes Description
strategy string <optional>

Strategy to apply when a quota limit is reached. Possible values :

  • "retry" : wait for the end of the limited period and retry
  • "abort" : abort the request and return an informative error message
onEvent ProxAPI~onEvent <optional>

Callback function called each time an event occurs

onEnd ProxAPI~onEnd

Callback function called after the API call has been made

results object <optional>

results from preceding API calls to aggregate

Source:

getLimitInfo() → {LimitInfo}

Provides informations about the API limitations

Source:
Returns:

infos - Informations about the API limitations ProxAPI.LimitInfo

Type
LimitInfo

Type Definitions

LimitInfo

Type:
  • object
Properties:
Name Type Description
retryDelay integer

Number of seconds to wait before retrying a call to the API

Source:

aggregate(results, data) → {object}

Parameters:
Name Type Description
results string

results from preceding API calls

data object

API request results

Source:
Returns:

results - Aggregated results

Type
object

endCondition(error, data) → {boolean}

Parameters:
Name Type Description
error string

API request error

data object

API request results

Source:
Returns:

stop - True if all results have been fetched, False if more API calls are needed

Type
boolean

newParams(error, data) → {object}

Parameters:
Name Type Description
error string

API request error

data object

API request results

Source:
Returns:

params - Parameters used for the next API call

Type
object

onEnd(error, data)

Parameters:
Name Type Description
error string
data object

API request results

Source:

onEvent(eventName, data)

Parameters:
Name Type Description
eventName string

Name of the event (ie "retrying")

data string

Event message

Source: