This commit is contained in:
Matthieu Dubuget 2016-12-07 23:21:43 +01:00
parent 9ec88ea823
commit 54f7114c44
3 changed files with 266 additions and 134 deletions

View File

@ -1,36 +1,17 @@
module Dict : sig
type 'a t = (string * 'a) list
val t_to_js: ('a -> Ojs.t) -> 'a t -> Ojs.t
val t_of_js: (Ojs.t -> 'a) -> Ojs.t -> 'a t
end = struct
type 'a t = (string * 'a) list
let t_to_js ml2js l =
let o = Ojs.empty_obj () in
List.iter (fun (k, v) -> Ojs.set o k (ml2js v)) l;
o
let t_of_js js2ml o =
let l = ref [] in
Ojs.iter_properties o
(fun k -> l := (k, js2ml (Ojs.get o k)) :: !l);
!l
end
include ([%js] : sig include ([%js] : sig
module Date : sig module Date : sig
type t type t
val t_of_js: Ojs.t -> t val t_of_js: Ojs.t -> t
val t_to_js: t -> Ojs.t val t_to_js: t -> Ojs.t
val now: unit -> t [@@js.new "Date"] val now: unit -> t [@@js.new "Date"]
val get_day: t -> int [@@js.call] (* day of the week (0-6) *) val get_day: t -> int [@@js.call]
val get_full_year: t -> int [@@js.call] (* year (4 digits for 4-digit years) *) val get_full_year: t -> int [@@js.call]
val get_month: t -> int [@@js.call] (* month (0-11) *) val get_month: t -> int [@@js.call]
val get_date: t -> int [@@js.call] (* day of the month (1-31) *) val get_date: t -> int [@@js.call]
val get_hours: t -> int [@@js.call] (* hour (0-23) *) val get_hours: t -> int [@@js.call]
val get_minutes: t -> int [@@js.call] (* minutes (0-59) *) val get_minutes: t -> int [@@js.call]
val get_seconds: t -> int [@@js.call] (* seconds (0-59) *) val get_seconds: t -> int [@@js.call]
val to_date_string: t -> string [@@js.call] val to_date_string: t -> string [@@js.call]
val to_ISO_string: t -> string [@@js.call] val to_ISO_string: t -> string [@@js.call]
val to_locale_date_string: t -> string [@@js.call] val to_locale_date_string: t -> string [@@js.call]
@ -78,9 +59,38 @@ include ([%js] : sig
val get_range: t -> Range.t [@@js.call] val get_range: t -> Range.t [@@js.call]
end end
module SandboxMode : sig
type t
val iframe : t [@@js.global "HtmlService.SandboxMode.IFRAME"]
end
module HtmlOutput : sig
type t
val create_html_output_from_file: string -> t [@@js.global "HtmlService.createHtmlOutputFromFile"]
val set_sandbox_mode : t -> SandboxMode.t -> t [@@js.call]
val set_title : t -> string -> t [@@js.call]
end
module Menu : sig
type t
val add_item : t -> caption:string -> functionName:string -> t [@@js.call]
val add_separator : t -> t [@@js.call]
val add_sub_menu : t -> t -> t [@@js.call]
val add_to_ui : t -> unit [@@js.call]
end
module Ui : sig
type t
type menu
val show_sidebar : t -> HtmlOutput.t -> unit [@@js.call]
val create_menu : t -> caption:string -> Menu.t [@@js.call]
end
module Sheet : sig module Sheet : sig
type t type t
val get_active_sheet: unit -> t [@@js.global "SpreadsheetApp.getActiveSheet"] val get_active_sheet: unit -> t [@@js.global "SpreadsheetApp.getActiveSheet"]
val get_ui: unit -> Ui.t [@@js.global "SpreadsheetApp.getUi"]
val get_last_row: t -> int [@@js.call] val get_last_row: t -> int [@@js.call]
val get_last_column: t -> int [@@js.call] val get_last_column: t -> int [@@js.call]
val get_sheet_values: t -> start_row:int -> start_column:int -> num_rows:int -> num_columns:int -> Ojs.t array array [@@js.call] val get_sheet_values: t -> start_row:int -> start_column:int -> num_rows:int -> num_columns:int -> Ojs.t array array [@@js.call]
@ -88,6 +98,7 @@ include ([%js] : sig
val get_data_range: t -> Range.t [@@js.call] val get_data_range: t -> Range.t [@@js.call]
val get_name: t -> string [@@js.call] val get_name: t -> string [@@js.call]
val get_named_ranges: t -> NamedRange.t list [@@js.call] val get_named_ranges: t -> NamedRange.t list [@@js.call]
val add_menu: string -> Ojs.t list -> unit [@@js.global "Spreadsheet.addMenu"]
end end
module EmailField : sig module EmailField : sig
@ -98,11 +109,10 @@ include ([%js] : sig
module PhoneField : sig module PhoneField : sig
type t type t
module Field : sig module Field : sig
type t = type t
| Work [@js "ContactsApp.Field.WORK_PHONE"] val work : t [@@js.global "ContactsApp.Field.WORK_PHONE"]
| Mobile [@js "ContactsApp.Field.MOBILE_PHONE"] val mobile : t [@@js.global "ContactsApp.Field.MOBILE_PHONE"]
| Home [@js "ContactsApp.Field.HOME_PHONE"] val home : t [@@js.global "ContactsApp.Field.HOME_PHONE"]
[@@js.enum]
end end
val get_phone_number: t -> string [@@js.call] val get_phone_number: t -> string [@@js.call]
end end
@ -119,20 +129,34 @@ include ([%js] : sig
val get_phones: t -> PhoneField.t list [@@js.call] val get_phones: t -> PhoneField.t list [@@js.call]
val add_phone: t -> PhoneField.Field.t -> string -> PhoneField.t [@@js.call] val add_phone: t -> PhoneField.Field.t -> string -> PhoneField.t [@@js.call]
val create: given_name:string -> family_name:string -> email:string -> t
[@@js.global "ContactsApp.createContact"]
module Group : sig module Group : sig
type g type g
val get_contact_group: string -> g [@@js.global "ContactsApp.getContactGroup"] val get_contact_group: string -> g [@@js.global "ContactsApp.getContactGroup"]
val get_contacts: g -> t list [@@js.call] val get_contacts: g -> t list [@@js.call]
end end
val add_to_group: t -> Group.g -> t [@@js.call]
val get_contact_groups: t -> Group.g list val get_contact_groups: t -> Group.g list
end end
module GmailMessage : sig
type t
val get_body : t -> string [@@js.call]
val get_subject : t -> string [@@js.call]
val get_from : t -> string [@@js.call]
end
module GmailThread : sig
type t
val get_messages: t -> GmailMessage.t list [@@js.call]
end
module GmailApp : sig module GmailApp : sig
type t val send_email: recipient:string -> subject:string -> body:string -> unit
val i : t [@@js.global "GmailApp"] [@@js.global "GmailApp.sendEmail"]
val send_email: t -> address:string -> subject:string -> content:string -> unit [@@js.call] val search: string -> GmailThread.t list [@@js.global "GmailApp.search"]
end end
end) end)

View File

@ -1,110 +1,211 @@
module Dict : (** OCaml binding for Google Apps (https://developers.google.com/apps-script/) *)
sig
type 'a t = (string * 'a) list (** Standard JavaScript Date *)
val t_to_js : ('a -> Ojs.t) -> 'a t -> Ojs.t
val t_of_js : (Ojs.t -> 'a) -> Ojs.t -> 'a t
end
module Date : module Date :
sig sig
type t type t
val t_of_js : Ojs.t -> t val t_of_js : Ojs.t -> t
val t_to_js : t -> Ojs.t val t_to_js : t -> Ojs.t
val now : unit -> t val now : unit -> t
val get_day : t -> int
val get_full_year : t -> int (** @return day of the week (0-6) *)
val get_month : t -> int val get_day : t -> int
val get_date : t -> int
val get_hours : t -> int (** @return year (4 digits) *)
val get_minutes : t -> int val get_full_year : t -> int
val get_seconds : t -> int
val to_date_string : t -> string (** @return month (0-11) *)
val to_ISO_string : t -> string val get_month : t -> int
val to_locale_date_string : t -> string
val to_string : t -> string (** @return day of the month (1-31) *)
end val get_date : t -> int
(** @return hour (0-23) *)
val get_hours : t -> int
(** @return minutes (0-59) *)
val get_minutes : t -> int
(** @return seconds (0-59) *)
val get_seconds : t -> int
val to_date_string : t -> string
val to_ISO_string : t -> string
val to_locale_date_string : t -> string
val to_string : t -> string
end
(** Files in Google Drive. *)
module File : module File :
sig sig
type t type t
val t_of_js : Ojs.t -> t val t_of_js : Ojs.t -> t
val get_id : t -> string val get_id : t -> string
val get_name : t -> string val get_name : t -> string
val get_size : t -> int val get_size : t -> int
end end
(** An iterator that allows scripts to iterate over a potentially large
collection of {!File.t}.*)
module FileIterator : module FileIterator :
sig sig
type t type t
val get_files : unit -> t
val t_of_js : Ojs.t -> t (** @return a {!FileIterator.t} for all files of the drive *)
val has_next : t -> bool val get_files : unit -> t
val next : t -> File.t val t_of_js : Ojs.t -> t
end val has_next : t -> bool
val log : string -> unit val next : t -> File.t
end
(** spreadsheet ranges *)
module Range : module Range :
sig sig
type t type t
val get_a1_notation : t -> string val get_a1_notation : t -> string
val get_background : t -> string val get_background : t -> string
val get_row : t -> int val get_row : t -> int
val get_last_row : t -> int val get_last_row : t -> int
val get_column : t -> int val get_column : t -> int
val get_last_column : t -> int val get_last_column : t -> int
val get_num_columns : t -> int val get_num_columns : t -> int
val get_num_rows : t -> int val get_num_rows : t -> int
val get_values : t -> Ojs.t array array val get_values : t -> Ojs.t array array
val get_formulas : t -> string array array val get_formulas : t -> string array array
val get_display_values : t -> string array array val get_display_values : t -> string array array
val set_value : t -> Ojs.t -> t val set_value : t -> Ojs.t -> t
end end
(** spreadsheet named ranges *)
module NamedRange : module NamedRange :
sig type t val get_name : t -> string val get_range : t -> Range.t end sig
type t
val get_name : t -> string
val get_range : t -> Range.t
end
module SandboxMode : sig
type t
val iframe : t
end
module HtmlOutput :
sig
type t
val create_html_output_from_file : string -> t
val set_sandbox_mode : t -> SandboxMode.t -> t
val set_title : t -> string -> t
end
module Menu :
sig
type t
val add_item : t -> caption:string -> functionName:string -> t
val add_separator : t -> t
val add_sub_menu : t -> t -> t
val add_to_ui : t -> unit
end
module Ui :
sig
type t
type menu
val show_sidebar : t -> HtmlOutput.t -> unit
val create_menu : t -> caption:string -> Menu.t
end
(** Access and modify spreadsheet sheets. *)
module Sheet : module Sheet :
sig sig
type t type t
val get_active_sheet : unit -> t val get_active_sheet : unit -> t
val get_last_row : t -> int val get_ui: unit -> Ui.t
val get_last_column : t -> int val get_last_row : t -> int
val get_sheet_values : val get_last_column : t -> int
t -> val get_sheet_values :
start_row:int -> t ->
start_column:int -> start_row:int ->
num_rows:int -> num_columns:int -> Ojs.t array array start_column:int ->
val get_range : num_rows:int -> num_columns:int -> Ojs.t array array
t -> val get_range :
start_row:int -> t ->
start_column:int -> num_rows:int -> num_columns:int -> Range.t start_row:int ->
val get_data_range : t -> Range.t start_column:int -> num_rows:int -> num_columns:int -> Range.t
val get_name : t -> string val get_data_range : t -> Range.t
val get_named_ranges : t -> NamedRange.t list val get_name : t -> string
end val get_named_ranges : t -> NamedRange.t list
module EmailField : sig type t val get_address : t -> string end end
(** An email field in a {!Contact.t}. *)
module EmailField :
sig
type t
val get_address : t -> string
end
(** An email field in a {!Contact.t}. *)
module PhoneField : module PhoneField :
sig sig
type t
module Field : sig
type t type t
module Field : sig type t = Work | Mobile | Home end val work : t
val get_phone_number : t -> string val mobile : t
val home : t
end end
val get_phone_number : t -> string
end
(** A {!Contact.t} contains the name, address, and various contact details of a contact.*)
module Contacts : module Contacts :
sig
type t
val get_contacts : unit -> t list
(** Create a contact *)
val create: given_name:string -> family_name:string -> email:string -> t
(** A {!Group.t} is is a group of contacts. *)
module Group :
sig sig
type t type g
val get_contacts : unit -> t list val get_contact_group : string -> g
module Group : val get_contacts : g -> t list
sig
type g
val get_contact_group : string -> g
val get_contacts : g -> t list
end
val get_emails : t -> EmailField.t list
val get_family_name : t -> string
val get_given_name : t -> string
val get_full_name : t -> string
val get_phones : t -> PhoneField.t list
val get_contact_groups : t -> Group.g list
val add_phone : t -> PhoneField.Field.t -> string -> PhoneField.t
end end
val get_emails : t -> EmailField.t list
val get_family_name : t -> string
val get_given_name : t -> string
val get_full_name : t -> string
val get_phones : t -> PhoneField.t list
val get_contact_groups : t -> Group.g list
val add_phone : t -> PhoneField.Field.t -> string -> PhoneField.t
(** Adds a {!Contact.t} to a {!Group.t} *)
val add_to_group: t -> Group.g -> t
val get_contact_groups: t -> Group.g list
end
module GmailMessage :
sig
type t
val get_body : t -> string
val get_subject : t -> string
val get_from : t -> string
end
module GmailThread :
sig
type t
val get_messages: t -> GmailMessage.t list
end
(** Provides access to Gmail threads, messages, and labels. *)
module GmailApp : module GmailApp :
sig sig
type t
val i : t (** Send an email *)
val send_email : val send_email : recipient:string -> subject:string -> body:string -> unit
t -> address:string -> subject:string -> content:string -> unit val search : string -> GmailThread.t list
end end
val log : string -> unit

7
opam Normal file
View File

@ -0,0 +1,7 @@
opam-version: "1.2"
name: "ocaml-google-apps"
version: "0.1"
maintainer: "Matthieu Dubuget <matthieu.dubuget@gmail.com>"
install: [make "install"]
remove: [make "uninstall"]
depends: "ocamlfind"