jonathanraftery/bullhorn-rest-client
Composer 安装命令:
composer require jonathanraftery/bullhorn-rest-client
包简介
Simple REST client for the Bullhorn API, including automated OAuth2 login
README 文档
README
Provides a simple client for the Bullhorn REST API.
Installation
$ composer require jonathanraftery/bullhorn-rest-client
Usage
use jonathanraftery\Bullhorn\Rest\Client as BullhornClient; $client = new BullhornClient();
By default, the client will look for credentials in environment variables:
- BULLHORN_CLIENT_ID
- BULLHORN_CLIENT_SECRET
- BULLHORN_USERNAME
- BULLHORN_PASSWORD
Options
The client constructor accepts an option array.
use jonathanraftery\Bullhorn\Rest\Auth\CredentialsProvider\MemoryCredentialsProvider; use jonathanraftery\Bullhorn\Rest\Client as BullhornClient; use jonathanraftery\Bullhorn\Rest\ClientOptions; $client = new BullhornClient([ // NOTE: MemoryCredentialProvider not recommended for production ClientOptions::CredentialsProvider => new MemoryCredentialsProvider( 'clientId', 'clientSecret', 'username', 'password' ), ]);
The ClientOptions class can be used to view the available options.
Credential Providers
A credential provider supplies the client with the credentials needed to connect to the API. There are simple providers included, or you can create your own with a class implementing the CredentialsProviderInterface (for example, to fetch credentials from Google Cloud Secret Manager).
use jonathanraftery\Bullhorn\Rest\Client as BullhornClient; use jonathanraftery\Bullhorn\Rest\ClientOptions; use jonathanraftery\Bullhorn\Rest\Auth\CredentialsProvider\CredentialsProviderInterface; class CustomCredentialProvider implements CredentialsProviderInterface { public function getClientId() : string{ return 'id'; } public function getClientSecret() : string{ return 'secret'; } public function getUsername() : string{ return 'username'; } public function getPassword() : string{ return 'password'; } } $client = new BullhornClient([ ClientOptions::CredentialsProvider => new CustomCredentialProvider() ]);
By default, the client will use an EnvironmentCredentialsProvider, which will look in the environment variables listed above for credentials. The variables used can be changed by constructing an EnvironmentCredentialsProvider with the other variables.
Auth Data Stores
API session data needs persisted in a data store. By default, the client will use a local JSON file for this store, but custom stores can be used.
use jonathanraftery\Bullhorn\Rest\Client as BullhornClient; use jonathanraftery\Bullhorn\Rest\ClientOptions; use jonathanraftery\Bullhorn\Rest\Auth\Store\DataStoreInterface; class CustomDataStore implements DataStoreInterface { private $vars; public function get(string $key) : ?string{ return $this->vars[$key]; } public function store(string $key,$value){ $this->vars[$key] = $value; } } $client = new BullhornClient([ ClientOptions::AuthDataStore => new CustomDataStore() ]);
Initial OAuth consent
Before Bullhorn authorizes API calls from a new user, the user is required to give consent. If no consent has been given yet the library will throw an IdentityException and the client will respond with an HTML representation of the consent form.
To permanently fix this, visit the authorization URL with your credentials auth.bullhornstaffing.com/oauth/authorize?response_type=code&action=Login&username=&password=&state=<client_secret>&approval_prompt=auto&client_id=<client_id> while logged into bullhorn and press the Agree button. This will authorize your application to use the API in the user's name.
Raw Requests
Simple requests as documented in the Bullhorn API documentation can be run as:
use jonathanraftery\Bullhorn\Rest\Client as BullhornClient; $client = new BullhornClient(); $response = $client->rawRequest( 'GET', 'search/JobOrder', [ 'query' => 'id:1234' ] );
PUT/POST Requests
The client uses GuzzleHTTP for requests, and the parameters to the request method match those to create a request object in Guzzle. The third parameter is the request options, as described in the Guzzle documentation.
To set the body of a PUT/POST request, set the "body" option of the request to the JSON content of the request body such as:
use jonathanraftery\Bullhorn\Rest\Client as BullhornClient; $client = new BullhornClient(); $response = $client->rawRequest( 'PUT', 'entity/Candidate', [ 'body' => json_encode(['firstName' => 'Alanzo', 'lastName' => 'Smith', 'status' => 'Registered']) ] );
Entity Operations
Entities can be fetched, created, and deleted
use jonathanraftery\Bullhorn\Rest\Client as BullhornClient; use jonathanraftery\Bullhorn\Rest\BullhornEntities; $client = new BullhornClient(); $fetchedJobOrders = $client->fetchEntities(BullhornEntities::JobOrder, [1,2,3], [ 'fields' => 'id', ]); $createdJobOrder = $client->createEntity(BullhornEntities::JobOrder, [ 'propName' => 'value', 'propName2' => 'value', ]); $deleteId = 1; $client->deleteEntity(BullhornEntities::JobOrder, $deleteId);
Event Subscriptions
use jonathanraftery\Bullhorn\Rest\Client as BullhornClient; use jonathanraftery\Bullhorn\Rest\BullhornEntities; use jonathanraftery\Bullhorn\Rest\EventTypes; $client = new BullhornClient(); $client->createEventSubscription('SubscriptionName', [BullhornEntities::JobOrder], [EventTypes::Created]); $client->fetchEventSubscriptionEvents('SubscriptionName'); $client->deleteEventSubscription('SubscriptionName');
Sessions
A session will automatically be initiated upon the first request if no session exists in the data store.
A session can be manually initiated with:
use jonathanraftery\Bullhorn\Rest\Client as BullhornClient; $client = new BullhornClient(); $client->initiateSession();
The session will automatically refresh if expiration detected, or can be refreshed manually (shown with optional parameters)
use jonathanraftery\Bullhorn\Rest\Client as BullhornClient; $client = new BullhornClient(); $client->refreshSession(['ttl' => 60]);
jonathanraftery/bullhorn-rest-client 适用场景与选型建议
jonathanraftery/bullhorn-rest-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43.59k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2018 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「api」 「client」 「bullhorn」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jonathanraftery/bullhorn-rest-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jonathanraftery/bullhorn-rest-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jonathanraftery/bullhorn-rest-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
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%).
统计信息
- 总下载量: 43.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-17