-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
6 changed files
with
196 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,11 @@ | ||
(* For this demo, it's necessary to create smartsheetSecrets.ur, | ||
* defining [api_token]. *) | ||
structure Z = Smartsheet.Make(Smartsheet.TwoLegged(SmartsheetSecrets)) | ||
|
||
val main = | ||
ts <- Z.Templates.list; | ||
return <xml><body> | ||
<ul> | ||
{List.mapX (fn r => <xml><li>{[r.Nam]}</li></xml>) ts} | ||
</ul> | ||
</body></xml> |
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 @@ | ||
library ../src/ur | ||
rewrite all SmartsheetDemo/* | ||
database dbname=smartsheetDemo | ||
sql smartsheetDemo.sql | ||
safeGetDefault | ||
allow url https://* | ||
prefix http://localhost:8080/ | ||
|
||
smartsheetSecrets | ||
smartsheetDemo |
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 @@ | ||
val main : transaction page |
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 |
---|---|---|
|
@@ -30,3 +30,4 @@ openIdConnect | |
zenefits | ||
netSuite | ||
chatgpt | ||
smartsheet |
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,128 @@ | ||
open Json | ||
|
||
signature AUTH = sig | ||
val token : transaction (option string) | ||
end | ||
|
||
functor TwoLegged(M : sig | ||
val api_token : string | ||
end) = struct | ||
val token = return (Some M.api_token) | ||
end | ||
|
||
datatype template_type = | ||
Report | ||
| Sheet | ||
|
||
val _ : json template_type = json_derived | ||
(fn x => | ||
case x of | ||
"report" => Report | ||
| "sheet" => Sheet | ||
| _ => error <xml>Bad Smartsheet template type {[x]}</xml>) | ||
(fn x => | ||
case x of | ||
Report => "report" | ||
| Sheet => "sheet") | ||
|
||
datatype access_level = | ||
ADMIN | ||
| COMMENTER | ||
| EDITOR | ||
| EDITOR_SHARE | ||
| OWNER | ||
| VIEWER | ||
|
||
val _ : json access_level = json_derived | ||
(fn x => case x of | ||
"ADMIN" => ADMIN | ||
| "COMMENTER" => COMMENTER | ||
| "EDITOR" => EDITOR | ||
| "EDITOR_SHARE" => EDITOR_SHARE | ||
| "OWNER" => OWNER | ||
| "VIEWER" => VIEWER | ||
| _ => error <xml>Bad Smartsheet access level {[x]}</xml>) | ||
(fn x => | ||
case x of | ||
ADMIN => "ADMIN" | ||
| COMMENTER => "COMMENTER" | ||
| EDITOR => "EDITOR" | ||
| EDITOR_SHARE => "EDITOR_SHARE" | ||
| OWNER => "OWNER" | ||
| VIEWER => "VIEWER") | ||
|
||
datatype global_template_type = | ||
BLANK_SHEET | ||
| PROJECT_SHEET | ||
| TASK_LIST | ||
|
||
val _ : json global_template_type = json_derived | ||
(fn x => case x of | ||
"BLANK_SHEET" => BLANK_SHEET | ||
| "PROJECT_SHEET" => PROJECT_SHEET | ||
| "TASK_LIST" => TASK_LIST | ||
| _ => error <xml>Bad Smartsheet global template type {[x]}</xml>) | ||
(fn x => | ||
case x of | ||
BLANK_SHEET => "BLANK_SHEET" | ||
| PROJECT_SHEET => "PROJECT_SHEET" | ||
| TASK_LIST => "TASK_LIST") | ||
|
||
type template = { | ||
Id : option int, | ||
Typ : option template_type, | ||
AccessLevel : option access_level, | ||
Blank : option bool, | ||
Categories : option (list string), | ||
GlobalTemplate : option global_template_type, | ||
Image : option string, | ||
LargeImage : option string, | ||
Nam : string, | ||
Tags : option (list string) | ||
} | ||
|
||
val _ : json template = json_record_withOptional | ||
{Nam = "name"} | ||
{Id = "id", | ||
Typ = "type", | ||
AccessLevel = "accessLevel", | ||
Blank = "blank", | ||
Categories = "categories", | ||
GlobalTemplate = "globalTemplate", | ||
Image = "image", | ||
LargeImage = "largeImage", | ||
Tags = "tags"} | ||
|
||
type templates = { | ||
Data : list template | ||
} | ||
|
||
val _ : json templates = json_record {Data = "data"} | ||
|
||
functor Make(M : AUTH) = struct | ||
open M | ||
|
||
val token = | ||
toko <- token; | ||
case toko of | ||
None => error <xml>You must be logged into Smartsheet to use this feature.</xml> | ||
| Some tok => return tok | ||
|
||
val prefix = "https://api.smartsheet.com/2.0/" | ||
|
||
fun logged [a] (_ : show a) (t : transaction a) = | ||
v <- t; | ||
debug ("Smartsheet response: " ^ show v); | ||
return v | ||
|
||
fun api url = | ||
tok <- token; | ||
debug ("Smartsheet GET: " ^ prefix ^ url); | ||
logged (WorldFfi.get (bless (prefix ^ url)) (WorldFfi.addHeader WorldFfi.emptyHeaders "Authorization" ("Bearer " ^ tok)) False) | ||
|
||
structure Templates = struct | ||
val list = | ||
s <- api "templates?includeAll=true"; | ||
return ((fromJson s : templates).Data) | ||
end | ||
end |
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,45 @@ | ||
signature AUTH = sig | ||
val token : transaction (option string) | ||
end | ||
|
||
functor TwoLegged(M : sig | ||
val api_token : string | ||
end) : sig | ||
val token : transaction (option string) | ||
end | ||
|
||
datatype template_type = | ||
Report | ||
| Sheet | ||
|
||
datatype access_level = | ||
ADMIN | ||
| COMMENTER | ||
| EDITOR | ||
| EDITOR_SHARE | ||
| OWNER | ||
| VIEWER | ||
|
||
datatype global_template_type = | ||
BLANK_SHEET | ||
| PROJECT_SHEET | ||
| TASK_LIST | ||
|
||
type template = { | ||
Id : option int, | ||
Typ : option template_type, | ||
AccessLevel : option access_level, | ||
Blank : option bool, | ||
Categories : option (list string), | ||
GlobalTemplate : option global_template_type, | ||
Image : option string, | ||
LargeImage : option string, | ||
Nam : string, | ||
Tags : option (list string) | ||
} | ||
|
||
functor Make(M : AUTH) : sig | ||
structure Templates : sig | ||
val list : transaction (list template) | ||
end | ||
end |