-
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.
Dropbox: just FileRequests.create so far, with two-legged auth
- Loading branch information
Showing
8 changed files
with
204 additions
and
1 deletion.
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,20 @@ | ||
(* For this demo, it's necessary to create dropboxSecrets.ur, | ||
* defining [api_key] and [api_secret]. *) | ||
structure D = Dropbox.Make(Dropbox.TwoLegged(DropboxSecrets)) | ||
|
||
fun create r = | ||
m <- D.FileRequests.create ({Title = r.Title, | ||
Destination = r.Destination, | ||
Open = True} | ||
++ Api.optionals {}); | ||
return <xml><body>ID: {[m.Id]}</body></xml> | ||
|
||
val main = return <xml><body> | ||
<h3>Create Request</h3> | ||
|
||
<form> | ||
Title: <textbox{#Title}/><br/> | ||
Destination: <textbox{#Destination}/><br/> | ||
<submit action={create}/> | ||
</form> | ||
</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 DropboxDemo/* | ||
database dbname=dropboxDemo | ||
sql dropboxDemo.sql | ||
safeGetDefault | ||
allow url https://* | ||
prefix http://localhost:8080/ | ||
|
||
dropboxSecrets | ||
dropboxDemo |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
val token = "sl.ArMQd_xwOsCUogNtfZriKxTOb78tokjfD6hM23YustyImp31vb6hrOOjbCpcFganZGjWvLwlWwo5e9p0A_KljGxRRxsSWNi1N8v62zh2G3gWEfHW2Cu89W2vBLi9EE5Q7dwz6rP7" |
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
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,118 @@ | ||
open Json | ||
|
||
signature AUTH = sig | ||
val token : transaction (option string) | ||
end | ||
|
||
functor TwoLegged(M : sig | ||
val token : string | ||
end) = struct | ||
val token = return (Some M.token) | ||
end | ||
|
||
type file_request_id = string | ||
val file_request_id_eq = _ | ||
val file_request_id_show = _ | ||
val file_request_id_inj = _ | ||
|
||
datatype grace_period = | ||
OneDay | ||
| TwoDays | ||
| SevenDays | ||
| ThirtyDays | ||
| Always | ||
val _ : json grace_period = json_derived | ||
(fn x => | ||
case x of | ||
"one_day" => OneDay | ||
| "two_days" => TwoDays | ||
| "seven_days" => SevenDays | ||
| "thirty_days" => ThirtyDays | ||
| "always" => Always | ||
| _ => error <xml>Bad Dropbox grace period {[x]}</xml>) | ||
(fn x => | ||
case x of | ||
OneDay => "one_day" | ||
| TwoDays => "two_days" | ||
| SevenDays => "seven_days" | ||
| ThirtyDays => "thirty_days" | ||
| Always => "always") | ||
|
||
type file_request_deadline = { | ||
Deadline : time, | ||
AllowLateUploads : option grace_period | ||
} | ||
val _ : json file_request_deadline = json_record_withOptional | ||
{Deadline = "deadline"} | ||
{AllowLateUploads = "allow_late_uploads"} | ||
|
||
type file_request_parameters = { | ||
Title : string, | ||
Destination : string, | ||
Deadline : option file_request_deadline, | ||
Open : bool, | ||
Description : option string | ||
} | ||
val _ : json file_request_parameters = json_record_withOptional | ||
{Title = "title", | ||
Destination = "destination", | ||
Open = "open"} | ||
{Deadline = "deadline", | ||
Description = "description"} | ||
|
||
type file_request = { | ||
Id : file_request_id, | ||
Url : string, | ||
Title : string, | ||
Created : time, | ||
IsOpen : bool, | ||
FileCount : int, | ||
Destination : option string, | ||
Deadline : option file_request_deadline, | ||
Description : option string | ||
} | ||
val _ : json file_request = json_record_withOptional | ||
{Id = "id", | ||
Url = "url", | ||
Title = "title", | ||
Created = "created", | ||
IsOpen = "is_open", | ||
FileCount = "file_count"} | ||
{Destination = "destination", | ||
Deadline = "deadline", | ||
Description = "description"} | ||
|
||
functor Make(M : AUTH) = struct | ||
open M | ||
|
||
val token = | ||
toko <- token; | ||
case toko of | ||
None => error <xml>You must be logged into Dropbox to use this feature.</xml> | ||
| Some tok => return tok | ||
|
||
val prefix = "https://api.dropboxapi.com/2/" | ||
|
||
fun logged [a] (_ : show a) (t : transaction a) = | ||
v <- t; | ||
debug ("Dropbox response: " ^ show v); | ||
return v | ||
|
||
fun api url = | ||
tok <- token; | ||
logged (WorldFfi.get (bless (prefix ^ url)) (Some ("Bearer " ^ tok)) False) | ||
|
||
fun apiOpt url = | ||
tok <- token; | ||
logged (WorldFfi.getOpt (bless (prefix ^ url)) (Some ("Bearer " ^ tok)) False) | ||
|
||
fun apiPost url body = | ||
tok <- token; | ||
logged (WorldFfi.post (bless (prefix ^ url)) (Some ("Bearer " ^ tok)) (Some "application/json") body) | ||
|
||
structure FileRequests = struct | ||
fun create p = | ||
r <- apiPost "file_requests/create" (toJson p); | ||
return (fromJson r) | ||
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,52 @@ | ||
signature AUTH = sig | ||
val token : transaction (option string) | ||
end | ||
|
||
functor TwoLegged(M : sig | ||
val token : string | ||
end) : sig | ||
val token : transaction (option string) | ||
end | ||
|
||
type file_request_id | ||
val file_request_id_eq : eq file_request_id | ||
val file_request_id_show : show file_request_id | ||
val file_request_id_inj : sql_injectable_prim file_request_id | ||
|
||
datatype grace_period = | ||
OneDay | ||
| TwoDays | ||
| SevenDays | ||
| ThirtyDays | ||
| Always | ||
|
||
type file_request_deadline = { | ||
Deadline : time, | ||
AllowLateUploads : option grace_period | ||
} | ||
|
||
type file_request_parameters = { | ||
Title : string, | ||
Destination : string, | ||
Deadline : option file_request_deadline, | ||
Open : bool, | ||
Description : option string | ||
} | ||
|
||
type file_request = { | ||
Id : file_request_id, | ||
Url : string, | ||
Title : string, | ||
Created : time, | ||
IsOpen : bool, | ||
FileCount : int, | ||
Destination : option string, | ||
Deadline : option file_request_deadline, | ||
Description : option string | ||
} | ||
|
||
functor Make(M : AUTH) : sig | ||
structure FileRequests : sig | ||
val create : file_request_parameters -> transaction file_request | ||
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ urls | |
oauth | ||
scopes | ||
clearbit | ||
dropbox | ||
github | ||
hotcrp | ||
|