woganmay / domo-php
使用 PHP 与 Domo.com APIs
Requires
- php: ^8
- ext-curl: *
- guzzlehttp/guzzle: *
Requires (Dev)
- phpunit/phpunit: 10.2.3
This package is auto-updated.
Last update: 2024-09-17 12:28:33 UTC
README
非官方 PHP 库,用于与 Domo.com APIs 交互。MIT 许可证。
❔ 关于此项目
Domo.com 提供了一系列平台 API,版本为 v1。此库旨在封装所有这些端点,并通过 PHP 使其易于使用。该库最初于 2018 年(当时 API 仍在测试阶段)构建,截至 2023 年 7 月,此库正在进行改造,以考虑新的端点、方法和作用域。
如果您在项目中使用此库并遇到困难,可以通过以下方式获得帮助
- 提交带有重现步骤的新问题: https://github.com/woganmay/domo-php/issues/new
- 向项目维护者发送电子邮件以获得直接支持: wogan.may@gmail.com
⚠️ 关于 v0.2.2
截至 v0.2.2
(发布日期 2023 年 7 月 8 日),此库已被下载超过 10,000 次。此版本的库支持 2018 年大多数可用的 API,并包含一些用于常见任务的 Helper。从现在开始,此项目将会有破坏性的更改,包括
- 将移除 Helper - 该功能更适合作为独立的库
- 客户端将重构为至少需要 PHP 8.1,并利用较新的语言功能
- DomoPHP 客户端将更新以实现截至 2023 年 7 月的 Domo 的所有 API 方法
如果您不想立即处理任何破坏性更改,建议在 composer.json 中将依赖锁定在此特定版本
"require": {
"woganmay/domo-php": "v0.2.2"
}
v0.2.2
下的旧方法将不再在未来版本中得到支持。从 v0.3
及以后版本开始,库将使用不同的对象模式,您调用方法的方式也将有所不同。
🛣️ 通向 v1.0.0 的道路
此库的目的是与 Domo 开发者网站上记录的 API 保持一致。所有客户端代码都将从头开始重新实现。路线图目前如下
Domo 文档 URL: https://developer.domo.com/portal/8ba9aedad3679-ap-is
一旦所有服务都已实现且可测试,将发布 v1.0.0
版本,这应该是相当长一段时间内的最后一个主要版本!新版本仅会在 API 发生变化或处理依赖项和安全更新时发生。
⚙️ 安装
确保您有一个有效的 Domo 账户,并在 developer.domo 网站上生成访问令牌
通过 composer 安装
composer require woganmay/domo-php
加载后,您将能够创建一个新的 DomoPHP 对象,如下所示
use WoganMay\DomoPHP\Client; // Create a new instance by passing in the client ID and Secret yourself $client = new Client("your-client-id", "your-client-secret"); // Or, if you can set environment variables (DOMO_CLIENT_ID and DOMO_CLIENT_SECRET), the Client // can read those, letting you simply do this: $client = new Client(); // That's the recommended approach when using a framework (like Laravel) that reads .env variables into // your environment! You can now call API methods via the $client object, for eg: $allUsers = $client->user()->getList(); // Every API has a helper proxy method, as follows: $client->account(); // Account API $client->activityLog(); // Activity Log API $client->dataSet(); // DataSet API $client->embedToken(); // Embed Token API $client->group(); // Group API $client->page(); // Page API $client->projects(); // Projects and Tasks API $client->simple(); // Simple API $client->stream(); // Stream API $client->user(); // User API
📝 示例:创建并填充数据集
此方法适用于简单的、小的 CSV 加载 - 总共 1,000 条记录。对于更大的加载,Domo 建议使用流 API。
use WoganMay\DomoPHP\Client; $client = new Client(); // The domo-php library expects key-value pairs, where the keys are the column headers, and the values // are the data type. Valid types are: STRING, DECIMAL, LONG, DOUBLE, DATE, DATETIME $schema = [ 'id' => 'LONG', 'name' => 'STRING', 'created_at' => 'DATETIME' ]; // This will create a new, empty dataset with our schema $dataset = $client->dataSet()->create("My new dataset", $schema); // We'll build a simple set of CSV data, though in real life you'd be reading this directly from a file, // using file_get_contents() or similar. Domo expects \n line endings, and for the first line of the provided // data to include the CSV headers, matching the name, casing and order of the schema declared earlier. $csv = "id,name,created_at\n"; $csv .= "1,John Doe,2023-07-07 13:00:00\n"; $csv .= "2,Jane Doe,2023-07-08 14:00:00\n"; $csv .= "3,Bob Smith,2023-07-09 15:00:00\n"; // We can now import data directly into the dataset: $importResult = $client->dataSet()->import($dataset->id, $csv); // The import process can take up to 10 seconds to complete on Domo's side, so within 10 seconds after // completing the above, we should now be able to query our data back out. This query would return two rows // of data, based on the sample loaded above: $queryResult = $client->dataSet()->query($dataset->id, "SELECT * FROM table WHERE id >= 2");