Giter Club home page Giter Club logo

notion-sdk-php's Introduction

notion-sdk-php

A complete Notion SDK for PHP developers.

๐Ÿ“ฆ Installation

This project requires PHP 8.1 or higher. To install it with Composer run:

$ composer require mariosimao/notion-sdk-php

๐Ÿ‘ฉโ€๐Ÿ’ป Basic usage

Creating a page on Notion with the SDK is easy.

use Notion\Blocks\Heading1;
use Notion\Blocks\ToDo;
use Notion\Common\Emoji;
use Notion\Notion;
use Notion\Pages\Page;
use Notion\Pages\PageParent;

$notion = Notion::create("secret_token");

$parent = PageParent::page("c986d7b0-7051-4f18-b165-cc0b9503ffc2");
$page = Page::create($parent)
            ->changeTitle("Shopping list")
            ->changeIcon(Emoji::fromString("๐Ÿ›’"));

$content = [
    Heading1::fromString("Supermarket"),
    ToDo::fromString("Tomato"),
    ToDo::fromString("Sugar"),
    ToDo::fromString("Apple"),
    ToDo::fromString("Milk"),
    Heading1::fromString("Mall"),
    ToDo::fromString("Black T-shirt"),
];

$page = $notion->pages()->create($page, $content);

๐Ÿ“„ Documentation

Further documentation can be found at https://mariosimao.github.io/notion-sdk-php.

The Notion PHP SDK supports the usage of static analysers. We strongly recommend the usage of either vimeo/psalm or phpstan/phpstan in combination with this library, to avoid simple mistakes.

๐Ÿท๏ธ Versioning

SemVer is followed closely. Minor and patch releases should not introduce breaking changes to the codebase.

Any classes or methods marked as @internal are not intended for use outside of this library and are subject to breaking changes at any time, avoid using them.

๐Ÿ› ๏ธ Maintenance & Support

When a new minor version (e.g. 1.3 -> 1.4) is released, the previous one (1.3) will continue to receive security and critical bug fixes for at least 3 months.

When a new major version is released (e.g. 1.6 -> 2.0), the previous one (1.6) will receive critical bug fixes for at least 3 months and security updates for 6 months after that new release comes out.

This policy may change in the future and exceptions may be made on a case-by-case basis.

โค๏ธ Sponsors

An special thanks to all sponsors who activelly support the SDK!

notion-sdk-php's People

Contributors

aknevrnky avatar awilum avatar braumye avatar champsupertramp avatar dependabot[bot] avatar djafari avatar ffirmenich avatar frederichoule avatar github-actions[bot] avatar iamalexchip avatar joseph-azzam avatar juampi92 avatar larowka avatar mariosimao avatar nfarrington avatar notfloran avatar philippe-pixieset avatar ren0v avatar samzzi avatar tambait avatar willgibson avatar xynnn avatar youvalteboul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

notion-sdk-php's Issues

How to retrieve pages from database

Does this API allow for the ability to return a set of pages from a given database? I can't seem to find any documentation or tests that handle this use-case. Perhaps I'm missing something?

Issue with files field

I have files property (Files & Media type)

Screenshot 2022-08-19 at 20 31 18

when I'm fetching my page

$page = $notion->pages()->find('f3b4ab7c34fa4b71acb0c7fa011374d9');
dd($page);

I see error

Fatal error: Uncaught Exception: Invalid property type: 'files' in /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/mariosimao/notion-sdk-php/src/Pages/Properties/Factory.php:34 Stack trace: #0 /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/mariosimao/notion-sdk-php/src/Pages/Page.php(108): Notion\Pages\Properties\Factory::fromArray(Array) #1 /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/mariosimao/notion-sdk-php/src/Pages/Client.php(57): Notion\Pages\Page::fromArray(Array) #2 /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/plugin.php(58): Notion\Pages\Client->find('f3b4ab7c34fa4b7...') #3 /Applications/MAMP/htdocs/projects/flextype/flextype/src/flextype/core/Plugins.php(423): require_once('/Applications/M...') #4 /Applications/MAMP/htdocs/projects/flextype/flextype/src/flextype/core/Plugins.php(191): Flextype\Plugins->includeEnabledPlugins() #5 /Applications/MAMP/htdocs/projects/flextype/flextype/src/flextype/core/Plugins.php(51): Flextype\Plugins->init() #6 /Applications/MAMP/htdocs/projects/flextype/flextype/src/flextype/flextype.php(350): Flextype\Plugins->__construct() #7 /Applications/MAMP/htdocs/projects/flextype/flextype/index.php(46): require_once('/Applications/M...') #8 {main} thrown in /Applications/MAMP/htdocs/projects/flextype/flextype/project/plugins/notion/vendor/mariosimao/notion-sdk-php/src/Pages/Properties/Factory.php on line 34

