via-work/lever-php
Composer 安装命令:
composer require via-work/lever-php
包简介
Super-simple, minimum abstraction Lever DATA API v1 wrapper in PHP with support for Laravel.
README 文档
README
Super-simple Lever Data API v1 wrapper in PHP with support for Laravel.
Installation
You can install the package via composer:
composer require via-work/lever-php
Usage
PHP
use \ViaWork\LeverPhp\LeverPhp; $lever = new LeverPhp('leverKey'); $lever->opportunities()->fetch();
Laravel
After installing, the package will automatically register its service provider.
To publish the config file to config/lever-php.php run:
php artisan vendor:publish --provider="ViaWork\LeverPhp\LeverPhpServiceProvider"
After changing your API keys in your ENV file accordingly, you can call a Lever instance as follows:
Lever::opportunities()->fetch();
Methods
This package is modeled after Lever's Data API documentation, so you should be able to find a method for many of the endpoints.
For example, if you would like to fetch all Opportunities you would simply call:
Lever::opportunities()->fetch();
To retrieve a single opportunity you should call the same method while passing the id as a parameter:
Lever::opportunities('250d8f03-738a-4bba-a671-8a3d73477145')->fetch();
To create an opportunity use the create method while passing the fields array (use same names as Lever):
$newOpportunity = [ 'name' => 'Shane Smith', 'headline' => 'Brickly LLC, Vandelay Industries, Inc, Central Perk', 'stage' => '00922a60-7c15-422b-b086-f62000824fd7', ... ]; Lever::opportunities()->create($newOpportunity);
When submiting an application on behalf of a candidate to a specific posting you should use the following method:
$application = [ 'customQuestions' => [...], 'personalInformation' => [...], 'ipAddress' => '184.23.195.146', ... ]; Lever::opportunities('730e37db-93d3-4acf-b9de-7cfc397cef1d') ->sendConfirmationEmail() ->apply($application);
When an update endpoint is available, you can do it as follows:
$posting = [ 'text' => 'Infrastructure Engineer', 'state' => 'published', ... ]; Lever::postings('730e37db-93d3-4acf-b9de-7cfc397cef1d') ->performAs('8d49b010-cc6a-4f40-ace5-e86061c677ed') ->update($posting);
Be aware of the resources that require some parameters to work. When creating a posting for example, the perform_as parameter is required. You can pass this information with the performAs($userId) method.
When a resource depends on another one to work, you can simply chain the methods (order is important). For example, to retrieve the offers of a opportunity, you should execute this:
Lever::opportunities('250d8f03-738a-4bba-a671-8a3d73477145')->offers()->fetch();
When Lever asks to use the PUT verb, you can use putUpdate() instead of update() (POST).
Parameters
There are many helper methods available to include parameters in a request. For example, to include the followers and expand applications and stages, when fetching opportunities, you can do so:
Lever::opportunities() ->include('followers') ->expand(['applications', 'stages']) ->expand('posting') ->fetch();
Notice you can pass a string or an array of strings in both methods, and you can chain the same method many times if you wish.
Not all parameters have a method available, but you can use the addParameter($field, $value) method for this. This method can be chained without overwriting previous values. For example:
Lever::opportunities() ->addParameter('origin', 'applied') ->addParameter('posting_id', 'f2f01e16-27f8-4711-a728-7d49499795a0') ->fetch();
Be aware that when using the same field name, the new value will be appended and not overwritten.
Uploading files and resumes
LeverPhp allows you to include resumes or files when available. To do this, you have to include the file in the fields array (see example) and chaining the hasFiles() method (before the create or update method!). For example, you can append a resume when creating an opportunity:
$newOpportunity = [ 'name' => 'Shane Smith', 'headline' => 'Brickly LLC, Vandelay Industries, Inc, Central Perk', 'resumeFile' => [ 'file' => file_get_contents('path/to/resume.pdf'), 'name' => 'resume.pdf' 'type' => mime_content_type('path/to/resume.pdf'), // application/pdf ] ]; Lever::opportunities()->hasFiles()->create($newOpportunity);
Currently, there is no support for multiple files in one call.
Pagination
All Lever resources with a list endpoint (candidates, users, postings) have pagination and a max limit of 100 results per page. LeverPhp handles this automatically leveraging Laravel LazyCollection class. For example, you can iterate over the whole set of Opportunities without worrying about pagination:
$opportunities = Lever::opportunities()->fetch(); foreach ($opportunities as $opportunity) { echo $opportunity['name]; }
When item hundred is reached, another call is made to the API requesting the next 100 items until there are no more left.
Of course you can take advantage of all methods available on the LazyCollection class.
Rate Limit and Exponential Backoff
By default, Lever API allows a steady state number of 10 requests/second per API key.
To comply with this, LeverPhp automatically limits the number of requests to the Lever Data API to 10 per second and uses exponential backoff to decrease the retry rate when a 429 or 500 response is received. Please plan you code accordingly, as a request might take much longer than expected because of this. Using some kind of queues is suggested.
By default, the rate limiter works in memory. This means that if you have a second PHP process (or Guzzle client) consuming the same API, you'd still possibly hit the rate limit.
The LeverPhp() constructor accepts a custom store in its third parameter to overcome the in memory issue. If you are using Laravel, a custom store that uses your cache driver is already configured. Please see the documentation of GuzzleRateLimiterMiddleware if you need more information.
Client
If a method is not available for the resource you are trying to reach, you can get an instance of the Guzzle client directly by calling Lever::client(). Feel free to add it to the source code. Please see CONTRIBUTING for details.
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email dev@via.work instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
via-work/lever-php 适用场景与选型建议
via-work/lever-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 526 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wrapper」 「jobs」 「data api」 「lever」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 via-work/lever-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 via-work/lever-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 via-work/lever-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Adds the EDTF data type to Wikibase
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
A simple library that allows transform any kind of data to native php data or whatever
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
This module enables subscription to latest jobs by email
统计信息
- 总下载量: 526
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-13