Skip to content

Latest commit

 

History

History
325 lines (230 loc) · 9.35 KB

README.md

File metadata and controls

325 lines (230 loc) · 9.35 KB

Phonegap Build API - PHP

PHP library to interact with Phonegap Build API

Support

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

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

Use

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

Handle response

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.'

}

API

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(1488);
GET /api/v1/apps/:id/icon (docs)
$res = $api->getApplicationIcon(1488);
GET /api/v1/apps/:id/:platform (docs)
$res = $api->downloadApplicationPlatform(1488, PhonegapBuildApi::IOS);
$res = $api->downloadApplicationPlatform(1488, 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, 228);
$res = $api->getKeyPlatform(PhonegapBuildApi::ANDROID, 228);
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' => 228,
      '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(1488, array(
  'title' => 'Phonegap Application',
  // better use methods below or see docs for all options
));

From remote repo (preferable):

$res = $api->updateApplicationFromRepo(1488, array(
  'title' => 'Phonegap Application',
  // see docs for all options
));

From file (preferable):

$res = $api->updateApplicationFromFile(1488, '/path/to/archive.zip', array(
  'title' => 'Phonegap Application',
  // see docs for all options
));
POST /api/v1/apps/:id/icon (docs)
$res = $api->updateApplicationIcon(1488, '/path/to/icon.png');
POST /api/v1/apps/:id/build (docs)
$res = $api->buildApplication(1488, array(
  PhonegapBuildApi::IOS, PhonegapBuildApi::ANDROID
));
POST /api/v1/apps/:id/build/:platform (docs)
$res = $api->buildApplicationPlatform(1488, PhonegapBuildApi::IOS);
$res = $api->buildApplicationPlatform(1488, PhonegapBuildApi::ANDROID);
POST /api/v1/apps/:id/collaborators (docs)
$res = $api->addCollaborator(1488, 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(1488, 69, 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, 228, array(
  // better use methods below or see docs for all options
));
$res = $api->updateKeyPlatform(PhonegapBuildApi::ANDROID, 228, array(
  // better use methods below or see docs for all options
));

Android specific (preferable):

$res = $api->updateKeyIos(228, 'key_password');

iOS specific (preferable):

$res = $api->updateKeyAndroid(228, 'key_password', 'keystore_password');
DELETE /api/v1/apps/:id (docs)
$res = $api->deleteApplication(1488);
DELETE /api/v1/apps/:id/collaborators/:id (docs)
$res = $api->deleteCollaborator(1488, 69);
DELETE /api/v1/keys/:platform/:id (docs)
$res = $api->deleteKeyPlatform(PhonegapBuildApi::IOS, 228);
$res = $api->deleteKeyPlatform(PhonegapBuildApi::ANDROID, 228);