API Reference
This is what you were really after.
OAuth
Creates an OAuth object which signs and makes requests. You must so this first, as all other calls are based on the object this creates.
Parameters
-
- config
- object
The following config parameters can be set.
Parameter | Value | Required | Default | Notes |
---|---|---|---|---|
consumerKey | string | true | ||
consumerSecret | string | true | ||
accessTokenKey | string | Some services give you an access token so you can skip the OAuth dance |
||
accessTokenSecret | string | Required if 'accessTokenKey' was set | ||
signatureMethod | string | HMAC-SHA1 | jsOAuth only supports HMAC-SHA1 | |
realm | string | |||
requestTokenUrl | string | Required for 3-legged requests | ||
authorizationUrl | string | Required for 3-legged requests | ||
accessTokenUrl | string | Required for 3-legged requests | ||
enablePrivilege | boolean | false | Allows you to put Firefox into a Cross domain requests enabled mode* |
* Should only be used for testing
Usage
var config = {
consumerKey: 'MY-KEY',
consumerSecret: 'MY-SECRET'
};
var oauth = OAuth(config);
get
Performs a GET request
Parameters
-
- url
- string
-
- success
- function
-
- failure
- function
Usage
function success(data) {
alert('Success ' + data.text);
}
function failure(data) {
alert('Something bad happened! :(');
}
oauth.get('http://www.example.com/person/1', success, failure);
post
Performs a POST request
Parameters
-
- url
- string
-
- data
- object
-
- success
- function
-
- failure
- function
Usage
function success(data) {
alert('Success ' + data.text);
}
function failure(data) {
alert('Something bad happened! :(');
}
var data = {
name: 'Darth Vader',
age: 43
};
oauth.post('http://www.example.com/person/edit/1', data, success, failure);
getJSON
Performs a GET request and parses JSON. Requires a JSON library
Parameters
-
- url
- string
-
- success
- function
-
- failure
- function
Usage
function success(data_object) {
alert('Name: ' + data_object.name);
}
function failure(data) {
alert('Something bad happened! :(');
}
oauth.getJSON('http://www.example.com/person/1', success, failure);
request
Performs a request based on the configuration you give. More flexible than the previous request methods as you can specify additional headers.
Parameters
-
- options
- object
Parameter | Value | Required | Default | Notes |
---|---|---|---|---|
method | string | GET | ||
url | string | true | ||
data | object | |||
headers | object | |||
success | function | |||
failure | function |
Usage
function success(data) {
alert('Name: ' + data.text);
}
function failure(data) {
alert('Something bad happened! :(');
}
var options = {
method: 'POST';
url: 'http://www.example.com/person/edit/2',
success: success,
failure: failure,
headers: {
'X-Do-Not-Track': 1
},
data: {
'name': 'Luke Skywalker',
'age': '18'
}
};
oauth.request(options);