fiveam-code / laravel-notion-api
Laravel 对 Notion API 的封装
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.0.1
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^6.0|^8.0|^9.0
- pestphp/pest: ^1.22|^2.34
- pestphp/pest-plugin-laravel: ^1.3|^2.3
- phpunit/phpunit: ^9.0|^10.5
- dev-main
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0.0
- v0.8.1
- v0.8.0
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.0
- v0.1.0-alpha
- dev-2.0.0-beta
- dev-dev
- dev-feature/retrieve-page-property-items
- dev-refactor/snapshot-replay-testing
- dev-feature/database-creation
- dev-feature/notion-models-and-commands
- dev-feature/resolve
- dev-fix/as-text-for-scalar-values
- dev-refactor/record-and-fake-tests
- dev-fix/notion-exception-null-error
- dev-refactor/tests-use-phpvcr
- dev-feature/comments
- dev-feature/add-database-attributes
- dev-feature/create-timestampable-trait
- dev-feature/allow-filter-collections
- dev-page-and-property-polish
- dev-feature/compound-filters
- dev-feature/allow-single-sorting-in-query
- dev-fix/changed-property-structure
This package is auto-updated.
Last update: 2024-09-02 21:04:02 UTC
README
文档
要查看更全面的文档、更多上下文和用法示例,请访问官方文档 notionforlaravel.com。
快速入门指南
所有示例都参照我们的测试数据库,您可以在此处找到。
安装
该包与 Laravel 8、9 和 10 兼容。最低 PHP 要求为 8.0。
-
通过 composer 安装包
composer require fiveam-code/laravel-notion-api
-
获取您的 Notion API 访问令牌,如 他们的文档 中所述。同样重要的是在 Notion 页面上授予集成访问权限,这也在 Notion 的开发者文档中有所描述。
-
在您的应用程序的
.env
文件中添加新行NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"
-
您已经准备好了!现在您可以通过
Notion
门面访问 Notion 端点use \Notion; Notion::databases()->find("8284f3ff77e24d4a939d19459e4d6bdc");
这就完了。
有关详细用法信息和可用端点的列表,请参阅(文档)。
示例
获取 Notion 数据库
databases()->find()
方法返回一个 FiveamCode\LaravelNotionApi\Entities\Database
对象,其中包含有关数据库的所有信息,包括其属性和每个属性的可能的值。
use \Notion; Notion::databases() ->find("8284f3ff77e24d4a939d19459e4d6bdc");
获取 Notion 页面
pages()->find()
方法返回一个 FiveamCode\LaravelNotionApi\Entities\Page
对象,其中包含有关页面的一切信息,包括其属性和每个属性的可能的值。
Notion::pages() ->find("e7e5e47d-23ca-463b-9750-eb07ca7115e4");
搜索
search()
端点返回与搜索查询匹配的页面集合。搜索范围限制在安装集成的 workspace 和与集成共享的页面。
Notion::search("Search term") ->query() ->asCollection();
查询数据库
database()
端点允许您查询特定的数据库,并返回一个页面集合(即数据库条目)。您可以过滤和排序结果,并限制返回条目的数量。有关可用过滤器和排序的详细信息,请参阅 文档。
use FiveamCode\LaravelNotionApi\Query\Filters\Filter; use FiveamCode\LaravelNotionApi\Query\Filters\Operators; $nameFilter = Filter::textFilter('Name', Operators::EQUALS, 'Ada Lovelace'); \Notion::database("8284f3ff77e24d4a939d19459e4d6bdc") ->filterBy($nameFilter) ->limit(5) ->query() ->asCollection();
还提供了用于 AND 或 OR 查询的复合过滤器
use Illuminate\Support\Collection; use FiveamCode\LaravelNotionApi\Query\Filters\Filter; use FiveamCode\LaravelNotionApi\Query\Filters\FilterBag; use FiveamCode\LaravelNotionApi\Query\Filters\Operators; use FiveamCode\LaravelNotionApi\Query\Sorting; # Give me all entries that are # (KnownFor == UNIVAC || KnownFor == ENIAC) # and sort them by name ascending $filterBag = new FilterBag(Operators::AND); $filterBag->addFilter( Filter::rawFilter("Known for", [ "multi_select" => [Operators::CONTAINS => "UNIVAC"], ]) ); $filterBag->addFilter( Filter::rawFilter("Known for", [ "multi_select" => [Operators::CONTAINS => "ENIAC"], ]) ); \Notion::database("8284f3ff77e24d4a939d19459e4d6bdc") ->filterBy($filterBag) ->sortBy(Sorting::propertySort('Name', 'ascending')) ->limit(5) ->query() ->asCollection();
测试
您可以通过检查 /tests
目录中的包测试来找到更多用法示例。我们使用 Pest 进行测试,并正在将所有现有的 PHPUnit 测试转换为 Pest。
如果您想在 CLI 中运行测试
vendor/bin/pest tests
支持
由 Tinkerwell 支持
本包的开发由 Tinkerwell 支持。
贡献
有关详细信息,请参阅 CONTRIBUTING。
安全
如果您发现任何安全相关的问题,请通过电子邮件 hello@dianaweb.dev 而不是使用问题跟踪器。
版权信息
许可证
MIT 许可证(MIT)。有关更多信息,请参阅许可证文件。