Rename `Notion\Client` to `Notion\Notion`

I like the way you designed all this with DI in mind :)

Only complain I have is that Client itself does not have an interface, so it is hard to mock/stub.

Another detail is that Client seems to be more like an entry-point: perhaps this class could be called Notion:

$notion = Notion::create(...)->users()->...

In fact, users() gives you a client, while Notion could be expanded with further utilities later on

Originally posted by @Ocramius in #6 (comment)

Internal cover image is not supported

Internal cover images are now supported by Notion API, as read-only fields. I think we should be able to retrieve pages with internal covers instead of throwing an exception.

How to change the value of a property in a database row?

Hello, tell me what is the correct way to change the value of a property in a row from a database table? And yet, you can show an example of how to add new rows to a table with a data base.

There are no examples at all of how to change property values in pages. Or I didn't find it.

Thanks a lot. I hope you have some time to answer this question.

And thanks a lot for this SDK.

Use Eums

PHP 8.1 Enum seem the right choice for many constants such as block type, code language, etc.

Enable deprecation errors in PHPUnit

Probably worth enabling turning deprecations into errors here - PHPUnit disabled it because of Symfony's and PHP 8.1 broken design constraints, but it's good to prevent deprecations from randomly propagating to your consumers

Originally posted in #6 (comment)

Add mutation tests

One thing you may want to start doing instead of coverage, is mutation testing, with either of:

  • infection/infection
  • roave/infection-static-analysis-plugin

Both should give you a good idea of which areas in the code are not tested well enough, but a mutation test score of >80% is generally really good :)

Code coverage itself is mostly a vanity metric these days: admirable, but not a clear indicator of tested/untested paths.

Originally posted by @Ocramius in #6 (comment)

Database properties

Add support to database properties with one class for each property.

  • title
  • rich_text
  • number
  • select
  • multi_select
  • date
  • people
  • files
  • checkbox
  • url
  • email
  • phone_number
  • formula
  • created_time
  • created_by
  • last_edited_time
  • last_edited_by

Unable to create RichText URL

Hello, thanks for the great SDK ๐Ÿ˜

It doesn't currently appear possible to create a RichText object with a link to a URL that's correctly formatted as a clickable link.

As an example, I currently have this code:

BulletedListItem::create()->withText([
    RichText::createText("My link: "),
    RichText::createText("https://example.com/my-link"),
]));

It's not possible to use a Text object directly as BulletedListItem only accepts RichText. https://example.com/my-link isn't clickable in Notion, I guess because the underlying text object isn't a link object (https://developers.notion.com/reference/rich-text#link-objects).

It would be great to be able to do something like the following to make the link clickable:

BulletedListItem::create()->withText([
    RichText::createText("My link: "),
    RichText::createText("https://example.com/my-link")
        ->withUrl("https://example.com/my-link"),
]));

Use `never` on `BlockInterface::changeChildren()`

With the new never return type, the method BlockInterface::changeChildren() could optionally be marked as a never returning method, due to blocks that do no accept children.

public function changeChildren(array $children): self|never

Use `list<Type>` instead of `Type[]`

Instead of using Type[] syntax, consider being explicit about the shape of the input.

For example:

  • RichText[] means array<array-key, RichText>
  • array<int, RichText> could be [0 => new RichText(), 4 => new RichText()]
  • list<RichText> is like array<int, RichText>, but prevents gaps in array keys (safer, when considering that a lot of this stuff will be json_encode()d

Originally posted by @Ocramius in #6 (comment)

Database actions

Support database actions:

  • Create a database
  • Update a database
  • Retrieve a database

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.