Giter Club home page Giter Club logo

easynotion's Introduction

easynotion

Notion SDK for PHP

use EasyNotion\EasyNotion;

require __DIR__ . '/vendor/autoload.php';

$token = getenv("NOTION_TOKEN");
$notion = new EasyNotion($token);

Database

$dbClient = $notion->database();

$dbId = 'your-db-id';
$db = $dbClient->get($dbId);
var_dump($db); // db entity

// db content
$query = $dbClient->query($dbId, 1);
var_dump($query->results());

while($query->hasMore()) {
    sleep(2);
    $query = $query->next();
    var_dump($query->results());
} 

Database Filter

use EasyNotion\Property\Filter;

$dbClient = $notion->database();
$dbId = 'your-db-id';
$db = $dbClient->get($dbId);

$propConfig = $db->properties; // $db is a db-entity from remote

$filter1 = Filter::make("Age", $propConfig['Age']->getType()); // type Number
$filter1->greaterThan(30);

$filter2 = Filter::make("Name", $propConfig['Name']->getType()); // type Title
$filter2->contains('Gu');

$filter1->and($filter2); // Compound

echo json_encode($filter1) . PHP_EOL;

$query = $dbClient->query($dbId, filter: $filter1);

var_export($query->results());

Database Sorts

use EasyNotion\Property\Sort;

$sort = new Sort();
$sort->by("created_time", Direction::Asc);
$sort->by('Name', Direction::Desc);
echo json_encode($sort) . PHP_EOL;

Page

$pageClient = $notion->page();

$pageId = 'your-page-id';
$page = $pageClient->get($pageId);

var_dump($page);

Block

$blockClient = $notion->block();

$blockId = 'your-block-id'; // page is a special block

$block = $blockClient->get($blockId);
var_dump($block); // block entity

$children = $blockClient->children($blockId, 5); // collection
var_dump($children);
var_dump($children->next()); // collection for next page

Property

$pageClient = $notion->page();

$pageId = 'your-page-id';
$page = $pageClient->get($pageId);
var_dump($page);

$propertyClient = $notion->property($page);
$property = $propertyClient->get('your-property-id'); // PropertyId from $page->properties
var_dump($property);

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.