Skip to content

Commit 0366545

Browse files
committed
Updated README & contribution guide
1 parent b3bb528 commit 0366545

File tree

2 files changed

+114
-51
lines changed

2 files changed

+114
-51
lines changed

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: 111 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1 align="center"> Notion for Laravel</h1>
22

3-
<img src="https://banners.beyondco.de/Notion%20for%20Laravel.png?theme=light&packageManager=composer+require&packageName=fiveam-code%2Flaravel-notion-api&pattern=architect&style=style_1&description=Effortless+Notion+integrations+with+Laravel&md=1&showWatermark=1&fontSize=100px&images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg">
3+
<img src="open-graph.png">
44

55
[![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)
66
[![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)
@@ -9,94 +9,158 @@
99

1010
This package provides a simple and crisp way to access the Notion API endpoints, query data and update existing entries.
1111

12-
1312
## Installation
1413

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

17-
```bash
18-
composer require fiveam-code/laravel-notion-api
19-
```
16+
1. Install the package via composer:
2017

18+
```bash
19+
composer require fiveam-code/laravel-notion-api
20+
```
2121

2222
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 documentation at Notion as well.
23+
important to grant access to the integration within your Notion pages, which is described in the developer
24+
documentation at Notion as well.
25+
26+
3. Add a new line to your applications `.env` file:
27+
28+
```bash
29+
NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"
30+
```
2431

25-
3. For internal Integrations, please add a new entry to your `.env` like the following:
32+
4. You're ready to go! You can now access Notion endpoints through the `Notion` facade:
2633

27-
```bash
28-
NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"
29-
```
30-
4. Now you can easily access Notion:
31-
```php
32-
use \Notion;
33-
34-
Notion::databases()->find($databaseId);
35-
```
34+
```php
35+
use \Notion;
3636

37-
That's it.
37+
Notion::databases()->find("8284f3ff77e24d4a939d19459e4d6bdc");
38+
```
3839

40+
That's it.
3941

40-
## Usage
42+
For detailed usage information and a list of available endpoints see (the docs).
4143

42-
Head over to the [Documentation](https://notionforlaravel.com) of this package.
44+
## Examples
4345

44-
### 🔥 Code Examples to jumpstart your next Notion API Project
46+
All examples refer to our test database, which you can
47+
find [here](https://dianawebdev.notion.site/8284f3ff77e24d4a939d19459e4d6bdc?v=bc3a9ce8cdb84d3faefc9ae490136ac2).
48+
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.
4554

46-
#### Fetch a Notion Database (through a Facade)
4755
```php
48-
use \Notion;
56+
use \Notion;
4957

5058
Notion::databases()
51-
->find("a7e5e47d-23ca-463b-9750-eb07ca7115e4");
59+
->find("8284f3ff77e24d4a939d19459e4d6bdc");
5260
```
5361

54-
#### Fetch a Notion Page
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+
5567
```php
5668
Notion::pages()
5769
->find("e7e5e47d-23ca-463b-9750-eb07ca7115e4");
5870
```
5971

60-
#### 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+
6178
```php
62-
// Returns a collection pages and databases of your workspace (included in your integration-token)
63-
Notion::search("My Notion Search")
79+
Notion::search("Search term")
6480
->query()
6581
->asCollection();
6682
```
6783

68-
#### 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).
6991

7092
```php
71-
// Queries a specific database and returns a collection of pages (= database entries)
72-
$sortings = new Collection();
73-
$filters = new Collection();
74-
75-
$sortings->add(Sorting::propertySort('Ordered', 'ascending'));
76-
$sortings->add(Sorting::timestampSort('created_time', 'ascending'));
77-
78-
$filters->add(Filter::textFilter('title', ['contains' => 'new']));
79-
// or
80-
$filters->add(Filter::rawFilter('Tags', ['multi_select' => ['contains' => 'great']]));
81-
82-
Notion::database("a7e5e47d-23ca-463b-9750-eb07ca7115e4")
83-
->filterBy($filters) // filters are optional
84-
->sortBy($sortings) // sorts are optional
85-
->limit(5) // limit is optional
86-
->query()
87-
->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();
88103
```
89104

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+
```
90139

91140
### Testing (pestphp)
92141

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:
146+
93147
```bash
94148
vendor/bin/pest tests
95149
```
96150

97151
## Support
98152

99-
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+
100164

101165
## Contributing
102166

@@ -111,7 +175,6 @@ If you discover any security related issues, please email hello@dianaweb.dev ins
111175
- [Diana Scharf](https://github.com/mechelon)
112176
- [Johannes Güntner](https://github.com/johguentner)
113177

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

0 commit comments

Comments
 (0)