kylewlawrence/gravity-forms-api-client-php
GForms API PHP SDK
Requires
- php: >=8.2
- doctrine/inflector: ^2.0
- guzzlehttp/guzzle: >=7.0
- guzzlehttp/psr7: >=2.0
Requires (Dev)
- bshaffer/phpunit-retry-annotations: ^0.3.0
- fzaninotto/faker: >=1.5.0
- phpmd/phpmd: @stable
- phpunit/phpunit: ^9.5
- psy/psysh: ^0.11
- squizlabs/php_codesniffer: 2.*
This package is auto-updated.
Last update: 2024-09-20 18:59:22 UTC
README
API客户端版本
这是Gravity Forms API的社区赞助PHP SDK客户端的第一个版本。
API版本支持
此客户端仅支持Gravity Forms的API v2。请参阅他们的API文档获取更多信息。
要求
- PHP 8.1+
安装
Gravity Forms API PHP SDK客户端可以通过Composer进行安装。
您是否正在使用Laravel?如果是,请使用Laravel包装器。
Composer
要安装,请运行composer require kylewlawrence/gravity-forms-api-client-php
配置
配置是通过一个GForms\Api\HttpClient
实例来完成的。该块是强制性的,如果不传递,将抛出错误。
// load Composer require 'vendor/autoload.php'; use KyleWLawrence\GForms\Api\HttpClient as GFormsAPI; $username = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; // replace this with your Gravity Forms api username $password = "fdsJfds43dMo1mRDMuVwkw1EPsNkeUj9fdjk376l"; // replace this with your Gravity Forms api password $domain = "example.com"; // replace this with the domain (and path) of your Gravity Forms installation $client = new GFormsAPI(); $client->setAuth('basic', ['username' => $username, 'password' => $password]);
用法
基本操作
// Get all forms $forms = $client->forms()->getAll(); print_r($forms); // Create a new form $newForm = $client->forms()->create([ 'title' => 'Blah Blah', 'fields' => [ { 'id' : '1', 'label' : 'My Text', 'type' : 'text' }, { 'id' : '2', 'label' : 'More Text', 'type' : 'text' } ], ]); print_r($newForm); // Update a form $client->forms()->update(12345, [ 'title' => 'New Title', 'fields' => [ { 'id' : '1', 'label' : 'New Field Label', 'type' : 'text' }, { 'id' : '2', 'label' : 'New Field Label #2', 'type' : 'text' } ], ]); // Delete a form $client->forms()->delete(12345); // Get all forms $forms = $client->forms()->getAll(); print_r($forms);
发现方法和类
// Get the base methods/classes available $client->getValidSubResrouces() // The above example will output something like: [ 'entries' => "GForms\Api\Resources\Core\Entries", 'forms' => "GForms\Api\Resources\Core\Forms", ] // These are methods/classes that can be chained to the client. For instance: // For instance, "forms" => "GForms\Api\Resources\Core\Forms", can be used as $client->forms() // To find the chained methods available to the class, now do: $client->forms()->getRoutes() // The above example will output something like: [ 'getAll' => 'forms', 'get' => 'forms/{id}', 'create' => 'forms', 'update' => 'forms/{id}', 'delete' => 'forms/{id}', ] // Those routes can be compared with the GForms documentation routes and run as chained methods such as the below command to get all sites: $client->forms()->getAll()
分页
GForms API提供了一种获取请求的下一页的方法,并在GForms开发者文档中进行了说明。
这样做的方法是将它作为选项传递给您的请求。
$forms = $this->client->forms()->getAll(['paging[page_size]' => 20, 'paging[current_page]' => 1]);
允许的选项有
- page_size
- current_page
- offset
重试请求
在您的GuzzleHttp\Client
实例的HandlerStack
上添加RetryHandler
中间件。默认情况下,GForms\Api\HttpClient
重试
- 超时请求
- 那些抛出
Psr\Http\Message\RequestInterface\ConnectException:class
- 以及那些抛出被识别为ssl问题的
Psr\Http\Message\RequestInterface\RequestException:class
。
可用的选项
选项作为值数组传递到RetryHandler
。
- max = 2 重试次数限制
- interval = 300 重试之间的基本延迟(毫秒)
- max_interval = 20000 最大延迟值
- backoff_factor = 1 退避因子
- exceptions = [ConnectException::class] 无需检查retry_if的重试异常
- retry_if = null 可以决定是否重试请求的可调用函数
贡献
欢迎提交拉取请求。我很快会制定贡献指南。在此期间,只需打开问题或创建拉取请求。
版权和许可证
版权所有 2023-present KyleWLawrence
根据Apache License,版本2.0(“许可证”);除非您遵守许可证规定,否则不得使用此文件。您可以在以下位置获得许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”基础提供,不提供任何明示或暗示的保证或条件。请参阅许可证以了解具体管理许可和限制的语言。