mradionov / phonegap-build-api
用于与 Phonegap Build API 交互的 PHP 库
This package is auto-updated.
Last update: 2024-09-21 20:50:43 UTC
README
用于与 Phonegap Build API 交互的 PHP 库
支持
库开发时使用的最新版本的 Cordova (Phonegap) - 3.1.0。包含此版本 API 中提供的所有方法。无论如何,它必须与 5+ 的最新版本 Cordova (Phonegap) 一起工作。
操作系统支持: iOS、Android。
需要安装并启用 CURL PHP 扩展,否则将触发 PHP 错误。
安装
通过命令行使用 Composer 安装
$ composer require mradionov/phonegap-build-api
或者将其添加到 composer.json
{
"require": {
"mradionov/phonegap-build-api": "^0.1.0"
}
}
并运行
$ composer install
使用
PhonegapBuildApi 构造函数接受两个参数,第二个参数是可选的。如果只提供一个参数,则必须是身份验证令牌。如果有两个,则必须是用户名和密码。否则,您总是可以使用公共方法 setToken() 和 setCredentials() 在以后提供身份验证参数。还有一个静态 factory 方法以不同的方式使用 API
use PhonegapBuildApi; // Use token $api = new PhonegapBuildApi('authentication_token'); // Use username and password $api = new PhonegapBuildApi('email@example.com', 'password'); // Set auth options after init $api = new PhonegapBuildApi(); $api->setToken('authentication_token'); $api->setCredentials('email@example.com', 'password'); // Use factory $res = PhonegapBuildApi::factory('email@example.com', 'password')->getProfile();
注意:上述身份验证令牌来自 Phonegap Build 账户 -> "编辑账户" 页面 -> "身份验证令牌" 部分。
要从 OAuth2 流中获取访问令牌,请使用 setAccessToken() 方法
use PhonegapBuildApi; $api = new PhonegapBuildApi(); $api->setAccessToken('d4f5g6');
处理响应
每个 API 方法都将响应作为从 JSON 创建的关联数组返回(如果成功)。您可以使用方法 success() 来检查最后一个请求是否成功。您可以使用方法 error() 来获取错误消息,如果请求失败。
$res = $api->getProfile(); if ($api->success()) { var_dump($res['email']); // 'email@example.com' } else { var_dump($api->error()); // 'Invalid email or password.' }
API
GET /api/v1/me (文档)
$res = $api->getProfile();
GET /api/v1/apps (文档)
$res = $api->getApplications();
GET /api/v1/apps/:id (文档)
$res = $api->getApplication(5);
GET /api/v1/apps/:id/icon (文档)
$res = $api->getApplicationIcon(5);
GET /api/v1/apps/:id/:platform (文档)
$res = $api->downloadApplicationPlatform(5, PhonegapBuildApi::IOS); $res = $api->downloadApplicationPlatform(5, PhonegapBuildApi::ANDROID);
GET /api/v1/keys (文档)
$res = $api->getKeys();
GET /api/v1/keys/:platform (文档)
$res = $api->getKeysPlatform(PhonegapBuildApi::IOS); $res = $api->getKeysPlatform(PhonegapBuildApi::ANDROID);
GET /api/v1/keys/:platform/:id (文档)
$res = $api->getKeyPlatform(PhonegapBuildApi::IOS, 3); $res = $api->getKeyPlatform(PhonegapBuildApi::ANDROID, 3);
POST /api/v1/apps (文档)
$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 ));
从远程仓库(首选)
$res = $api->createApplicationFromRepo('https://github.com/phonegap/phonegap-start', array( 'title' => 'Phonegap Application', // see docs for all options ));
从文件(首选)
$res = $api->createApplicationFromFile('/path/to/archive.zip', array( 'title' => 'Phonegap Application', // see docs for all options ));
PUT /api/v1/apps/:id (文档)
$res = $api->updateApplication(5, array( 'title' => 'Phonegap Application', // better use methods below or see docs for all options ));
从远程仓库(首选)
$res = $api->updateApplicationFromRepo(5, array( 'title' => 'Phonegap Application', // see docs for all options ));
从文件(首选)
$res = $api->updateApplicationFromFile(5, '/path/to/archive.zip', array( 'title' => 'Phonegap Application', // see docs for all options ));
POST /api/v1/apps/:id/icon (文档)
$res = $api->updateApplicationIcon(5, '/path/to/icon.png');
POST /api/v1/apps/:id/build (文档)
$res = $api->buildApplication(5, array( PhonegapBuildApi::IOS, PhonegapBuildApi::ANDROID ));
POST /api/v1/apps/:id/build/:platform (文档)
$res = $api->buildApplicationPlatform(5, PhonegapBuildApi::IOS); $res = $api->buildApplicationPlatform(5, PhonegapBuildApi::ANDROID);
POST /api/v1/apps/:id/collaborators (文档)
$res = $api->addCollaborator(5, array( 'email' => 'collab@example.com', 'role' => PhonegapBuildApi::ROLE_TESTER, // PhonegapBuildApi::ROLE_DEV // see docs for all options ));
PUT /api/v1/apps/:id/collaborators/:id (文档)
$res = $api->updateCollaborator(5, 7, array( 'role' => PhonegapBuildApi::ROLE_TESTER, // PhonegapBuildApi::ROLE_DEV // see docs for all options ));
POST /api/v1/keys/:platform (文档)
$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 特定(优先)
$res = $api->addKeyAndroid('Key Title', '/path/to/key.keystore', array( 'alias' => 'release', // see docs for all options ));
iOS 特定(优先)
$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 (文档)
$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 特定(优先)
$res = $api->updateKeyIos(3, 'key_password');
iOS 特定(优先)
$res = $api->updateKeyAndroid(3, 'key_password', 'keystore_password');
DELETE /api/v1/apps/:id (文档)
$res = $api->deleteApplication(5);
DELETE /api/v1/apps/:id/collaborators/:id (文档)
$res = $api->deleteCollaborator(5, 7);
DELETE /api/v1/keys/:platform/:id (文档)
$res = $api->deleteKeyPlatform(PhonegapBuildApi::IOS, 3); $res = $api->deleteKeyPlatform(PhonegapBuildApi::ANDROID, 3);