Skip to content

Commit fb94f87

Browse files
authored
Merge pull request #97 from 5am-code/dev
features, refactoring and fixes for 1.0.0
2 parents 1e259ff + 0366545 commit fb94f87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+4020
-1873
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
php:
1313
- '8.1'
1414
- '8.0'
15-
- '7.4'
1615
laravel:
1716
- '8.*'
1817
testbench:
@@ -45,4 +44,4 @@ jobs:
4544
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
4645
4746
- name: Execute tests
48-
run: vendor/bin/phpunit tests
47+
run: vendor/bin/pest tests

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ If the project maintainer has any additional requirements, you will find them li
4242

4343
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
4444

45-
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
45+
- **Add tests!** - Your pull request won't be accepted if it doesn't have tests. When implementing new tests, please use the Pest PHP framework. You can find examples and detailed documentation at [pestphp.com](https://pestphp.com/).
4646

47-
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
47+
- **Document any change in behaviour** - Make sure the `README.md` is kept up-to-date. If you implement a new feature or propose significant changes to an existing feature, you will have to provide the documentation for these as well. The maintainers of the project will inform you about the process if necessary.
4848

4949
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
5050

5151
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
5252

5353
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
5454

55-
**Happy coding**!
55+
**Happy coding!** 🚀!

README.md

Lines changed: 124 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
<h1 align="center"> Laravel Notion API</h1>
2-
<h2 align="center"> Effortless Notion integrations with Laravel</h2>
1+
<h1 align="center"> Notion for Laravel</h1>
32

4-
<p align="center">
5-
<img src="https://5amco.de/images/5am.png" width="200" height="200">
6-
</p>
3+
<img src="open-graph.png">
74

85
[![Latest Version on Packagist](https://img.shields.io/packagist/v/fiveam-code/laravel-notion-api.svg?style=flat-square)](https://packagist.org/packages/fiveam-code/laravel-notion-api)
96
[![Total Downloads](https://img.shields.io/packagist/dt/fiveam-code/laravel-notion-api.svg?style=flat-square)](https://packagist.org/packages/fiveam-code/laravel-notion-api)
@@ -14,90 +11,156 @@ This package provides a simple and crisp way to access the Notion API endpoints,
1411

1512
## Installation
1613

17-
You can install the package via composer:
14+
The package is compatible with Laravel 8, 9 and 10 with their respective PHP versions.
1815

19-
```bash
20-
composer require fiveam-code/laravel-notion-api
21-
```
16+
1. Install the package via composer:
2217

23-
### Authorization
18+
```bash
19+
composer require fiveam-code/laravel-notion-api
20+
```
2421

25-
The Notion API requires an access token and a Notion integration, [the Notion documentation](https://developers.notion.com/docs/getting-started#before-we-begin) explains how this works. It's important to grant access to the integration within your Notion account to enable the API access.
22+
2. Get your Notion API access token like explained in [their documentation](https://developers.notion.com/). It's also
23+
important to grant access to the integration within your Notion pages, which is described in the developer
24+
documentation at Notion as well.
2625

27-
Add your Notion API token to your `.env` file:
26+
3. Add a new line to your applications `.env` file:
2827

29-
```
30-
NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"
31-
```
28+
```bash
29+
NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"
30+
```
3231

33-
## Usage
32+
4. You're ready to go! You can now access Notion endpoints through the `Notion` facade:
3433

35-
Head over to the [Documentation](https://5amco.de/docs) of this package.
34+
```php
35+
use \Notion;
3636

37-
### 🔥 Code Examples to jumpstart your Notion API Project
37+
Notion::databases()->find("8284f3ff77e24d4a939d19459e4d6bdc");
38+
```
3839

39-
#### Basic Setup (+ example)
40-
```php
41-
use FiveamCode\LaravelNotionApi\Notion;
40+
That's it.
41+
42+
For detailed usage information and a list of available endpoints see (the docs).
43+
44+
## Examples
4245

43-
# Access through Facade (token has to be set in .env)
44-
\Notion::databases()->find($databaseId);
46+
All examples refer to our test database, which you can
47+
find [here](https://dianawebdev.notion.site/8284f3ff77e24d4a939d19459e4d6bdc?v=bc3a9ce8cdb84d3faefc9ae490136ac2).
4548

46-
# Custom instantiation (necessary if you want to access more than one NotionApi integration)
47-
$notion = new Notion($apiToken, $apiVersion); // version-default is 'v1'
48-
$notion->databases()->find($databaseId);
49+
### Fetch a Notion Database
50+
51+
The `databases()->find()` method returns a `FiveamCode\LaravelNotionApi\Entities\Database` object,
52+
which contains all the information about the database, including its properties and the possible values for each
53+
property.
54+
55+
```php
56+
use \Notion;
57+
58+
Notion::databases()
59+
->find("8284f3ff77e24d4a939d19459e4d6bdc");
4960
```
5061

51-
#### Fetch Page Information
62+
### Fetch a Notion Page
63+
64+
The `pages()->find()` method returns a `FiveamCode\LaravelNotionApi\Entities\Page` object,
65+
which contains all the information about the page, including its properties and the possible values for each property.
66+
5267
```php
53-
// Returns a specific page
54-
\Notion::pages()->find($yourPageId);
68+
Notion::pages()
69+
->find("e7e5e47d-23ca-463b-9750-eb07ca7115e4");
5570
```
5671

57-
#### Search
72+
### Search
73+
74+
The `search()` endpoint returns a collection of pages that match the search query. The scope of the search is limited to
75+
the workspace that the integration is installed in
76+
and the pages that are shared with the integration.
77+
5878
```php
59-
// Returns a collection pages and databases of your workspace (included in your integration-token)
60-
\Notion::search($searchText)
79+
Notion::search("Search term")
6180
->query()
6281
->asCollection();
6382
```
6483

65-
#### Query Database
84+
### Query Database
85+
86+
The `database()` endpoint allows you to query a specific database and returns a collection of pages (= database
87+
entries).
88+
You can filter and sort the results and limit the number of returned entries. For detailed information about the
89+
available
90+
filters and sorts, please refer to the [documentation](https://developers.notion.com/reference/post-database-query).
6691

6792
```php
68-
// Queries a specific database and returns a collection of pages (= database entries)
69-
$sortings = new Collection();
70-
$filters = new Collection();
71-
72-
$sortings
73-
->add(Sorting::propertySort('Ordered', 'ascending'));
74-
$sortings
75-
->add(Sorting::timestampSort('created_time', 'ascending'));
76-
77-
$filters
78-
->add(Filter::textFilter('title', ['contains' => 'new']));
79-
// or
80-
$filters
81-
->add(Filter::rawFilter('Tags', ['multi_select' => ['contains' => 'great']]));
82-
83-
\Notion::database($yourDatabaseId)
84-
->filterBy($filters) // filters are optional
85-
->sortBy($sortings) // sorts are optional
86-
->limit(5) // limit is optional
87-
->query()
88-
->asCollection();
93+
use FiveamCode\LaravelNotionApi\Query\Filters\Filter;
94+
use FiveamCode\LaravelNotionApi\Query\Filters\Operators;
95+
96+
$nameFilter = Filter::textFilter('Name', Operators::EQUALS, 'Ada Lovelace');
97+
98+
\Notion::database("8284f3ff77e24d4a939d19459e4d6bdc")
99+
->filterBy($nameFilter)
100+
->limit(5)
101+
->query()
102+
->asCollection();
89103
```
90104

105+
Compound filters for AND or OR queries are also available:
106+
107+
```php
108+
use Illuminate\Support\Collection;
109+
use FiveamCode\LaravelNotionApi\Query\Filters\Filter;
110+
use FiveamCode\LaravelNotionApi\Query\Filters\FilterBag;
111+
use FiveamCode\LaravelNotionApi\Query\Filters\Operators;
112+
use FiveamCode\LaravelNotionApi\Query\Sorting;
113+
114+
# Give me all entries that are
115+
# (KnownFor == UNIVAC || KnownFor == ENIAC)
116+
# and sort them by name ascending
117+
118+
$filterBag = new FilterBag(Operators::AND);
119+
120+
$filterBag->addFilter(
121+
Filter::rawFilter("Known for", [
122+
"multi_select" => [Operators::CONTAINS => "UNIVAC"],
123+
])
124+
);
125+
126+
$filterBag->addFilter(
127+
Filter::rawFilter("Known for", [
128+
"multi_select" => [Operators::CONTAINS => "ENIAC"],
129+
])
130+
);
131+
132+
\Notion::database("8284f3ff77e24d4a939d19459e4d6bdc")
133+
->filterBy($filterBag)
134+
->sortBy(Sorting::propertySort('Name', 'ascending'))
135+
->limit(5)
136+
->query()
137+
->asCollection();
138+
```
91139

92-
### Testing
140+
### Testing (pestphp)
141+
142+
You can find even more usage examples by checking out the package tests in the `/tests` directory.
143+
The tests are making use of Pest PHP and we are working on switching from PHPUNIT to it (todo sentence).
144+
145+
If you want to run the tests in your CLI:
93146

94147
```bash
95-
vendor/bin/phpunit tests
148+
vendor/bin/pest tests
96149
```
97150

98151
## Support
99152

100-
If you use this package in one of your projects or just want to support our development, consider becoming a [Patreon](https://www.patreon.com/bePatron?u=56662485)!
153+
If you use this package in one of your projects or want to support our development, consider becoming
154+
a [Patreon Supporter](https://www.patreon.com/bePatron?u=56662485)!
155+
156+
### Supported by Tinkerwell
157+
158+
<a href="https://tinkerwell.app/">
159+
<img src="https://tinkerwell.app/images/tinkerwell_logo.png" width="64" height="64" alt="Tinkerwell"> <br/>
160+
</a>
161+
162+
The development of this package is supported by [Tinkerwell](https://tinkerwell.app/).
163+
101164

102165
## Contributing
103166

@@ -107,19 +170,15 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
107170

108171
If you discover any security related issues, please email hello@dianaweb.dev instead of using the issue tracker.
109172

110-
## Used By
111-
112-
- Julien Nahum created [notionforms.io](https://notionforms.io) with [laravel-notion-api](https://github.com/5am-code/laravel-notion-api), which allows you to easily create custom forms, based on your selected database within notion.
113-
- [GitHub Notion Sync](https://githubnotionsync.com/), a service by [Beyond Code](https://beyondco.de) to sync the issues of multiple GitHub repositories into a Notion database
114-
- [Notion Invoice](https://notioninvoice.com/), the first premium invoicing solution for freelancers and businesses that use Notion. Create beautiful PDF invoices from your Notion data.
115-
116-
Using this package in your project? Open a PR to add it in this section!
117-
118173
## Credits
119174

120175
- [Diana Scharf](https://github.com/mechelon)
121176
- [Johannes Güntner](https://github.com/johguentner)
122177

178+
<p align="center">
179+
<img src="https://5amco.de/images/5am.png" width="200" height="200">
180+
</p>
181+
123182
## License
124183

125184
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
}
2626
],
2727
"require": {
28-
"php": "^7.4|^8.0",
28+
"php": "^8.0",
2929
"guzzlehttp/guzzle": "^7.0.1",
30-
"illuminate/support": "^8.0|^9.0"
30+
"illuminate/support": "^8.0|^9.0|^10.0"
3131
},
3232
"require-dev": {
33-
"orchestra/testbench": "^6.0",
33+
"orchestra/testbench": "^6.0|^8.0",
34+
"pestphp/pest": "^1.22",
35+
"pestphp/pest-plugin-laravel": "^1.3",
3436
"phpunit/phpunit": "^9.0"
3537
},
3638
"autoload": {
@@ -46,9 +48,8 @@
4648
}
4749
},
4850
"scripts": {
49-
"test": "vendor/bin/phpunit",
50-
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
51-
51+
"test": "vendor/bin/pest",
52+
"test-coverage": "vendor/bin/pest --coverage-html coverage"
5253
},
5354
"config": {
5455
"sort-packages": true

0 commit comments

Comments
 (0)