Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
9e09c06
Added the Pest dependency for future tests
mechelon Sep 8, 2022
42b3670
Merge pull request #80 from 5am-code/feature/add-pest-support
mechelon Sep 16, 2022
bc2c838
Moved existing FilterTest to PEST tests
mechelon Sep 20, 2022
1ddb0dd
WIP
mechelon Sep 25, 2022
5d1f3dc
Apply fixes from StyleCI (#83)
mechelon Sep 25, 2022
4802f81
WIP
mechelon Sep 26, 2022
7c12a43
Merge branch 'feature/compound-filters' of https://github.com/5am-cod…
mechelon Sep 26, 2022
fd73d83
Apply fixes from StyleCI (#84)
mechelon Sep 26, 2022
578b36c
Pest tests work now properly, thanks to @mpociot
mechelon Sep 26, 2022
f097a52
Merge branch 'feature/compound-filters' of https://github.com/5am-cod…
mechelon Sep 26, 2022
377ae88
Apply fixes from StyleCI (#85)
mechelon Sep 26, 2022
40354b6
search endpoint: fix cursor not passed correctly
Nov 15, 2022
e2a34be
NotionException: use status from http response
Nov 15, 2022
11639f5
Pest tests work now properly, thanks to @mpociot
mechelon Dec 7, 2022
e48aef4
use union types for sortBy method; removed PHP 7.4 support
mechelon Dec 7, 2022
cc624f3
updated tests for sortings; allowed union type in query helper
mechelon Dec 7, 2022
c561b8c
Apply fixes from StyleCI (#91)
mechelon Dec 7, 2022
a03a01e
removed sortBy method from Search endpoint because it's not allowed a…
mechelon Dec 7, 2022
f1067ee
Merge branch 'feature/allow-single-sorting-in-query' of https://githu…
mechelon Dec 7, 2022
f2d3c46
Apply fixes from StyleCI (#92)
mechelon Dec 7, 2022
0be3d15
change workflow to pest
mechelon Dec 7, 2022
9a67bcd
Merge branch 'feature/allow-single-sorting-in-query' of https://githu…
mechelon Dec 7, 2022
ed30338
Remove PHP 7.4 from workflow test matrix
mechelon Dec 7, 2022
44c3cc2
update composer.lock
danielh-official Dec 18, 2022
da70be2
add check on instance method that looks into payload for a "responseD…
danielh-official Dec 18, 2022
45c2924
add expectExceptionCode for all tests that check for exceptions to en…
danielh-official Dec 18, 2022
a76fdb3
Revert "update composer.lock"
danielh-official Dec 18, 2022
eb6747e
restore spacing
danielh-official Dec 18, 2022
2f75bbd
Merge pull request #93 from 5am-code/feature/allow-single-sorting-in-…
mechelon Dec 19, 2022
456186e
tests for compound filters
mechelon Jan 30, 2023
eb5d16f
Merge branch 'dev' into feature/compound-filters
mechelon Jan 30, 2023
21d3e1a
fixed / resorted tests
mechelon Jan 30, 2023
72ba501
Apply fixes from StyleCI (#98)
mechelon Jan 30, 2023
c8be31c
polish introduction, header and examples
johguentner Feb 1, 2023
44294ba
Bump dependencies for Laravel 10
laravel-shift Feb 2, 2023
de705ae
polish page and properties
johguentner Feb 2, 2023
8542f79
Apply fixes from StyleCI (#102)
mechelon Feb 2, 2023
7f7919d
Merge pull request #87 from fschirinzi/feature/fix-pagination-for-search
johguentner Feb 2, 2023
685e73a
Merge pull request #99 from 5am-code/feature/compound-filters
johguentner Feb 2, 2023
cbabe91
Merge branch 'dev' into page-and-property-polish
johguentner Feb 2, 2023
ef0daae
add tests which check properties/methods
johguentner Feb 2, 2023
0ab4d2f
Merge pull request #103 from 5am-code/page-and-property-polish
johguentner Feb 2, 2023
fad163c
Merge branch 'dev' into pr/88-add-tests
johguentner Feb 2, 2023
20f634c
cleanup
johguentner Feb 2, 2023
58b94f4
cleanup
johguentner Feb 2, 2023
80f38df
Merge pull request #95 from danielh-official/pr/88-add-tests
johguentner Feb 2, 2023
ed6ad32
Merge branch 'dev' into l10-compatibility
johguentner Feb 3, 2023
241ce71
Merge pull request #100 from laravel-shift/l10-compatibility
johguentner Feb 3, 2023
bef69a5
refactor timestampables of entities into traid
johguentner Feb 4, 2023
0a982bb
Apply fixes from StyleCI (#104)
mechelon Feb 4, 2023
f2e8893
Merge branch 'dev' into feature/add-database-attributes
johguentner Feb 5, 2023
2b84fce
refactor title and add description for db entity
johguentner Feb 5, 2023
fcb68e9
rewrite tests for title and add for description
johguentner Feb 5, 2023
558844e
rename ``TimestampableEntity``
johguentner Feb 5, 2023
7260246
Merge branch 'feature/create-timestampable-trait' into feature/add-da…
johguentner Feb 5, 2023
192ae82
introduce ``HasParent`` as Trait for entities
johguentner Feb 5, 2023
0cccb2e
add tests for entities which use ``HasParent``
johguentner Feb 5, 2023
f2c0702
Apply fixes from StyleCI (#106)
mechelon Feb 5, 2023
b9797bf
add ``is_inline`` property to database entity
johguentner Feb 5, 2023
3df9d7b
Merge branch 'feature/add-database-attributes' of https://github.com/…
johguentner Feb 5, 2023
60bcca4
introduce ``HasArchive`` trait for entities
johguentner Feb 5, 2023
81b2b10
add tests for the ``HasArchive`` trait
johguentner Feb 5, 2023
dedf7c3
Apply fixes from StyleCI (#107)
mechelon Feb 5, 2023
c5b482e
move ``object`` to entity base class
johguentner Feb 5, 2023
4d36500
add test-cases (previous commit)
johguentner Feb 5, 2023
c1e8eb5
Merge branch 'feature/add-database-attributes' of https://github.com/…
johguentner Feb 5, 2023
d59324c
Apply fixes from StyleCI (#108)
mechelon Feb 5, 2023
6ddc29e
add comment entity, collection and endpoints
johguentner Feb 5, 2023
bc1b326
Apply fixes from StyleCI (#110)
mechelon Feb 5, 2023
91e189f
add various tests for the comment endpoint
johguentner Feb 6, 2023
dc735ce
Merge branch 'feature/comments' of https://github.com/5am-code/larave…
johguentner Feb 6, 2023
769168a
Apply fixes from StyleCI (#112)
mechelon Feb 6, 2023
b32890e
change name ``->fillTimestampableProperties``
johguentner Feb 6, 2023
cef1226
Merge branch 'feature/create-timestampable-trait' into feature/add-da…
johguentner Feb 6, 2023
78d93e2
change name of fill-method of traits
johguentner Feb 6, 2023
661beeb
Merge branch 'feature/add-database-attributes' into feature/comments
johguentner Feb 6, 2023
dd4e289
minor refactor (previous commits)
johguentner Feb 6, 2023
43c6d10
- Still allow collections inside the filterBy method - this "undoes" …
mechelon Feb 6, 2023
e818d67
Apply fixes from StyleCI (#113)
mechelon Feb 6, 2023
5166157
rename ``Comment::create(...)``
johguentner Feb 6, 2023
da9f86a
Merge pull request #114 from 5am-code/feature/allow-filter-collections
johguentner Feb 6, 2023
c47dfbc
allow ``null`` for attrs in HasTimestamps trait
johguentner Feb 6, 2023
be1efeb
rename trait comment
johguentner Feb 6, 2023
13a6b38
Merge branch 'feature/create-timestampable-trait' into feature/comments
johguentner Feb 6, 2023
2795c1b
add ``null`` test to ``getLastEditedBy()``
johguentner Feb 6, 2023
4ef3d6e
add doc to comments endpoint in ``Notion::class``
johguentner Feb 6, 2023
f7c097d
rename `fillEntityBase()` to `fillEssentials` and
johguentner Feb 6, 2023
25c97d4
Apply fixes from StyleCI (#117)
mechelon Feb 6, 2023
e0c12f6
Merge branch 'feature/add-database-attributes' into feature/comments
johguentner Feb 6, 2023
76a287a
modify `Comment`, based on changes in `Entity`
johguentner Feb 6, 2023
91f2cc2
polish error message in `Comment` Endpoint
johguentner Feb 6, 2023
2533e4b
Apply fixes from StyleCI (#118)
mechelon Feb 6, 2023
4b847e1
add alias for `Comment` Entity
johguentner Feb 6, 2023
63d288a
Apply fixes from StyleCI (#119)
mechelon Feb 6, 2023
34acb4c
Merge pull request #105 from 5am-code/feature/create-timestampable-trait
johguentner Feb 6, 2023
ff4794a
Merge pull request #109 from 5am-code/feature/add-database-attributes
johguentner Feb 6, 2023
b3bb528
Merge pull request #111 from 5am-code/feature/comments
johguentner Feb 6, 2023
0366545
Updated README & contribution guide
mechelon Mar 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
php:
- '8.1'
- '8.0'
- '7.4'
laravel:
- '8.*'
testbench:
Expand Down Expand Up @@ -45,4 +44,4 @@ jobs:
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

- name: Execute tests
run: vendor/bin/phpunit tests
run: vendor/bin/pest tests
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ If the project maintainer has any additional requirements, you will find them li

- **[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).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **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/).

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **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.

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

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

- **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.

**Happy coding**!
**Happy coding!** 🚀!
189 changes: 124 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<h1 align="center"> Laravel Notion API</h1>
<h2 align="center"> Effortless Notion integrations with Laravel</h2>
<h1 align="center"> Notion for Laravel</h1>

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

[![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)
[![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)
Expand All @@ -14,90 +11,156 @@ This package provides a simple and crisp way to access the Notion API endpoints,

## Installation

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

```bash
composer require fiveam-code/laravel-notion-api
```
1. Install the package via composer:

### Authorization
```bash
composer require fiveam-code/laravel-notion-api
```

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.
2. Get your Notion API access token like explained in [their documentation](https://developers.notion.com/). It's also
important to grant access to the integration within your Notion pages, which is described in the developer
documentation at Notion as well.

Add your Notion API token to your `.env` file:
3. Add a new line to your applications `.env` file:

```
NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"
```
```bash
NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"
```

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

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

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

#### Basic Setup (+ example)
```php
use FiveamCode\LaravelNotionApi\Notion;
That's it.

For detailed usage information and a list of available endpoints see (the docs).

## Examples

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

# Custom instantiation (necessary if you want to access more than one NotionApi integration)
$notion = new Notion($apiToken, $apiVersion); // version-default is 'v1'
$notion->databases()->find($databaseId);
### Fetch a Notion Database

The `databases()->find()` method returns a `FiveamCode\LaravelNotionApi\Entities\Database` object,
which contains all the information about the database, including its properties and the possible values for each
property.

```php
use \Notion;

Notion::databases()
->find("8284f3ff77e24d4a939d19459e4d6bdc");
```

#### Fetch Page Information
### Fetch a Notion Page

The `pages()->find()` method returns a `FiveamCode\LaravelNotionApi\Entities\Page` object,
which contains all the information about the page, including its properties and the possible values for each property.

```php
// Returns a specific page
\Notion::pages()->find($yourPageId);
Notion::pages()
->find("e7e5e47d-23ca-463b-9750-eb07ca7115e4");
```

#### Search
### Search

The `search()` endpoint returns a collection of pages that match the search query. The scope of the search is limited to
the workspace that the integration is installed in
and the pages that are shared with the integration.

```php
// Returns a collection pages and databases of your workspace (included in your integration-token)
\Notion::search($searchText)
Notion::search("Search term")
->query()
->asCollection();
```

#### Query Database
### Query Database

The `database()` endpoint allows you to query a specific database and returns a collection of pages (= database
entries).
You can filter and sort the results and limit the number of returned entries. For detailed information about the
available
filters and sorts, please refer to the [documentation](https://developers.notion.com/reference/post-database-query).

```php
// Queries a specific database and returns a collection of pages (= database entries)
$sortings = new Collection();
$filters = new Collection();

$sortings
->add(Sorting::propertySort('Ordered', 'ascending'));
$sortings
->add(Sorting::timestampSort('created_time', 'ascending'));

$filters
->add(Filter::textFilter('title', ['contains' => 'new']));
// or
$filters
->add(Filter::rawFilter('Tags', ['multi_select' => ['contains' => 'great']]));

\Notion::database($yourDatabaseId)
->filterBy($filters) // filters are optional
->sortBy($sortings) // sorts are optional
->limit(5) // limit is optional
->query()
->asCollection();
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();
```

Compound filters for AND or OR queries are also available:

```php
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();
```

### Testing
### Testing (pestphp)

You can find even more usage examples by checking out the package tests in the `/tests` directory.
The tests are making use of Pest PHP and we are working on switching from PHPUNIT to it (todo sentence).

If you want to run the tests in your CLI:

```bash
vendor/bin/phpunit tests
vendor/bin/pest tests
```

## Support

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)!
If you use this package in one of your projects or want to support our development, consider becoming
a [Patreon Supporter](https://www.patreon.com/bePatron?u=56662485)!

### Supported by Tinkerwell

<a href="https://tinkerwell.app/">
<img src="https://tinkerwell.app/images/tinkerwell_logo.png" width="64" height="64" alt="Tinkerwell"> <br/>
</a>

The development of this package is supported by [Tinkerwell](https://tinkerwell.app/).


## Contributing

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

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

## Used By

- 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.
- [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
- [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.

Using this package in your project? Open a PR to add it in this section!

## Credits

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

<p align="center">
<img src="https://5amco.de/images/5am.png" width="200" height="200">
</p>

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
}
],
"require": {
"php": "^7.4|^8.0",
"php": "^8.0",
"guzzlehttp/guzzle": "^7.0.1",
"illuminate/support": "^8.0|^9.0"
"illuminate/support": "^8.0|^9.0|^10.0"
},
"require-dev": {
"orchestra/testbench": "^6.0",
"orchestra/testbench": "^6.0|^8.0",
"pestphp/pest": "^1.22",
"pestphp/pest-plugin-laravel": "^1.3",
"phpunit/phpunit": "^9.0"
},
"autoload": {
Expand All @@ -46,9 +48,8 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"

"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage-html coverage"
},
"config": {
"sort-packages": true
Expand Down
Loading