GithubHelp home page GithubHelp logo

node-phonegap-build-api's Introduction

PhoneGap Build API Node Module Build Status bitHound Score

Node.js REST Client for the PhoneGap Build API

Overview

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!

Usage

Authenticate with Username and Password

var client = require('phonegap-build-api');

client.auth({ username: 'zelda', password: 'tr1f0rce' }, function(e, api) {
    // time to make requests
});

Authenticate with Token

var client = require('phonegap-build-api');

client.auth({ token: 'abc123' }, function(e, api) {
    // time to make requests
});

GET /api/v1/me

api.get('/me', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

GET /api/v1/apps

api.get('/apps', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

GET /api/v1/apps/:id

api.get('/apps/199692', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

GET /api/v1/apps/:id/icon

api.get('/apps/199692/icon').pipe(fs.createWriteStream('icon.png'));

GET /api/v1/apps/:id/:platform

api.get('/apps/199692/android').pipe(fs.createWriteStream('app.apk'));

GET /api/v1/keys

api.get('/keys', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

GET /api/v1/keys/:platform

api.get('/keys/ios', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

GET /api/v1/keys/:platform/:id

api.get('/keys/ios/917', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

POST /api/v1/apps

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/v1/apps/:id

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);
});

POST /api/v1/apps/:id/icon

var options = {
    form: {
        icon: 'my-icon.png'
    }
};

api.post('/apps/232741/icon', options, function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

POST /api/v1/apps/:id/build

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);
});

POST /api/v1/apps/:id/build/:platform

api.post('/apps/232741/build/android', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

POST /api/v1/apps/:id/collaborators

var options = {
    form: {
        data: {
            email: '[email protected]',
            role: 'dev'
        }
    }
};

api.post('/apps/232741/collaborators', options, function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

PUT /api/v1/apps/:id/collaborators/:id

var options = {
    form: {
        data: {
            role: 'tester'
        }
    }
};

api.put('/apps/232741/collaborators/263955', options, function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

POST /api/v1/keys/:platform

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);
});

PUT /api/v1/keys/:platform/:id

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);
});

DELETE /api/v1/apps/:id

api.del('/apps/14450', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

DELETE /api/v1/apps/:id/collaborators/:id

api.del('/apps/232741/collaborators/263955', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

DELETE /api/v1/keys/:platform/:id

api.del('/keys/ios/2729', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

API

client.auth(options, callback)

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:

  • 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 the API instance to interact with phonegap build.

Example:

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(path, [options], [callback])

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.

Options:

  • 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 request
    • e {Error} is null unless there is an error
    • data {Object} is the JSON response.

Example: GET Request

api('/me', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

Example: POST Request

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);
});

api.get(path, [options], [callback])

GET API Request.

A convenience function for api(path, [options], [callback]), where options uses { method: 'GET' }.

Options:

  • path {String} is a relative resource path (e.g. "/apps").
  • [options] {Object} is a request options object.
  • [callback] {Function} is trigger after the request
    • e {Error} is null unless there is an error
    • data {Object} is the JSON response.

Example:

api.get('/me', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

api.post(path, [options], [callback])

POST API Request.

A convenience function for api(path, [options], [callback]), where options uses { method: 'POST' }.

Options:

  • path {String} is a relative resource path (e.g. "/apps").
  • [options] {Object} is a request options object.
  • [callback] {Function} is trigger after the request
    • e {Error} is null unless there is an error
    • data {Object} is the JSON response.

Example:

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);
});

api.put(path, [options], [callback])

PUT API Request.

A convenience function for api(path, [options], [callback]), where options uses { method: 'PUT' }.

Options:

  • path {String} is a relative resource path (e.g. "/apps").
  • [options] {Object} is a request options object.
  • [callback] {Function} is trigger after the request
    • e {Error} is null unless there is an error
    • data {Object} is the JSON response.

Example:

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);
});

api.del(path, [options], [callback])

DELETE API Request.

A convenience function for api(path, [options], [callback]), where options uses { method: 'DELETE' }.

Options:

  • path {String} is a relative resource path (e.g. "/apps").
  • [options] {Object} is a request options object.
  • [callback] {Function} is trigger after the request
    • e {Error} is null unless there is an error
    • data {Object} is the JSON response.

Example:

