immobiliarelabs/braze-sdk
Composer 安装命令:
composer require immobiliarelabs/braze-sdk
包简介
An sdk to interact with Braze API
README 文档
README
A PHP client to interact with Braze API
Braze offers a cloud-based customer engagement platform for multichannel marketing. This SDK allows you to integrate its REST API into a PHP application.
Table of Contents
Features
- Explicit representation of the API contract to write requests easily using the IDE autocomplete
- Formal validation (strict and non-strict) of requests
- Dry-run mode to simulate requests and validate them without actually performing calls
- Ability to use any http client via an adapter. For PSR-18 compatible clients and the Symfony client, adapters are included in the SDK
- Parallel API calls supported if the http client allows it (for example the Symfony one)
Install
Add the SDK as a dependency running:
composer require immobiliarelabs/braze-sdk
If not already included in your project, to make http requests, you need to install any combination of packages that implements:
psr/http-client-implementationorsymfony/http-client-contractspsr/http-factory-implementationpsr/http-message-implementation
for example by installing symfony/http-client and nyholm/psr7 you are ready to use the SDK, also with parallel requests.
Alternatively, it is also possible to use any http client by creating the appropriate adapter.
Usage
Example
Before instantiating the SDK it is necessary to create the http client and its adapter.
use ImmobiliareLabs\BrazeSDK\ClientAdapter\SymfonyAdapter; use Symfony\Component\HttpClient\HttpClient; $client = HttpClient::create(); $adapter = new SymfonyAdapter($client);
This example is for the Symfony http client, but the flow is the same whether you are using a PSR-18 client or a custom one. Then you can create the SDK instance.
use ImmobiliareLabs\BrazeSDK\Braze; use ImmobiliareLabs\BrazeSDK\Region; $braze = new Braze($adapter, 'my-api-key', Region::EU01);
Now you can start making requests by creating one and passing it to the appropriate endpoint.
use ImmobiliareLabs\BrazeSDK\Object\Event; use ImmobiliareLabs\BrazeSDK\Request\Users\TrackRequest; $event = new Event(); $event->external_id = 'user-id'; $event->app_id = 'app-id'; $event->name = 'event-name'; $event->time = new \DateTimeImmutable(); $event->properties = ['property' => 'property-value']; $request = new TrackRequest(); $request->events = [$event]; $response = $braze->users()->track($request, false);
You can also set connection and overall timeout.
$braze->setConnectionTimeout(2.0); $braze->setOverallTimeout(3.0);
Currently, SymfonyAdapter supports them, while Psr18Adapter does not.
You can see a few complete examples in the repository.
Custom user attributes
To set custom User attributes use the setCustomAttribute or setCustomAttributes methods available in the UserAttributes class.
use ImmobiliareLabs\BrazeSDK\Object\UserAttributes; $userAttributes = new UserAttributes(); $userAttributes->external_id = 'user-id'; $userAttributes->first_name = 'Name'; $userAttributes->setCustomAttribute('custom_int_property', 47); $userAttributes->setCustomAttributes([ 'custom_string_property' => 'properyValue', 'custom_bool_property' => false, ]); $request = new TrackRequest(); $request->attributes = [$userAttributes]; $response = $braze->users()->track($request, false);
Endpoints
Endpoints are organized by url prefix. The SDK supports all the Braze endpoints:
- users
- campaigns
- canvas
- messages
- content_blocks
- templates
- events
- feed
- purchases
- sessions
- sends
- transactional
- subscription
Validation and dry-run
The SDK does a formal validation of the request before executing it. It is however possible to disable it completely:
$braze->setValidation(false);
or just the strict one, since Braze partially executes requests when possible:
$braze->setValidation(true, false);
By default, the SDK performs strict validation.
If you want to validate your requests without sending them to Braze you can enable dry-run mode:
$braze->setDryRun(true);
HTTP client adapter
If, in your project, you already have a http client which does not implement one of the two supported interfaces (Symfony and PSR18),
and you don't want to install another one, just define an adapter that implements the ImmobiliareLabs\BrazeSDK\ClientAdapter\ClientAdapterInterface interface,
and use it when instantiate the SDK.
Parallel requests
If the chosen http client supports asynchronous calls, you can exploit that to make parallel requests to Braze in this way:
$response1 = $braze->users()->track($request1, true); $response2 = $braze->users()->track($request2, true); $braze->flush();
The response objects will be filled with the values obtained only after the call to flush.
Compatibility
| Version | Status | PHP compatibility |
|---|---|---|
| 1.x | unmaintained | >=7.2 |
| 2.x | maintained | >=8.0 |
| 3.x | maintained | >=8.1 |
Requirements
- ext-json
Powered Apps
Braze PHP SDK was created by the PHP team at ImmobiliareLabs, the Tech dept of Immobiliare.it, the #1 real estate company in Italy.
We are currently using this SDK to stay in touch with our users.
If you are using Braze PHP SDK in production drop us a message.
Contributing
Any questions, bug reports or suggestions for improvement are very welcome. See the contributing file for details on how to contribute.
Changelog
Please refer to the changelog notes.
License
Braze PHP SDK is licensed under the MIT license.
See the LICENSE file for more information.
immobiliarelabs/braze-sdk 适用场景与选型建议
immobiliarelabs/braze-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 84.79k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2022 年 01 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「client」 「sdk」 「API-Client」 「client-library」 「sdk-php」 「braze」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 immobiliarelabs/braze-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 immobiliarelabs/braze-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 immobiliarelabs/braze-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Skolkovo API Client
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
A client library for the OpenPLZ API project
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%).
统计信息
- 总下载量: 84.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-21