--- /dev/null
+! Copyright (C) 2018 Björn Lindqvist.
+! See http://factorcode.org/license.txt for BSD license.
+USING: help.markup help.syntax ;
+IN: google.gmail
+
+ARTICLE: "google.gmail" "GMail Client"
+"This vocab implements an api to GMail based on " { $vocab-link "oauth2" } "."
+$nl
+"To use the vocab, it first needs to be supplied the 'Client ID' and 'Client secret settings' using the " { $link configure-oauth2 } " vord:"
+{ $unchecked-example
+ "\"client-id\" \"client-secret\" configure-oauth2"
+}
+"The settings can be found on Google's developer console at " { $url "https://console.developers.google.com" } ". Then the authenticated users labels can be listed using:"
+{ $unchecked-example
+ "list-labels"
+}
+"Or to list the first message in the users inbox:"
+{ $unchecked-example
+ "\"INBOX\" list-messages-by-label \"messages\" of"
+ "first \"id\" of { } get-messages"
+} ;
+
+ABOUT: "google.gmail"
CONSTANT: redirect-uri "urn:ietf:wg:oauth:2.0:oob"
CONSTANT: gmail-scope-ro "https://www.googleapis.com/auth/gmail.readonly"
-SYMBOL: access-token
+SYMBOLS: access-token google-oauth2 ;
: configure-oauth2 ( client-id client-secret -- )
[ auth-uri token-uri redirect-uri ] 2dip gmail-scope-ro { }
- oauth2 boa oauth2 set ;
+ oauth2 boa google-oauth2 set ;
: ensure-token ( -- )
access-token [
[
dup access-expired? [
- oauth2 get over refresh-flow update-tokens
+ google-oauth2 get over refresh-flow update-tokens
] when
] [
- oauth2 get console-flow
+ google-oauth2 get console-flow
] if*
] change ;