Skip to content

Commit

Permalink
Smartsheet: get sources of sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
achlipala committed Aug 13, 2023
1 parent a8325fd commit 9604a64
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
4 changes: 3 additions & 1 deletion examples/smartsheetDemo.ur
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ val main =
{List.mapX (fn r =>
case r.Id of
None => error <xml>No ID returned for sheet</xml>
| Some sid => <xml><li><a link={sheet sid}>{[r.Nam]}</a></li></xml>) shs}
| Some sid => <xml><li><a link={sheet sid}>{[r.Nam]}</a>{case r.Source of
None => <xml></xml>
| Some s => <xml> (from {[s.Id]})</xml>}</li></xml>) shs}
</ul>

<h2>Templates</h2>
Expand Down
33 changes: 30 additions & 3 deletions src/ur/smartsheet.ur
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ val _ : json template_type = json_derived

type template_id = int
val show_template_id = _
val eq_template_id = _
fun template_id x = x

type template = {
Id : option template_id,
Expand Down Expand Up @@ -152,20 +154,45 @@ val _ : json row = json_record_withOptional
Columns = "columns",
RowNumber = "rowNumber"}

datatype source_type = Report | Sheet | Sight | Template

val _ : json source_type = json_derived
(fn x =>
case x of
"report" => Report
| "sheet" => Sheet
| "sight" => Sight
| "template" => Template
| _ => error <xml>Bad Smartsheet source type {[x]}</xml>)
(fn x =>
case x of
Report => "report"
| Sheet => "sheet"
| Sight => "sight"
| Template => "template")

type source = {
Id : int,
Typ : source_type
}
val _ : json source = json_record {Id = "id", Typ = "type"}

type sheet = {
Id : option sheet_id,
Nam : string,
FromId : option template_id,
Columns : option (list column),
Rows : option (list row)
Rows : option (list row),
Source : option source
}

val _ : json sheet = json_record_withOptional
{Nam = "name"}
{Id = "id",
FromId = "fromId",
Columns = "columns",
Rows = "rows"}
Rows = "rows",
Source = "source"}

type workspace_id = int
val show_workspace_id = _
Expand Down Expand Up @@ -248,7 +275,7 @@ functor Make(M : AUTH) = struct

structure Sheets = struct
val list =
s <- api "sheets?includeAll=true";
s <- api "sheets?includeAll=true&include=source";
return ((fromJson s : sheets).Data)

fun get id =
Expand Down
12 changes: 11 additions & 1 deletion src/ur/smartsheet.urs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type workspace = {

type template_id
val show_template_id : show template_id
val eq_template_id : eq template_id
val template_id : int -> template_id

type template = {
Id : option template_id,
Expand Down Expand Up @@ -80,12 +82,20 @@ type row = {
RowNumber : option int
}

datatype source_type = Report | Sheet | Sight | Template

type source = {
Id : int,
Typ : source_type
}

type sheet = {
Id : option sheet_id,
Nam : string,
FromId : option template_id,
Columns : option (list column),
Rows : option (list row)
Rows : option (list row),
Source : option source
}

functor Make(M : AUTH) : sig
Expand Down

0 comments on commit 9604a64

Please sign in to comment.