Documentation
¶
Overview ¶
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- type Access
- func (a *Access) Connect(service any)
- func (a *Access) Cycle(rate time.Duration)
- func (a *Access) GetClient() *http.Client
- func (a *Access) Gmail() *Gmailer
- func (a *Access) ReadCredentials()
- func (a *Access) SaveToken() error
- func (a *Access) Sheets() *Sheeter
- func (a *Access) TokenFromFile() error
- func (a *Access) TokenFromWeb()
- type Gmailer
- func (g *Gmailer) CheckByLabel(label string) (int64, error)
- func (g *Gmailer) CheckForUnread() (int64, error)
- func (g *Gmailer) DecodeEmailBody(data string) (string, error)
- func (g *Gmailer) GetBody(msg *gmail.Message, mimeType string) (string, error)
- func (g *Gmailer) GetByID(msgs *gmail.ListMessagesResponse) ([]*gmail.Message, error)
- func (g *Gmailer) GetLabels() (*gmail.ListLabelsResponse, error)
- func (g *Gmailer) GetMessages(howMany uint) ([]*gmail.Message, error)
- func (g *Gmailer) GetPartialMetadata(msg *gmail.Message) *PartialMetadata
- func (g *Gmailer) MarkAllAsRead() error
- func (g *Gmailer) MarkAs(msg *gmail.Message, req *gmail.ModifyMessageRequest) (*gmail.Message, error)
- func (g *Gmailer) Query(query string) ([]*gmail.Message, error)
- func (g *Gmailer) ReceivedTime(datetime int64) (time.Time, error)
- func (g *Gmailer) Send(m *Msg) error
- type Msg
- type PartialMetadata
- type Sheeter
- type SpreadSheet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Access ¶
type Access struct { Context context.Context // TokenPath is the path to your token.json file. If you're having trouble // authenticating, try deleting this file and running the program // again. This should renew your token. If you've never run this // program, you may not have a token. This program will generate a // token for you. Also see: Access.CredentialsPath TokenPath string // CredentialsPath is the path to your credentials.json file. This file can // be obtained from the API Keys section of Google Cloud Platform. You // may need to generate the file and enable the API you're interfacing with // from within Google Cloud Platform. CredentialsPath string // Scopes define what level(s) of access we'll have to the API service. // If modifying these scopes, delete your previously saved token.json. Scopes []string // Config is mostly generated and used by the API. Config *oauth2.Config // The token is the token used to authenticate with the API, and will need // to be refreshed using *Access.Cycle() Token *oauth2.Token // GmailAPI is used as an alternative access point to the Gmail API // service, if you don't wish to use the Gmailer struct. see: gmail.go GmailAPI *gmail.Service // SheetsAPI is used as an alternative access point to the Sheets API // service, if you don't wish to use the Sheeter struct. see: sheets.go SheetsAPI *sheets.Service // RefreshRate RefreshRate *time.Ticker // LastRefreshed LastRefreshed time.Time Client *http.Client }
Access contains values used for accessing Googles API services, including access token, API credentials, and scopes
func NewAccess ¶
NewAccess() instantiates a new *Access struct, initializing it with default values most people will probably need, and authenticated the user, taking them through the manual authentication process as necessary (see READEME.md)
func (*Access) Connect ¶
*Access.Connect(any) connects us to a service. At this time gsheet only supports the Gmail API, the Google Sheets API, or both. Pass either of the following empty (as empty structs):
*gmail.Sevice{} *sheets.Service{}
func (*Access) Cycle ¶
*Access.Cycle(time.Duration) is used to cycle (refresh) the token, if ran with rate = 0 it'll refresh every 23 hours as default.
func (*Access) ReadCredentials ¶
func (a *Access) ReadCredentials()
func (*Access) TokenFromFile ¶
Retrieves a token from a local file.
func (*Access) TokenFromWeb ¶
func (a *Access) TokenFromWeb()
Request a token from the web, then returns the retrieved token.
type Gmailer ¶
type Gmailer struct { Service *gmail.Service Msgs []*Msg }
Gmailer is a wrapper around the *gmail.Service type, giving us access to the Google Gmail API service.
func (*Gmailer) CheckByLabel ¶
*Gmailer.CheckFByLabel() checks for mail matching the specified label.
func (*Gmailer) CheckForUnread ¶
*Gmailer.CheckForUnread() checks for mail labeled "UNREAD". NOTE: When checking your inbox for unread messages, it's not uncommon for it to return thousands of unread messages that you don't know about. To see them in gmail, query your mail for "label:unread". For CheckForUnread to work properly you need to mark all mail as read either through gmail or through the MarkAllAsRead() function found in this library.
func (*Gmailer) DecodeEmailBody ¶
*Gmailer.DecodeEmailBody() is used to decode the email body by converting from URLEncoded base64 to a string.
func (*Gmailer) GetBody ¶
*Gmailer.GetBody() gets, decodes, and returns the body of the email. It returns an error if decoding goes wrong. mimeType is used to indicate whether you want the plain text or html encoding ("text/html", "text/plain").
func (*Gmailer) GetByID ¶
*Gmailer.GetByID() gets emails individually by ID. This is necessary because this is how the gmail API is set [0][1] up apparently (but why?). [0] https://developers.google.com/gmail/api/v1/reference/users/messages/get [1] https://stackoverflow.com/questions/36365172/message-payload-is-always-null-for-all-messages-how-do-i-get-this-data
func (*Gmailer) GetMessages ¶
*Gmailer.GetMessages() gets and returns gmail messages
func (*Gmailer) GetPartialMetadata ¶
func (g *Gmailer) GetPartialMetadata(msg *gmail.Message) *PartialMetadata
*Gmailer.GetPartialMetadata() gets some of the useful metadata from the headers.
func (*Gmailer) MarkAllAsRead ¶
*Gmailer.MarkAllAsRead() removes the UNREAD label from all emails.
func (*Gmailer) MarkAs ¶
func (g *Gmailer) MarkAs(msg *gmail.Message, req *gmail.ModifyMessageRequest) (*gmail.Message, error)
*Gmailer.MarkAs() allows you to mark an email with a specific label using the gmail.ModifyMessageRequest struct.
func (*Gmailer) Query ¶
*Gmailer.Query() queries the inbox for a string following the search style of the gmail online mailbox. example: "in:sent after:2017/01/01 before:2017/01/30"
func (*Gmailer) ReceivedTime ¶
*Gmailer.ReceivedTime() parses and converts a Unix time stamp into a human readable format ().
type Msg ¶
type Msg struct { From string To string Subject string Body string ImagePath string MimeType string Markup string Bytes []byte Formed *gmail.Message PartialMetadata }
Gmailer.Msg is an email message, self explanatory
type PartialMetadata ¶
type PartialMetadata struct { // Sender is the entity that originally created and sent the message Sender string // From is the entity that sent the message to you (e.g. googlegroups). Most // of the time this information is only relevant to mailing lists. From string // Subject is the email subject Subject string // Mailing list contains the name of the mailing list that the email was // posted to, if any. MailingList string // CC is the "carbon copy" list of addresses CC []string // To is the recipient of the email. To []string // ThreadTopic contains the topic of the thread (e.g. google groups threads) ThreadTopic []string // DeliveredTo is who the email was sent to. This can contain multiple // addresses if the email was forwarded. DeliveredTo []string }
PartialMetadata stores email metadata. Some fields may sound redundant, but in fact have different contexts. Some are slices of string because the ones that have multiple values are still being sorted from those that don't.
type Sheeter ¶
type Sheeter struct { Service *sheets.Service DefaultSheet *SpreadSheet // just guess what these could be used for Writables map[string]*SpreadSheet Readables map[string]*SpreadSheet ReadWriteables map[string]*SpreadSheet }
gsheet.Sheeter is a wrapper around the *sheets.Service type, giving us access to the Google Sheets API service.
func (*Sheeter) AppendRow ¶
func (s *Sheeter) AppendRow(sht *SpreadSheet) (*sheets.AppendValuesResponse, error)
*Sheeter.AppendRow() is used to append a row to a spreadsheet
func (*Sheeter) Read ¶
func (s *Sheeter) Read(sht *SpreadSheet) (*sheets.ValueRange, error)
*Sheeter.Read() is used to read from a spreadsheet