Node.js REST Client for the PhoneGap Build API
This library simplifies authentication and requests to the PhoneGap Build REST API for node.js clients.
In many ways, this library is little more than a convenience wrapper
for mikeal's request library. You can expect
that all of request's functionality to be available to the
API
object returned by client.auth();
.
If something is inaccurate or missing, please send a pull request!
var client = require('phonegap-build-api');
client.auth({ username: 'zelda', password: 'tr1f0rce' }, function(e, api) {
// time to make requests
});
var client = require('phonegap-build-api');
client.auth({ token: 'abc123' }, function(e, api) {
// time to make requests
});
api.get('/me', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.get('/apps', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.get('/apps/199692', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.get('/apps/199692/icon').pipe(fs.createWriteStream('icon.png'));
api.get('/apps/199692/android').pipe(fs.createWriteStream('app.apk'));
api.get('/keys', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.get('/keys/ios', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.get('/keys/ios/917', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
data: {
title: 'My App',
create_method: 'file'
},
file: '/path/to/app.zip'
}
};
api.post('/apps', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
data: {
debug: false
},
file: '/path/to/app.zip'
}
};
api.put('/apps/197196', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
icon: 'my-icon.png'
}
};
api.post('/apps/232741/icon', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
Build all platforms:
api.post('/apps/232741/build', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
Build specific platforms:
var options = {
form: {
data: {
platforms: [ 'android', 'blackberry', 'ios', 'winphone', 'webos' ]
}
}
};
api.post('/apps/232741/build', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.post('/apps/232741/build/android', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
data: {
email: 'michael@michaelbrooks.ca',
role: 'dev'
}
}
};
api.post('/apps/232741/collaborators', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
data: {
role: 'tester'
}
}
};
api.put('/apps/232741/collaborators/263955', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
data: {
title: 'My BlackBerry Signing Key',
password: 'my-password'
},
db: '/path/to/sigtool.db',
csk: '/path/to/sigtool.csk'
}
};
api.post('/keys/blackberry', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
data: {
password: 'my-updated-password'
}
}
};
api.put('/keys/blackberry/1505', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.del('/apps/14450', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.del('/apps/232741/collaborators/263955', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
api.del('/keys/ios/2729', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
PhoneGap Build Authentication.
Authentications with PhoneGap Build and returns an instance of API
.
The authentication credentials can be a username and password or user-token.
options
{Object}
is the authentication settings.options.username
{String}
is the phonegap build username.options.password
{String}
is the phonegap build password.options.token
{String}
can be used instead of username and password.- [
options.protocol
]{String}
optional server protocol. e.g. 'https:'. - [
options.host
]{String}
optional server host. e.g. 'build.phonegap.com:'. - [
options.port
]{String}
optional server port. e.g. '443'. - [
options.path
]{String}
optional server path prefix. e.g. '/api/v1'. - [
options.proxy
]{String}
specifies an optional proxy server. e.g. 'http://myproxy.com:8181'. callback
{Function}
is trigger after the authentication.e
{Error}
is null unless there is an error.api
{Object}
is theAPI
instance to interact with phonegap build.
var client = require('phonegap-build-api');
client.auth({ username: 'zelda', password: 'tr1force' }, function(e, api) {
if (e) {
console.log('error:', e);
return;
}
// make some api requests
});
API Request.
Create a RESTful request to the PhoneGap Build API. The api
function is a
wrapper to request's interface.
The path
parameter is a relative path to a PhoneGap Build API response.
For example, to the resource https://build.phonegap.com/api/v1/me
is specified
as the path /me
.
The options
parameter maps directly to request's options.
The default request method is GET
. You can specify a specific but you can be changed
in the options
parameters (e.g. { method: 'POST' }
).
To send form data, you can use the options.form
parameter. The key data
is
assumed to be JSON and all other keys are assumed to be file paths.
path
{String}
is a relative resource path (e.g."/apps"
).[options]
{Object}
is a request options object.[options.protocol]
{String}
optional server protocol. e.g. 'https:'.[options.host]
{String}
optional server host. e.g. 'build.phonegap.com:'.[options.port]
{String}
optional server port. e.g. '443'.[options.path]
{String}
optional server path prefix. e.g. '/api/v1'.[callback]
{Function}
is trigger after the requeste
{Error}
is null unless there is an errordata
{Object}
is the JSON response.
api('/me', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
var options = {
form: {
data: {
title: 'My App',
create_method: 'file'
},
file: '/path/to/app.zip'
},
method: 'POST'
};
api('/apps', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
GET API Request.
A convenience function for api(path, [options], [callback])
, where options
uses { method: 'GET' }
.
path
{String}
is a relative resource path (e.g."/apps"
).[options]
{Object}
is a request options object.[callback]
{Function}
is trigger after the requeste
{Error}
is null unless there is an errordata
{Object}
is the JSON response.
api.get('/me', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
POST API Request.
A convenience function for api(path, [options], [callback])
, where options
uses { method: 'POST' }
.
path
{String}
is a relative resource path (e.g."/apps"
).[options]
{Object}
is a request options object.[callback]
{Function}
is trigger after the requeste
{Error}
is null unless there is an errordata
{Object}
is the JSON response.
var options = {
form: {
data: {
title: 'My App',
create_method: 'file'
},
file: '/path/to/app.zip'
}
};
api.post('/apps', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
PUT API Request.
A convenience function for api(path, [options], [callback])
, where options
uses { method: 'PUT' }
.
path
{String}
is a relative resource path (e.g."/apps"
).[options]
{Object}
is a request options object.[callback]
{Function}
is trigger after the requeste
{Error}
is null unless there is an errordata
{Object}
is the JSON response.
var options = {
form: {
data: {
debug: false
},
file: '/path/to/app.zip'
}
};
api.put('/apps/197196', options, function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
DELETE API Request.
A convenience function for api(path, [options], [callback])
, where options
uses { method: 'DELETE' }
.
path
{String}
is a relative resource path (e.g."/apps"
).[options]
{Object}
is a request options object.[callback]
{Function}
is trigger after the requeste
{Error}
is null unless there is an errordata
{Object}
is the JSON response.
api.del('/apps/14450', function(e, data) {
console.log('error:', e);
console.log('data:', data);
});
This maps directly to request's default
method.
This method returns a wrapper around the normal request API that defaults to whatever options you pass in to it.