sendgrid

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 15 Imported by: 0

README

SendGrid API in Go

GoDoc test lint codecov

This library supports most if not all of the SendGrid REST calls.

Installing

go get
$ go get -u github.com/kenzo0107/sendgrid

Example

Get Teammate
package main

import (
	"context"
	"log"
	"os"

	"github.com/kenzo0107/sendgrid"
)

func main() {
	apiKey := os.Getenv("SENDGRID_API_KEY")

	c := sendgrid.New(apiKey)
	u, err := c.GetTeammate(context.TODO(), "username")
	if err != nil {
		fmt.Printf("%s\n", err)
		return
	}
	log.Printf("user: %#v\n", u)
}

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func OptionBaseURL

func OptionBaseURL(endpoint string) func(*Client)

OptionBaseURL - provide a custom base url to the sendgrid client.

func OptionDebug

func OptionDebug(b bool) func(*Client)

OptionDebug enable debugging for the client

func OptionHTTPClient

func OptionHTTPClient(client httpClient) func(*Client)

OptionHTTPClient - provide a custom http client to the sendgrid client.

func OptionLog

func OptionLog(l logger) func(*Client)

OptionLog set logging for client.

func OptionSubuser

func OptionSubuser(subuser string) func(*Client)

OptionBaseURL - provide a custom base url to the sendgrid client.

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Types

type APIKey added in v0.0.2

