fbng/netgalley-api-client
Composer 安装命令:
composer require fbng/netgalley-api-client
包简介
NetGalley Public API Client
关键字:
README 文档
README
The NetGalley Public REST API provides a way for NetGalley's partners to interact with the system. The library currently supports only PHP, but the API itself can of course be accessed via REST by any system.
Installation
To install with Composer, add the following to your composer.json file:
"require": {
...
"fbng/netgalley-api-client": "*",
...
},
Then run a composer update and you should be all set.
To install without Composer, download the latest archive, extract it to your project, and add the appropriate require_once line to your code:
require_once('/path/to/lib/NetGalley/API/Client.php');
If you are connecting to the NetGalley API using OAuth2 (more about this below), also add the require_once line:
require_once('/path/to/lib/NetGalley/API/OauthClient.php');
Usage
To use the client library, first obtain a set of API credentials from NetGalley (contact your concierge representative if you have any questions). These credentials will either be a Key / Secret pair or an OAuth Client ID / Secret pair, which will determine which method below you will use to access the NetGalley API.
Key / Secret connection method
If you have received Key / Secret credentials, use this example code as a basis for accessing the API:
use NetGalley\API\Client; // obtain your credentials from NetGalley $myUser = 'example'; $myApiKey = 'KEY'; $myApiSecret = 'SECRET'; // if set to true, the client will target a staging server $testMode = true; // instantiate the client using your credentials $client = new Client($myUser, $myApiKey, $myApiSecret, $testMode); // make an API request; see the relevant documentation // for details of the API you are requesting; here we // are creating a new widget for a customer $response = $client->makeRequest('/private/widgets', 'POST', array( 'email' => 'customer@gmail.com', 'isbn' => '1234567890123', 'market' => 'US', 'temporaryDrm' => false, 'firstName' => 'Some', 'lastName' => 'Customer' )); // the response will be a JSON-encoded string, so decode it $response = json_decode($response, true); // do something with the response echo 'Response was: ' . print_r($response, true) . PHP_EOL;
OAuth2 Client ID / Secret connection method
If you have received OAuth2 credentials, use this example code as a basis for accessing the API:
use NetGalley\API\OauthClient; // obtain your credentials from NetGalley $clientId = 'CLIENTID'; $clientSecret = 'SECRET'; // if requesting a token to grant third-party access, set the authorization // code captured by the redirect URI // // NOTE: the NetGalley API does not currently support authorizing third-party // access - this is included only to avoid conflicts in client implementations // in the future if it ever becomes a supported feature $authorizationCode = ''; // if set to true, the client will target a staging server $testMode = true; // instantiate the client using your credentials $client = new OauthClient($clientId, $clientSecret, $authorizationCode, $testMode); // request an access token once (will be set internally for subsequent requests) $client->requestToken(); // make requests and handle responses the same as above $response = null;
Handling Large Data Results
If you are granted access to any reporting APIs, you may foresee instances in your application where large data sets may be coming from the API. You can avoid loading the entire data set into memory by streaming the results directly into a temporary file.
In the example below, $responseFile is a file handle resource to a temporary file containing the response data from the API request. You can then write the file contents to the output buffer to provide a CSV download, for example, or rename the file to a permanent location.
$responseFile = $client->makeFileRequest('/private/reports/example_report', 'GET', array('filter' => 'example')); if ($responseFile !== false) { // Do something with $responseFile fclose($responseFile); }
API Documentation
See the API Documentation within this repository for up-to-date information on each REST API.
fbng/netgalley-api-client 适用场景与选型建议
fbng/netgalley-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 97 次下载、GitHub Stars 达 1, 最近一次更新时间为 2014 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「client」 「netgalley」 「firebrand」 「fbng」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fbng/netgalley-api-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fbng/netgalley-api-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fbng/netgalley-api-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
统计信息
- 总下载量: 97
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-21