api.del('/apps/14450', function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

api.defaults(options)

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.

Alternative Libraries

Java

Node.js

node-phonegap-build-api's People

Contributors

brianleroux avatar dave911d avatar filmaj avatar mwbrooks avatar purplecabbage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-phonegap-build-api's Issues

Errors are not caught

Currently, http request errors are caught but PhoneGap Build response errors are not.

When a request is invalid, PhoneGap Build returns a JSON response of the format:

{ "error": "something something" }

Multi-part forms are not supported

There are a number of times when a multi-part POST is required.

Examples are:

  • creating an application
  • updating icons
  • uploading signing keys

Currently, only URL encoded form data is supported, which means binary files cannot be uploaded.

A suggestion solution is to add a file key to the options argument of a post request. Whenever the file key exists, a multi-part form request is used.

var data = {
    data: {
        title: 'App name',
        create_method: 'file'
    },
    file: {
        file: 'path/to/app.zip'
    }
 };

api.post(data, function(e, response) {
    // do stuff
});

Saved Token

Is there any way to call an api using previously saved token ?

Phonegap + node js

Hello!

Ignorant question, how do I integrate a PhoneGap project with node js, ie I and I have my project with node js but I want to run mobile with PhoneGap, I don't know how integrate, where they and other files.

And on the web I found nothing

Thanks for the help!

Raul. -

key_id in build options?

After submitting the build via the API, we are still required to manually select the signing key for the platform(s) by going to build.phonegap.com. This breaks the automation.

Is there a way to provide iOS/Android signing key in the build API?

var options = {
    form: {
        data: {
            title: 'My App',
            create_method: 'file'
        },
        file: '/path/to/app.zip',
        ios_key_id: 123456789  // <---- is this possible?
    }
};

api.post('/apps', options, function(e, data) {
    console.log('error:', e);
    console.log('data:', data);
});

node js build API upload error 411

The nodejs API for phonegap build (phonegap-build-api module v1) has started giving 411 error today.

[error]
411 Length Required

411 Length Required
nginx

Seems to be happening on the CLI too.

INF] -phonegap-build:
[INF]
[INF] -phonegap-remote-login:
[INF]
[INF] -phonegap-remote-build:
[INF] [shellscript] [phonegap] compressing the app...
[INF] [shellscript] [phonegap] uploading the app...
[INF] [shellscript] [Error:
[INF] [shellscript] 411 Length Required [error]
[INF] [shellscript]
[INF] [shellscript] 411 Length Required

Happens on 3.4.0 and 3.5.0

Proxy

Seems to have trouble connecting to PhoneGap build when behind a http proxy.

api.get('/me', function(e, data) {
^
TypeError: Cannot call method 'get' of undefined
at repl:3:5
at Request.module.exports [as _callback](C:Program Filesnodejsnode_modulesphonegap-build-apilibauth.js:59:13)
at Request.init.self.callback (C:\Program Files\nodejs\node_modules\phonegap-build-api\node_modules\request\main.js:122:22)
at Request.EventEmitter.emit (events.js:96:17)
at ClientRequest.Request.init.self.clientErrorHandler (C:\Program Files\nodejs\node_modules\phonegap-build-api\node_modules\request\main.js:224:10
)
at ClientRequest.EventEmitter.emit (events.js:96:17)
at CleartextStream.socketErrorListener (http.js:1411:9)
at CleartextStream.EventEmitter.emit (events.js:96:17)
at Socket.onerror (tls.js:1336:17)
at Socket.EventEmitter.emit (events.js:126:20)

Application packages download is not working

The following example code times out: It is not possible to download the built apps using Node.js. Download from the web-app still works fine.

/*!
 * Module dependencies.
 */
var fs = require('fs');
var client = require('phonegap-build-api');

/*!
 * GET https://build.phonegap.com/api/v1/apps/:id/:platform
 */

var options = {
    username: '[email protected]',
    password: 'yyyy'
};

client.auth(options, function(e, api) {
    api.get('/apps/427391/android').pipe(fs.createWriteStream('android.apk'));
});

Build Android without signing

I would like to generate an .apk without singing. This option on the PhoneGap Build website as "No Key selected". How can i replicate this functionality using this library. Thanks for the help.

Wrong hadnling of 302 redirects

Hi everybody,

To describe this issue let's start from official Read API docs: https://build.phonegap.com/docs/read_api

For example the GET https://build.phonegap.com/api/v1/apps/:id/icon method contains the description of two different behaviors:

"In the successful case, this API method will return a 302 redirect to the icon file - the actual body of the response will point to the resource in question"

That means, that if we will follow the 302 redirect, than we will recieve the actual icon data, in other case - we should get the object with the location field, which points to the requested resource.

{
    "location":"http://s3.amazonaws.com/build.phonegap.com/some-long-guid/icon.png"
}

Currently, if we pass the followRedirect: false to API call, than we get the response in err parameter of callback, wrapped into Error object. So, considering the next example:

api.get(path, {followRedirect: false}, function(err, data) {
     return cb(err, data);
});

... we will get the undefined data param, and [Error: "{location: "..."}"] in error param.

Link to the root of issue: https://github.com/phonegap/node-phonegap-build-api/blob/master/lib/api.js#L208

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.