From 54f7114c448727de15eaae6be1cc661419c1f0cd Mon Sep 17 00:00:00 2001 From: Matthieu Dubuget Date: Wed, 7 Dec 2016 23:21:43 +0100 Subject: [PATCH] WiP --- googleApps.ml | 98 +++++++++------- googleApps.mli | 295 +++++++++++++++++++++++++++++++++---------------- opam | 7 ++ 3 files changed, 266 insertions(+), 134 deletions(-) create mode 100644 opam diff --git a/googleApps.ml b/googleApps.ml index 63f7ef8..b3e5e16 100644 --- a/googleApps.ml +++ b/googleApps.ml @@ -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 + module Date : sig type t val t_of_js: Ojs.t -> t val t_to_js: t -> Ojs.t val now: unit -> t [@@js.new "Date"] - val get_day: t -> int [@@js.call] (* day of the week (0-6) *) - val get_full_year: t -> int [@@js.call] (* year (4 digits for 4-digit years) *) - val get_month: t -> int [@@js.call] (* month (0-11) *) - val get_date: t -> int [@@js.call] (* day of the month (1-31) *) - val get_hours: t -> int [@@js.call] (* hour (0-23) *) - val get_minutes: t -> int [@@js.call] (* minutes (0-59) *) - val get_seconds: t -> int [@@js.call] (* seconds (0-59) *) + val get_day: t -> int [@@js.call] + val get_full_year: t -> int [@@js.call] + val get_month: t -> int [@@js.call] + val get_date: t -> int [@@js.call] + val get_hours: t -> int [@@js.call] + val get_minutes: t -> int [@@js.call] + val get_seconds: t -> int [@@js.call] val to_date_string: t -> string [@@js.call] val to_ISO_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] 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 type t 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_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] @@ -88,6 +98,7 @@ include ([%js] : sig val get_data_range: t -> Range.t [@@js.call] val get_name: t -> string [@@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 module EmailField : sig @@ -98,11 +109,10 @@ include ([%js] : sig module PhoneField : sig type t module Field : sig - type t = - | Work [@js "ContactsApp.Field.WORK_PHONE"] - | Mobile [@js "ContactsApp.Field.MOBILE_PHONE"] - | Home [@js "ContactsApp.Field.HOME_PHONE"] - [@@js.enum] + type t + val work : t [@@js.global "ContactsApp.Field.WORK_PHONE"] + val mobile : t [@@js.global "ContactsApp.Field.MOBILE_PHONE"] + val home : t [@@js.global "ContactsApp.Field.HOME_PHONE"] end val get_phone_number: t -> string [@@js.call] end @@ -119,20 +129,34 @@ include ([%js] : sig val get_phones: t -> PhoneField.t list [@@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 type g val get_contact_group: string -> g [@@js.global "ContactsApp.getContactGroup"] val get_contacts: g -> t list [@@js.call] end - + val add_to_group: t -> Group.g -> t [@@js.call] 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 - type t - val i : t [@@js.global "GmailApp"] - val send_email: t -> address:string -> subject:string -> content:string -> unit [@@js.call] + val send_email: recipient:string -> subject:string -> body:string -> unit + [@@js.global "GmailApp.sendEmail"] + val search: string -> GmailThread.t list [@@js.global "GmailApp.search"] end end) diff --git a/googleApps.mli b/googleApps.mli index 95886cc..2f7d2d6 100644 --- a/googleApps.mli +++ b/googleApps.mli @@ -1,110 +1,211 @@ -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 +(** OCaml binding for Google Apps (https://developers.google.com/apps-script/) *) + +(** Standard JavaScript Date *) module Date : - sig - type t - val t_of_js : Ojs.t -> t - val t_to_js : t -> Ojs.t - val now : unit -> t - val get_day : t -> int - val get_full_year : t -> int - val get_month : t -> int - val get_date : t -> int - val get_hours : t -> int - val get_minutes : t -> int - 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 +sig + type t + val t_of_js : Ojs.t -> t + val t_to_js : t -> Ojs.t + val now : unit -> t + + (** @return day of the week (0-6) *) + val get_day : t -> int + + (** @return year (4 digits) *) + val get_full_year : t -> int + + (** @return month (0-11) *) + val get_month : t -> int + + (** @return day of the month (1-31) *) + 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 : - sig - type t - val t_of_js : Ojs.t -> t - val get_id : t -> string - val get_name : t -> string - val get_size : t -> int - end +sig + type t + val t_of_js : Ojs.t -> t + val get_id : t -> string + val get_name : t -> string + val get_size : t -> int +end + +(** An iterator that allows scripts to iterate over a potentially large +collection of {!File.t}.*) module FileIterator : - sig - type t - val get_files : unit -> t - val t_of_js : Ojs.t -> t - val has_next : t -> bool - val next : t -> File.t - end -val log : string -> unit +sig + type t + + (** @return a {!FileIterator.t} for all files of the drive *) + val get_files : unit -> t + val t_of_js : Ojs.t -> t + val has_next : t -> bool + val next : t -> File.t +end + +(** spreadsheet ranges *) module Range : - sig - type t - val get_a1_notation : t -> string - val get_background : t -> string - val get_row : t -> int - val get_last_row : t -> int - val get_column : t -> int - val get_last_column : t -> int - val get_num_columns : t -> int - val get_num_rows : t -> int - val get_values : t -> Ojs.t array array - val get_formulas : t -> string array array - val get_display_values : t -> string array array - val set_value : t -> Ojs.t -> t - end +sig + type t + val get_a1_notation : t -> string + val get_background : t -> string + val get_row : t -> int + val get_last_row : t -> int + val get_column : t -> int + val get_last_column : t -> int + val get_num_columns : t -> int + val get_num_rows : t -> int + val get_values : t -> Ojs.t array array + val get_formulas : t -> string array array + val get_display_values : t -> string array array + val set_value : t -> Ojs.t -> t +end + +(** spreadsheet named ranges *) 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 : - sig - type t - val get_active_sheet : unit -> t - val get_last_row : t -> int - val get_last_column : t -> int - val get_sheet_values : - t -> - start_row:int -> - start_column:int -> - num_rows:int -> num_columns:int -> Ojs.t array array - val get_range : - t -> - start_row:int -> - start_column:int -> num_rows:int -> num_columns:int -> Range.t - val get_data_range : t -> Range.t - val get_name : t -> string - val get_named_ranges : t -> NamedRange.t list - end -module EmailField : sig type t val get_address : t -> string end +sig + type t + val get_active_sheet : unit -> t + val get_ui: unit -> Ui.t + val get_last_row : t -> int + val get_last_column : t -> int + val get_sheet_values : + t -> + start_row:int -> + start_column:int -> + num_rows:int -> num_columns:int -> Ojs.t array array + val get_range : + t -> + start_row:int -> + start_column:int -> num_rows:int -> num_columns:int -> Range.t + val get_data_range : t -> Range.t + val get_name : t -> string + val get_named_ranges : t -> NamedRange.t list +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 : - sig +sig + type t + module Field : sig type t - module Field : sig type t = Work | Mobile | Home end - val get_phone_number : t -> string + val work : t + val mobile : t + val home : t end + val get_phone_number : t -> string +end + +(** A {!Contact.t} contains the name, address, and various contact details of a contact.*) 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 - type t - val get_contacts : unit -> t list - module Group : - 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 + 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 + + (** 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 : - sig - type t - val i : t - val send_email : - t -> address:string -> subject:string -> content:string -> unit - end +sig + + (** Send an email *) + val send_email : recipient:string -> subject:string -> body:string -> unit + val search : string -> GmailThread.t list +end + +val log : string -> unit diff --git a/opam b/opam new file mode 100644 index 0000000..6621a8b --- /dev/null +++ b/opam @@ -0,0 +1,7 @@ +opam-version: "1.2" +name: "ocaml-google-apps" +version: "0.1" +maintainer: "Matthieu Dubuget " +install: [make "install"] +remove: [make "uninstall"] +depends: "ocamlfind"