-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9df0c8e
Showing
14 changed files
with
586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
env.dart | ||
.vscode | ||
|
||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
build/ | ||
|
||
# Android related | ||
**/android/**/gradle-wrapper.jar | ||
**/android/.gradle | ||
**/android/captures/ | ||
**/android/gradlew | ||
**/android/gradlew.bat | ||
**/android/local.properties | ||
**/android/**/GeneratedPluginRegistrant.java | ||
|
||
# iOS/XCode related | ||
**/ios/**/*.mode1v3 | ||
**/ios/**/*.mode2v3 | ||
**/ios/**/*.moved-aside | ||
**/ios/**/*.pbxuser | ||
**/ios/**/*.perspectivev3 | ||
**/ios/**/*sync/ | ||
**/ios/**/.sconsign.dblite | ||
**/ios/**/.tags* | ||
**/ios/**/.vagrant/ | ||
**/ios/**/DerivedData/ | ||
**/ios/**/Icon? | ||
**/ios/**/Pods/ | ||
**/ios/**/.symlinks/ | ||
**/ios/**/profile | ||
**/ios/**/xcuserdata | ||
**/ios/.generated/ | ||
**/ios/Flutter/App.framework | ||
**/ios/Flutter/Flutter.framework | ||
**/ios/Flutter/Flutter.podspec | ||
**/ios/Flutter/Generated.xcconfig | ||
**/ios/Flutter/app.flx | ||
**/ios/Flutter/app.zip | ||
**/ios/Flutter/flutter_assets/ | ||
**/ios/Flutter/flutter_export_environment.sh | ||
**/ios/ServiceDefinitions.json | ||
**/ios/Runner/GeneratedPluginRegistrant.* | ||
|
||
# Exceptions to above rules. | ||
!**/ios/**/default.mode1v3 | ||
!**/ios/**/default.mode2v3 | ||
!**/ios/**/default.pbxuser | ||
!**/ios/**/default.perspectivev3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: adc687823a831bbebe28bdccfac1a628ca621513 | ||
channel: stable | ||
|
||
project_type: package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Changelog | ||
## v0.0.1-prealpha1 | ||
> Release date: 20/May/2021 | ||
* First version | ||
* Add `page` requests parameters models | ||
* Add notion api endpoints: `pages` | ||
* Retrieve a page | ||
* Create a page | ||
* Note: Accept only basic content: `title` & `parent`. | ||
* Add `database` tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO: Add your license here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Notion API client for dart. | ||
|
||
## Using | ||
You only have to create a new instance of the NotionClient class and all the API requests will be available as class methods. | ||
> Note: Maybe they will be separated onto separated classes, idk yet. | ||
```dart | ||
NotionClient notion = NotionClient(token: 'YOUR SECRET TOKEN FROM INTEGRATIONS PAGE'); | ||
``` | ||
|
||
### Methods | ||
`20/May/2021`: The methods return a `http.Response`. You can find how to use it in its [documentation][1]. | ||
|
||
#### Creating pages | ||
```dart | ||
Page page = Page(databaseId: 'YOUR DATABASE ID'); | ||
page.title = Text(content: 'The title of the new page'); | ||
notion.createPage(page); | ||
``` | ||
|
||
#### Retrieving pages | ||
```dart | ||
notion.retrievePage(test_page_id); | ||
``` | ||
|
||
[1]:https://pub.dev/documentation/http/latest/http/Response-class.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Roadmap | ||
## v0.0.1-prealpha1: ✅ | ||
> Release date: 20/May/2021 | ||
* First version | ||
* Add `page` requests parameters models | ||
* Add notion api endpoints: `pages` | ||
* Retrieve a page | ||
* Create a page | ||
* Note: Accept only basic content: `title` & `parent`. | ||
* Add `database` tests | ||
|
||
## v0.0.1-prealpha2: | ||
> Release date: 24/May/2021 | ||
* Return data response directly instead of `http.Response` | ||
* Manage http calls errors | ||
|
||
## v0.0.1-prealpha3: | ||
> Release date: 26/May/2021 | ||
* Add `database` request parameters models | ||
* Add notion api endpoints: `databases` | ||
* Retrieve a database | ||
* Query a database | ||
* List databases | ||
* Add `database` tests | ||
|
||
## v0.0.1-prealpha4: | ||
> Release date: 28/May/2021 | ||
* Add `block children` request parameters models | ||
* Add notion api endpoints: `block children` | ||
* Retrieve block children | ||
* Append block children | ||
* Add `block children` tests | ||
|
||
## v0.0.1-beta1: | ||
> Release date: 28/May/2021 | ||
* Improve testing | ||
|
||
### More coming soon. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
library notion_api; | ||
|
||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart' show required; | ||
import 'package:http/http.dart' as http; | ||
import 'package:notion_api/models/pages.dart'; | ||
|
||
/// A Notion API. | ||
class NotionClient { | ||
String _token; | ||
String _url = 'https://api.notion.com/v1'; | ||
|
||
NotionClient({@required token}) : this._token = token; | ||
|
||
Future<http.Response> retrievePage(String id) async { | ||
return await http.get(Uri.parse('$_url/pages/$id'), headers: { | ||
'Authorization': 'Bearer $_token', | ||
}); | ||
} | ||
|
||
/// Create a new page | ||
Future<http.Response> createPage(Page page) async { | ||
return await http.post(Uri.parse('$_url/pages'), | ||
body: jsonEncode(page.toJson()), | ||
headers: { | ||
'Authorization': 'Bearer $_token', | ||
'Content-Type': 'application/json; charset=UTF-8', | ||
}); | ||
} | ||
|
||
/// Returns [value] plus 1. | ||
int addOne(int value) => value + 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
enum NotionObjects { | ||
user, | ||
database, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart' show required; | ||
import 'package:notion_api/models/rich_text.dart'; | ||
|
||
class Page { | ||
final PageParent parent = PageParent(); | ||
final PageProperties properties = PageProperties(); | ||
final PageChildren children = PageChildren(); | ||
|
||
Page({@required databaseId}) { | ||
this.parent.databaseId = databaseId; | ||
} | ||
|
||
set title(RichText value) => properties.title.add(value ?? Text(content: '')); | ||
|
||
Map<String, dynamic> toJson() => { | ||
'parent': this.parent.toJson(), | ||
'properties': this.properties.toJson(), | ||
}; | ||
} | ||
|
||
class PageParent { | ||
String databaseId; | ||
|
||
toJson() => { | ||
'database_id': databaseId, | ||
}; | ||
} | ||
|
||
class PageProperties { | ||
List<RichText> title = []; | ||
|
||
toJson() => { | ||
'title': { | ||
'title': title.map((e) => e.toJson()).toList(), | ||
}, | ||
}; | ||
} | ||
|
||
class PageChildren {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'package:notion_api/models/users.dart'; | ||
|
||
enum RichTextType { | ||
mention, | ||
text, | ||
equation, | ||
url, | ||
} | ||
|
||
enum RichTextColors { | ||
gray, | ||
brown, | ||
orange, | ||
yellow, | ||
} | ||
|
||
class RichTextAnnotations { | ||
bool bold; | ||
bool italic; | ||
bool strikethrough; | ||
bool underline; | ||
bool code; | ||
RichTextColors color; | ||
} | ||
|
||
class RichText { | ||
String plainText; | ||
String href; | ||
RichTextAnnotations annotations; | ||
RichTextType type; | ||
|
||
toJson() => { | ||
'plain_text': plainText, | ||
'href': href, | ||
'annotations': annotations, | ||
'type': type, | ||
}; | ||
} | ||
|
||
class Text extends RichText { | ||
String content; | ||
|
||
Text({content}) : this.content = content; | ||
|
||
toJson() { | ||
Map<String, dynamic> json = super.toJson(); | ||
json['text'] = { | ||
'content': content, | ||
}; | ||
json.removeWhere((key, value) => value == null); | ||
return json; | ||
} | ||
} | ||
|
||
class Link extends Text { | ||
RichTextType type = RichTextType.url; | ||
String url; | ||
} | ||
|
||
class Mention extends RichText { | ||
RichTextType type = RichTextType.mention; | ||
} | ||
|
||
class UserMention extends Mention { | ||
PeopleUser user; | ||
} | ||
|
||
class Equation extends RichText { | ||
String expression; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:notion_api/models/objects.dart'; | ||
|
||
enum UserType { | ||
person, | ||
bot, | ||
} | ||
|
||
class User { | ||
NotionObjects object = NotionObjects.user; | ||
String id; | ||
UserType type; | ||
String name; | ||
String avatar_url; | ||
} | ||
|
||
class _People { | ||
String email; | ||
} | ||
|
||
class PeopleUser extends User { | ||
_People people; | ||
} | ||
|
||
class BotUser extends User {} |
Oops, something went wrong.