type APIKey struct {
	ApiKeyId string `json:"api_key_id,omitempty"`
	Name     string `json:"name,omitempty"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client : sendgrid client

func New

func New(apiKey string, options ...Option) *Client

New builds a sendgrid client from the provided token, baseURL and options

func (*Client) AddOptions

func (c *Client) AddOptions(s string, opts interface{}) (string, error)

AddOptions adds the parameters in opt as URL query parameters to s. opt must be a struct whose fields may contain "url" tags.

func (*Client) CreateAPIKey added in v0.0.2

func (c *Client) CreateAPIKey(ctx context.Context, input *InputCreateAPIKey) (*OutputCreateAPIKey, error)

func (*Client) CreateSubuser added in v0.0.3

func (c *Client) CreateSubuser(ctx context.Context, input *InputCreateSubuser) (*OutputCreateSubuser, error)

func (*Client) Debug

func (c *Client) Debug() bool

Debug returns if debug is enabled.

func (*Client) Debugf

func (c *Client) Debugf(format string, v ...interface{})

Debugf print a formatted debug line.

func (*Client) Debugln

func (c *Client) Debugln(v ...interface{})

Debugln print a debug line.

func (*Client) DeleteAPIKey added in v0.0.2

func (c *Client) DeleteAPIKey(ctx context.Context, apiKeyId string) error

func (*Client) DeletePendingTeammate

func (c *Client) DeletePendingTeammate(ctx context.Context, token string) error

func (*Client) DeleteSubuser added in v0.0.3

func (c *Client) DeleteSubuser(ctx context.Context, username string) error

func (*Client) DeleteTeammate

func (c *Client) DeleteTeammate(ctx context.Context, username string) error

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) error

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If rate limit is exceeded and reset time is in the future, Do returns *RateLimitError immediately without making a network API call.

The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) GetAPIKey added in v0.0.2

func (c *Client) GetAPIKey(ctx context.Context, apiKeyId string) (*OutputGetAPIKey, error)

func (*Client) GetAPIKeys added in v0.0.2

func (c *Client) GetAPIKeys(ctx context.Context) (*OutputGetAPIKeys, error)

func (*Client) GetPendingTeammates

func (c *Client) GetPendingTeammates(ctx context.Context) (*OutputGetPendingTeammates, error)

func (*Client) GetSubuserReputations added in v0.0.3

func (c *Client) GetSubuserReputations(ctx context.Context, usernames string) ([]*Reputation, error)

func (*Client) GetSubusers added in v0.0.3

func (c *Client) GetSubusers(ctx context.Context, input *InputGetSubusers) ([]*Subuser, error)

func (*Client) GetTeammate

func (c *Client) GetTeammate(ctx context.Context, username string) (*OutputGetTeammate, error)

func (*Client) GetTeammates

func (c *Client) GetTeammates(ctx context.Context) (*OutputGetTeammates, error)

func (*Client) InviteTeammate

func (c *Client) InviteTeammate(ctx context.Context, input *InputInviteTeammate) (*OutputInviteTeammate, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) UpdateAPIKeyName added in v0.0.2

func (c *Client) UpdateAPIKeyName(ctx context.Context, apiKeyId string, input *InputUpdateAPIKeyName) (*OutputUpdateAPIKeyName, error)

func (*Client) UpdateAPIKeyNameAndScopes added in v0.0.2

func (c *Client) UpdateAPIKeyNameAndScopes(ctx context.Context, apiKeyId string, input *InputUpdateAPIKeyNameAndScopes) (*OutputUpdateAPIKeyNameAndScopes, error)

func (*Client) UpdateSubuserIps added in v0.0.3

func (c *Client) UpdateSubuserIps(ctx context.Context, username string, ips []string) error

func (*Client) UpdateSubuserStatus added in v0.0.3

func (c *Client) UpdateSubuserStatus(ctx context.Context, username string, input *InputUpdateSubuserStatus) error

func (*Client) UpdateTeammatePermissions

func (c *Client) UpdateTeammatePermissions(ctx context.Context, username string, input *InputUpdateTeammatePermissions) (*OutputUpdateTeammatePermissions, error)

type CreditAllocation added in v0.0.3

type CreditAllocation struct {
	Type string `json:"type"`
}

type Error

type Error struct {
	Field   *string `json:"field,omitempty"`
	Message *string `json:"message,omitempty"`
}

Error is sendgrid error

type ErrorResponse

type ErrorResponse struct {
	Errors []*Error `json:"errors"`
}

ErrorResponse is sendgrid error response

func (ErrorResponse) Errs

func (t ErrorResponse) Errs() error

Errs : error

type InputCreateAPIKey added in v0.0.2

type InputCreateAPIKey struct {
	Name   string   `json:"name,omitempty"`
	Scopes []string `json:"scopes,omitempty"`
}

type InputCreateSubuser added in v0.0.3

type InputCreateSubuser struct {
	Username string   `json:"username"`
	Email    string   `json:"email"`
	Password string   `json:"password"`
	Ips      []string `json:"ips"`
}

type InputGetSubusers added in v0.0.3

type InputGetSubusers struct {
	Username string
	Limit    int
	Offset   int
}

type InputInviteTeammate

type InputInviteTeammate struct {
	Email   string   `json:"email"`
	IsAdmin bool     `json:"is_admin"`
	Scopes  []string `json:"scopes"`
}

type InputUpdateAPIKeyName added in v0.0.2

type InputUpdateAPIKeyName struct {
	Name string `json:"name"`
}

type InputUpdateAPIKeyNameAndScopes added in v0.0.2

type InputUpdateAPIKeyNameAndScopes struct {
	Name   string   `json:"name"`
	Scopes []string `json:"scopes,omitempty"`
}

type InputUpdateSubuserStatus added in v0.0.3

type InputUpdateSubuserStatus struct {
	Disabled bool `json:"disabled"`
}

type InputUpdateTeammatePermissions

type InputUpdateTeammatePermissions struct {
	IsAdmin bool     `json:"is_admin"`
	Scopes  []string `json:"scopes"`
}

type Option

type Option func(*Client)

Option defines an option for a Client

type OutputCreateAPIKey added in v0.0.2

type OutputCreateAPIKey struct {
	ApiKey   string   `json:"api_key,omitempty"`
	ApiKeyId string   `json:"api_key_id,omitempty"`
	Name     string   `json:"name,omitempty"`
	Scopes   []string `json:"scopes,omitempty"`
}

type OutputCreateSubuser added in v0.0.3

type OutputCreateSubuser struct {
	UserID             int              `json:"user_id"`
	Username           string           `json:"username"`
	Email              string           `json:"email"`
	SignupSessionToken string           `json:"signup_session_token"`
	AuthorizationToken string           `json:"authorization_token"`
	Password           string           `json:"password"`
	CreditAllocation   CreditAllocation `json:"credit_allocation"`
}

type OutputGetAPIKey added in v0.0.2

type OutputGetAPIKey struct {
	ApiKeyId string   `json:"api_key_id,omitempty"`
	Name     string   `json:"name,omitempty"`
	Scopes   []string `json:"scopes,omitempty"`
}

type OutputGetAPIKeys added in v0.0.2

type OutputGetAPIKeys struct {
	APIKeys []APIKey `json:"result,omitempty"`
}

type OutputGetPendingTeammates

type OutputGetPendingTeammates struct {
	PendingTeammates []PendingTeammate `json:"result,omitempty"`
}

type OutputGetTeammate

type OutputGetTeammate struct {
	Username  string   `json:"username,omitempty"`
	FirstName string   `json:"first_name,omitempty"`
	LastName  string   `json:"last_name,omitempty"`
	Email     string   `json:"email,omitempty"`
	Scopes    []string `json:"scopes,omitempty"`
	UserType  string   `json:"user_type,omitempty"`
	IsAdmin   bool     `json:"is_admin,omitempty"`
	Phone     string   `json:"phone,omitempty"`
	Website   string   `json:"website,omitempty"`
	Address   string   `json:"address,omitempty"`
	Address2  string   `json:"address2,omitempty"`
	City      string   `json:"city,omitempty"`
	State     string   `json:"state,omitempty"`
	Zip       string   `json:"zip,omitempty"`
	Country   string   `json:"country,omitempty"`
}

type OutputGetTeammates

type OutputGetTeammates struct {
	Teammates []Teammate `json:"result,omitempty"`
}

type OutputInviteTeammate

type OutputInviteTeammate struct {
	Token   string   `json:"token,omitempty"`
	Email   string   `json:"email"`
	IsAdmin bool     `json:"is_admin"`
	Scopes  []string `json:"scopes"`
}

type OutputUpdateAPIKeyName added in v0.0.2

type OutputUpdateAPIKeyName struct {
	ApiKeyId string `json:"api_key_id,omitempty"`
	Name     string `json:"name,omitempty"`
}

type OutputUpdateAPIKeyNameAndScopes added in v0.0.2

type OutputUpdateAPIKeyNameAndScopes struct {
	ApiKeyId string   `json:"api_key_id,omitempty"`
	Name     string   `json:"name"`
	Scopes   []string `json:"scopes,omitempty"`
}

type OutputUpdateTeammatePermissions

type OutputUpdateTeammatePermissions struct {
	Username  string   `json:"username,omitempty"`
	FirstName string   `json:"first_name,omitempty"`
	LastName  string   `json:"last_name,omitempty"`
	Email     string   `json:"email,omitempty"`
	Scopes    []string `json:"scopes,omitempty"`
	UserType  string   `json:"user_type,omitempty"`
	IsAdmin   bool     `json:"is_admin,omitempty"`
	Phone     string   `json:"phone,omitempty"`
	Website   string   `json:"website,omitempty"`
	Address   string   `json:"address,omitempty"`
	Address2  string   `json:"address2,omitempty"`
	City      string   `json:"city,omitempty"`
	State     string   `json:"state,omitempty"`
	Zip       string   `json:"zip,omitempty"`
	Country   string   `json:"country,omitempty"`
}

type PendingTeammate

type PendingTeammate struct {
	Email          string   `json:"email,omitempty"`
	Scopes         []string `json:"scopes,omitempty"`
	IsAdmin        bool     `json:"is_admin,omitempty"`
	Token          string   `json:"token,omitempty"`
	ExpirationDate int      `json:"expiration_date,omitempty"`
}

type Reputation added in v0.0.3

type Reputation struct {
	Reputation float64 `json:"reputation,omitempty"`
	Username   string  `json:"username,omitempty"`
}

type Subuser added in v0.0.3

type Subuser struct {
	ID       int64  `json:"id,omitempty"`
	Disabled bool   `json:"disabled,omitempty"`
	Username string `json:"username,omitempty"`
	Email    string `json:"email,omitempty"`
}

type Teammate

type Teammate struct {
	Username  string `json:"username,omitempty"`
	Email     string `json:"email,omitempty"`
	FirstName string `json:"first_name,omitempty"`
	LastName  string `json:"last_name,omitempty"`
	UserType  string `json:"user_type,omitempty"`
	IsAdmin   bool   `json:"is_admin,omitempty"`
	Phone     string `json:"phone,omitempty"`
	Website   string `json:"website,omitempty"`
	Address   string `json:"address,omitempty"`
	Address2  string `json:"address2,omitempty"`
	City      string `json:"city,omitempty"`
	State     string `json:"state,omitempty"`
	Zip       string `json:"zip,omitempty"`
	Country   string `json:"country,omitempty"`
}

Directories

Path Synopsis
examples
create_api_key command
create_subuser command
delete_api_key command
delete_subuser command
delete_teammate command
get_api_key command
get_api_keys command
get_subusers command
get_teammate command
get_teammates command
invite_teammate command
update_subuser command

Jump to

Keyboard shortcuts

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