PHP library to interact with Phonegap Build API
The latest version of Cordova (Phonegap) for the time when library was developed - 3.1.0. Contains all methods that are presented in this version of API. Anyways, it has to work with the latest versions of Cordova (Phonegap) 5+.
OS support: iOS, Android.
Requires CURL PHP extension to be installed and enabled, it will trigger a PHP error otherwise.
Install via Composer from command line:
$ composer require mradionov/phonegap-build-api
or add it to composer.json
:
{
"require": {
"mradionov/phonegap-build-api": "^0.1.0"
}
}
and run
$ composer install
PhonegapBuildApi
constructor accepts two arguments, second is optional. If only one argument is provided, then it has to be authentication token. If two - username and password. Otherwise, you can always provide auth params later using public methods setToken()
and setCredentials()
. There is also a static factory
method to use API in a different way:
use PhonegapBuildApi;
// Use token
$api = new PhonegapBuildApi('authentication_token');
// Use username and password
$api = new PhonegapBuildApi('[email protected]', 'password');
// Set auth options after init
$api = new PhonegapBuildApi();
$api->setToken('authentication_token');
$api->setCredentials('[email protected]', 'password');
// Use factory
$res = PhonegapBuildApi::factory('[email protected]', 'password')->getProfile();
Note: Authentication token mentioned above is taken from Phonegap Build account -> "Edit account" page -> "Authentication token" section.
To use access token from OAuth2 flow use a method setAccessToken():
use PhonegapBuildApi;
$api = new PhonegapBuildApi();
$api->setAccessToken('d4f5g6');
Each API method returns response as associative array created from JSON (if successful). You can use method success()
to check whether or not last request was successful. You can use method error()
to get error message, if request failed.
$res = $api->getProfile();
if ($api->success()) {
var_dump($res['email']); // '[email protected]'
} else {
var_dump($api->error()); // 'Invalid email or password.'
}
GET /api/v1/me (docs)
$res = $api->getProfile();
GET /api/v1/apps (docs)
$res = $api->getApplications();
GET /api/v1/apps/:id (docs)
$res = $api->getApplication(5);
GET /api/v1/apps/:id/icon (docs)
$res = $api->getApplicationIcon(5);
GET /api/v1/apps/:id/:platform (docs)
$res = $api->downloadApplicationPlatform(5, PhonegapBuildApi::IOS);
$res = $api->downloadApplicationPlatform(5, PhonegapBuildApi::ANDROID);
GET /api/v1/keys (docs)
$res = $api->getKeys();
GET /api/v1/keys/:platform (docs)
$res = $api->getKeysPlatform(PhonegapBuildApi::IOS);
$res = $api->getKeysPlatform(PhonegapBuildApi::ANDROID);
GET /api/v1/keys/:platform/:id (docs)
$res = $api->getKeyPlatform(PhonegapBuildApi::IOS, 3);
$res = $api->getKeyPlatform(PhonegapBuildApi::ANDROID, 3);
POST /api/v1/apps (docs)
$res = $api->createApplication(array(
'title' => 'Phonegap Application',
'package' => 'com.phonegap.www',
'version' => '0.0.1',
'description' => 'Phonegap Application Description',
'debug' => false,
'keys' => array(
'ios' => array(
'id' => 3,
'password' => 'key_password'
),
),
'private' => true,
'phonegap_version' => '3.1.0',
'hydrates' => false,
// better use methods below or see docs for all options
));
From remote repo (preferable):
$res = $api->createApplicationFromRepo('https://github.com/phonegap/phonegap-start', array(
'title' => 'Phonegap Application',
// see docs for all options
));
From file (preferable):
$res = $api->createApplicationFromFile('/path/to/archive.zip', array(
'title' => 'Phonegap Application',
// see docs for all options
));
PUT /api/v1/apps/:id (docs)
$res = $api->updateApplication(5, array(
'title' => 'Phonegap Application',
// better use methods below or see docs for all options
));
From remote repo (preferable):
$res = $api->updateApplicationFromRepo(5, array(
'title' => 'Phonegap Application',
// see docs for all options
));
From file (preferable):
$res = $api->updateApplicationFromFile(5, '/path/to/archive.zip', array(
'title' => 'Phonegap Application',
// see docs for all options
));
POST /api/v1/apps/:id/icon (docs)
$res = $api->updateApplicationIcon(5, '/path/to/icon.png');
POST /api/v1/apps/:id/build (docs)
$res = $api->buildApplication(5, array(
PhonegapBuildApi::IOS, PhonegapBuildApi::ANDROID
));
POST /api/v1/apps/:id/build/:platform (docs)
$res = $api->buildApplicationPlatform(5, PhonegapBuildApi::IOS);
$res = $api->buildApplicationPlatform(5, PhonegapBuildApi::ANDROID);
POST /api/v1/apps/:id/collaborators (docs)
$res = $api->addCollaborator(5, array(
'email' => '[email protected]',
'role' => PhonegapBuildApi::ROLE_TESTER, // PhonegapBuildApi::ROLE_DEV
// see docs for all options
));
PUT /api/v1/apps/:id/collaborators/:id (docs)
$res = $api->updateCollaborator(5, 7, array(
'role' => PhonegapBuildApi::ROLE_TESTER, // PhonegapBuildApi::ROLE_DEV
// see docs for all options
));
POST /api/v1/keys/:platform (docs)
$res = $api->addKeyPlatform(PhonegapBuildApi::IOS, array(
// better use methods below or see docs for all options
));
$res = $api->addKeyPlatform(PhonegapBuildApi::ANDROID, array(
// better use methods below or see docs for all options
));
Android specific (preferable):
$res = $api->addKeyAndroid('Key Title', '/path/to/key.keystore', array(
'alias' => 'release',
// see docs for all options
));
iOS specific (preferable):
$res = $api->addKeyIos('Key Title', '/path/to/key.p12', '/path/to/key.mobileprovision', array(
// see docs for all options
));
PUT /api/v1/keys/:platform/:id (docs)
$res = $api->updateKeyPlatform(PhonegapBuildApi::IOS, 3, array(
// better use methods below or see docs for all options
));
$res = $api->updateKeyPlatform(PhonegapBuildApi::ANDROID, 3, array(
// better use methods below or see docs for all options
));
Android specific (preferable):
$res = $api->updateKeyIos(3, 'key_password');
iOS specific (preferable):
$res = $api->updateKeyAndroid(3, 'key_password', 'keystore_password');
DELETE /api/v1/apps/:id (docs)
$res = $api->deleteApplication(5);
DELETE /api/v1/apps/:id/collaborators/:id (docs)
$res = $api->deleteCollaborator(5, 7);
DELETE /api/v1/keys/:platform/:id (docs)
$res = $api->deleteKeyPlatform(PhonegapBuildApi::IOS, 3);
$res = $api->deleteKeyPlatform(PhonegapBuildApi::ANDROID, 3);