-
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
7 changed files
with
119 additions
and
4 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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
basic_in.ur | ||
*.exe | ||
*.sql | ||
slackSecrets.ur | ||
zoomSecrets.ur | ||
oidcSecrets.ur | ||
dropboxSecrets.ur | ||
*Secrets.ur |
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 zenefitsScrets.ur, | ||
* defining [api_token]. *) | ||
structure Z = Zenefits.Make(Zenefits.TwoLegged(ZenefitsSecrets)) | ||
|
||
fun main () = | ||
ps <- Z.People.list; | ||
return <xml><body> | ||
<ul> | ||
{List.mapX (fn p => <xml><li>{[p.FirstName]} {[p.LastName]} (<tt>{[p.WorkEmail]}</tt>)</li></xml>) ps} | ||
</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 ZenefitsDemo/* | ||
database dbname=zenefitsDemo | ||
sql zenefitsDemo.sql | ||
safeGetDefault | ||
allow url https://* | ||
prefix http://localhost:8080/ | ||
|
||
zenefitsSecrets | ||
zenefitsDemo |
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 : unit -> 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 |
---|---|---|
|
@@ -23,3 +23,4 @@ salesforce | |
slack | ||
zoom | ||
openIdConnect | ||
zenefits |
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 @@ | ||
open Json | ||
open Urls | ||
|
||
functor TwoLegged(M : sig | ||
val api_token : string | ||
end) = struct | ||
open M | ||
|
||
val token = return (Some api_token) | ||
end | ||
|
||
type person = { | ||
FirstName : option string, | ||
PreferredName : option string, | ||
LastName : option string, | ||
WorkEmail : option string, | ||
PersonalEmail : option string | ||
} | ||
val _ : json person = json_record | ||
{FirstName = "first_name", | ||
PreferredName = "preferred_name", | ||
LastName = "last_name", | ||
WorkEmail = "work_email", | ||
PersonalEmail = "personal_email"} | ||
|
||
type subresults a = { | ||
Data : list a, | ||
NextUrl : option string | ||
} | ||
fun json_subresults [a] (_ : json a) : json (subresults a) = | ||
json_record {Data = "data", NextUrl = "next_url"} | ||
|
||
type results a = { | ||
Data : subresults a | ||
} | ||
fun json_results [a] (_ : json a) : json (results a) = | ||
json_record {Data = "data"} | ||
|
||
functor Make(M : sig | ||
val token : transaction (option string) | ||
end) = struct | ||
val token = | ||
tok <- M.token; | ||
case tok of | ||
Some tok => return tok | ||
| None => error <xml>How odd: no Zenefits token!</xml> | ||
|
||
val urlPrefix = "https://api.zenefits.com/" | ||
|
||
fun api url = | ||
tok <- token; | ||
WorldFfi.get url (Some ("Bearer " ^ tok)) True | ||
|
||
fun apiPaged' [a] (_ : json a) (url : url) : transaction (list a) = | ||
s <- api url; | ||
debug (show url ^ " -> " ^ s); | ||
r <- return (fromJson s : results a); | ||
case r.Data.NextUrl of | ||
None => return r.Data.Data | ||
| Some nu => | ||
r' <- apiPaged' (bless nu); | ||
return (List.append r.Data.Data r') | ||
|
||
fun apiPaged [a] (_ : json a) (url : string) : transaction (list a) = | ||
apiPaged' (bless (urlPrefix ^ url)) | ||
|
||
structure People = struct | ||
val list = apiPaged "core/people" | ||
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,25 @@ | ||
functor TwoLegged(M : sig | ||
val api_token : string | ||
end) : sig | ||
val token : transaction (option string) | ||
end | ||
|
||
(** * Person API records *) | ||
|
||
type person = { | ||
FirstName : option string, | ||
PreferredName : option string, | ||
LastName : option string, | ||
WorkEmail : option string, | ||
PersonalEmail : option string | ||
} | ||
|
||
(** * Now for the actual methods.... *) | ||
|
||
functor Make(M : sig | ||
val token : transaction (option string) | ||
end) : sig | ||
structure People : sig | ||
val list : transaction (list person) | ||
end | ||
end |