google.gmail: vocab needs some docs

factor-shell
Björn Lindqvist 2018-02-04 21:53:08 +01:00
parent 2e112a7920
commit 5edc976941
2 changed files with 27 additions and 4 deletions

View File

@ -0,0 +1,23 @@
! 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"

View File

@ -11,20 +11,20 @@ CONSTANT: token-uri "https://www.googleapis.com/oauth2/v4/token"
CONSTANT: redirect-uri "urn:ietf:wg:oauth:2.0:oob" CONSTANT: redirect-uri "urn:ietf:wg:oauth:2.0:oob"
CONSTANT: gmail-scope-ro "https://www.googleapis.com/auth/gmail.readonly" 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 -- ) : configure-oauth2 ( client-id client-secret -- )
[ auth-uri token-uri redirect-uri ] 2dip gmail-scope-ro { } [ auth-uri token-uri redirect-uri ] 2dip gmail-scope-ro { }
oauth2 boa oauth2 set ; oauth2 boa google-oauth2 set ;
: ensure-token ( -- ) : ensure-token ( -- )
access-token [ access-token [
[ [
dup access-expired? [ dup access-expired? [
oauth2 get over refresh-flow update-tokens google-oauth2 get over refresh-flow update-tokens
] when ] when
] [ ] [
oauth2 get console-flow google-oauth2 get console-flow
] if* ] if*
] change ; ] change ;