Skip to content

Commit

Permalink
Update to examples
Browse files Browse the repository at this point in the history
Add example config files
  • Loading branch information
psarin committed Jan 17, 2022
1 parent c30e9f9 commit 1cbc7e4
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 71 deletions.
64 changes: 0 additions & 64 deletions example/simple.cfm

This file was deleted.

10 changes: 10 additions & 0 deletions examples/config/databases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"default": "projects",
"academic_refs": {
"DATABASE_ID": "database_id_for_academic_refs_db"
},
"projects": {
"DATABASE_ID": "database_id_for_projects_db",
"properties": ["Date Created","Slug","Title","Principal Investigator","Investigators","Assigned Project","Study Status"]
}
}
6 changes: 6 additions & 0 deletions examples/config/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "name_of_integration",
"auth": "secret_notion_integration_auth_key",
"notionVersion": "2021-08-16",
"baseUrl": "https://api.notion.com/v1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
var NOTION_TOKEN = Application.notion.auth;
var notion = new lib.NotionClient (auth: NOTION_TOKEN);
var useDatabaseKey = "projects";
var DATABASE_ID = Application.notion["databases"][useDatabaseKey]?.DATABASE_ID;
var not_renderable_text = "not renderable";
writeOutput("<h1>Example of Database Retrieval</h1>");
writeOutput("<h2>Use Notion API to retrieve and display rows in a database</h2>");
writeOutput("<p>The app queries a database's properties and content, displaying the values of the database's properties for each row.</p>");
var DATABASE_ID = Application.notion["DATABASE_ID"];
// Retrieve database properties / structure from Notion and convert into our own database model
var database_info = notion.databases.retrieve(argumentCollection={database_id: DATABASE_ID});
var database_model = new models.Database().init(argumentCollection = database_info);
// writedump(var = database_model);
// writeDump(var = database_model);
// abort;
// Query the database for all rows (pages) contained in the database, returned as a list, and convert into our own list model
Expand Down
66 changes: 66 additions & 0 deletions examples/simple.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<cfscript>
void public function main() {
var NOTION_TOKEN = Application.notion.auth;
var notion = new lib.NotionClient (auth: NOTION_TOKEN);
var useDatabaseKey = "projects";
var DATABASE_ID = Application.notion["databases"][useDatabaseKey]?.DATABASE_ID;
// Get list of users
writeOutput("Getting list of users<BR/>");
var usersList = notion.users.list().results;
// writeDump(var=usersList);
writeOutput("<HR/>");
// Get user info by userid
if (!arrayIsEmpty(userslist)){
writeOutput("Getting user info by userid<BR/>");
var userInfo = notion.users.retrieve(userslist[1].id);
// writeDump(var=userInfo);
writeOutput("<HR/>");
}
// Simple search
writeOutput("Performing a simple search<BR/>");
// writeDump(var=notion.search.search(argumentCollection = {
// query: 'cardiac',
// sort: {
// direction: 'ascending',
// timestamp: 'last_edited_time',
// },
// }));
writeOutput("<HR/>");
// Query a database and get content for first page
writeOutput("Querying a database, retrieving a page from database, and retrieving blocks for a page<BR/>");
var DATABASE_ID = DATABASE_ID?:'';
var resultDB = notion.databases.query(argumentCollection={database_id: DATABASE_ID});
writeOutput("Database results<BR/>");
// writeDump(var = resultDB);
writeOutput("<HR/>");
for (var i=1; i <= arrayLen(resultDB.results); i++){
var result = resultDB.results[i];
if (result.object eq 'page'){
var id = result.id;
var resultPage = notion.pages.retrieve(id);
writeDump(var=resultPage);
var resultPageTitle = resultPage.properties.Slug.title[1].plain_text;
writeOutput("Page results for page with title <u>#resultPageTitle#</u> and id #resultPage.id#<BR/>");
writeOutput("<HR/>");
var resultBlocks = notion.blocks.retrieve(resultPage.id);
// var resultBlocks = notion.blocks.children.list(id).results;
writeOutput("Blocks for page with title <u>#resultPageTitle#</u> and id #resultPage.id#<BR/>");
writeDump(var=resultBlocks?.results);
writeOutput("<HR/>");
break;
}
}
writeOutput("FINISHED!<BR/>");
}
main();
</cfscript>
5 changes: 0 additions & 5 deletions settings.json

This file was deleted.

0 comments on commit 1cbc7e4

Please sign in to comment.