contextio-go

module
v0.0.0-...-90da9b4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2019 License: Apache-2.0

README

[DEPRECATED] - contextio-go

Context.IO API Golang Library

This library is currently in BETA, and as such we make no promises; the use of this library is provided without warranty.

Installation

# For the LITE api
go get github.com/contextio/contextio-go/ciolite

CIO Lite Usage

package main

import (
	"fmt"
	"log"
	"os"
	"github.com/contextio/contextio-go/ciolite"
)

func main() {
	// Key and Secret
	cioKey := os.Getenv("CONTEXTIO_API_KEY")
	cioSecret := os.Getenv("CONTEXTIO_API_SECRET")

	// Client Instance
	cioLiteClient := ciolite.NewCioLite(cioKey, cioSecret)
	// Can also use with a standard or custom logger:
	// ciolite.NewCioLiteWithLogger(cioKey, cioSecret, logrus.StandardLogger())

	// Discovery Call Parameters
	discoveryParams := ciolite.GetDiscoveryParams{Email: "test@gmail.com"}

	// Actual Discovery Call
	discoveryResp, err := cioLiteClient.GetDiscovery(discoveryParams)
	if err != nil {
		log.Fatal("Error calling ContextIO: " + err.Error())
	}

	// Responses are simple structs, all fields accessible. The following line prints:
	// {Email:test@gmail.com Type:gmail Documentation:[] Found:true
	// IMAP:{Server:imap.gmail.com Username:test@gmail.com UseSSL:true OAuth:true Port:993}}
	fmt.Printf("%+v", discoveryResp)

	// Get a slice of users
	users, _ := cioLiteClient.GetUsers(ciolite.GetUsersParams{})

	// Get a slice of emails in the Inbox of the first users's first email account
	fmt.Println(cioLiteClient.GetUserEmailAccountsFolderMessages(
		users[0].ID,
		users[0].EmailAccounts[0].Label,
		"Inbox",
		ciolite.GetUserEmailAccountsFolderMessageParams{},
	))
}

Testing

A testing interface/mock is provided via GoMock, and can be used in tests like so:

// mock cio
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
cioMock := ciolite.NewMockInterface(mockCtrl)

// mock discovery
discoveryReq := ciolite.GetDiscoveryParams{Email: "test@gmail.com"}
discoveryRes := ciolite.GetDiscoveryResponse{
	Found: true,
	Type:  "gmail",
	IMAP: ciolite.GetDiscoveryIMAPResponse{
		Username: "test@gmail.com",
		Server:   "imap.gmail.com",
		Port:     993,
		UseSSL:   true,
		OAuth:    true,
	},
}

cioMock.EXPECT().GetDiscovery(discoveryReq).Return(discoveryRes, nil)

// use this mock in a test somewhere

Support

If you want to open an issue or PR for this library - go ahead! We'd love to hear your feedback.

For API support please consult our support site and feel free to drop a line to support@context.io.

Directories

Path Synopsis
Package ciolite is the Golang client library for the Lite Context.IO API Package ciolite is a generated GoMock package.
Package ciolite is the Golang client library for the Lite Context.IO API Package ciolite is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL