addyrest

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: MIT Imports: 9 Imported by: 0

README

addyrest

Addy RESTful API client library.

builds.sr.ht status Go Reference

INSTALL

Enter your project folder, and issue go get:

go get git.sr.ht/~kovmir/addyrest

USAGE

Go to your account settings to issue a new token, and then:

package main

import (
	"fmt"

	"git.sr.ht/~kovmir/addyrest"
)

func main() {
	c := addyrest.NewClient("YOUR_TOKEN")

	// Get token name.
	details, err := c.TokenGetAPIDetails()
	if err != nil {
		panic(err)
	}
	fmt.Printf("Token name: %s\n", details.Name)

	// Get first 5 active aliases.
	aliases, err := c.AliasesGet(&addyrest.AliasesGetArgs{
		Filter:   map[string]string{"active": "true"},
		PageSize: 5,
	})
	if err != nil {
		panic(err)
	}
	for i, v := range aliases.Data {
		fmt.Printf("%d. %s\n", i, v.Email)
	}

	// Create a new UUID alias.
	alias, err := c.AliasNew(&addyrest.AliasNewArgs{
		Desc:   "addy client test",
		Domain: "mailer.me",
		Format: addyrest.AliasFmtUUID,
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("alias %s created successfully\n", alias.Data.ID)
}

DOCUMENTATION

The entire codebase resides within client.go, the rest of the files define methods and JSONs from Addy API reference. Each method is more or less self-descriptive and has a URL pointing to the upstream reference.

Documentation

Index

Constants

View Source
const (
	AliasSortLocalPart  AliasSortCond = "local_part"
	AliasSortDomain     AliasSortCond = "domain"
	AliasSortEmail      AliasSortCond = "email"
	AliasSortEmailsFwd  AliasSortCond = "emails_forwarded"
	AliasSortEmailsBlkd AliasSortCond = "emails_blocked"
	AliasSortEmailsRepl AliasSortCond = "emails_replied"
	AliasSortEmailsSent AliasSortCond = "emails_sent"
	AliasSortActive     AliasSortCond = "active"
	AliasSortCreatedAt  AliasSortCond = "created_at"
	AliasSortUpdatedAt  AliasSortCond = "updated_at"
	AliasSortDeletedAt  AliasSortCond = "deleted_at"

	AliasFmtRndChars AliasFormat = "random_characters"
	AliasFmtUUID     AliasFormat = "uuid"
	AliasFmtRndWords AliasFormat = "random_words"
	AliasFmtCustom   AliasFormat = "custom"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountDetails

type AccountDetails struct {
	ID                           string    `json:"id"`
	Username                     string    `json:"username"`
	FromName                     string    `json:"from_name"`
	EmailSubject                 string    `json:"email_subject"`
	BannerLocation               string    `json:"banner_location"`
	Bandwidth                    uint      `json:"bandwidth"`
	UsernameCount                uint      `json:"username_count"`
	UsernameLimit                uint      `json:"username_limit"`
	DefaultRecipientID           string    `json:"default_recipient_id"`
	DefaultAliasDomain           string    `json:"default_alias_domain"`
	DefaultAliasFormat           string    `json:"default_alias_format"`
	Subscription                 string    `json:"subscription"`
	SubscriptionEndsAt           *UnixTime `json:"subscription_ends_at"`
	BandwidthLimit               uint      `json:"bandwidth_limit"`
	RecipientCount               uint      `json:"recipient_count"`
	RecipientLimit               uint      `json:"recipient_limit"`
	ActiveDomainCount            uint      `json:"active_domain_count"`
	ActiveDomainLimit            uint      `json:"active_domain_limit"`
	ActiveSharedDomainAliasCount uint      `json:"active_shared_domain_alias_count"`
	ActiveSharedDomainAliasLimit uint      `json:"active_shared_domain_alias_limit"`
	TotalEmailsForwarded         uint      `json:"total_emails_forwarded"`
	TotalEmailsBlocked           uint      `json:"total_emails_blocked"`
	TotalEmailsReplied           uint      `json:"total_emails_replied"`
	TotalEmailsSent              uint      `json:"total_emails_sent"`
	CreatedAt                    UnixTime  `json:"created_at"`
	UpdatedAt                    *UnixTime `json:"updated_at"`
}

type AccountDetailsWrap

type AccountDetailsWrap struct {
	Data AccountDetails `json:"data"`
}

type Action

type Action struct {
	Type  string `json:"action"`
	Value string `json:"value"`
}

type Actions

type Actions struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

type AddyOperator

type AddyOperator string
const (
	AddyANDCond AddyOperator = "AND"
	AddyORCond  AddyOperator = "OR"
)

type Alias

type Alias struct {
	ID              string      `json:"id"`
	UserID          string      `json:"user_id"`
	AliasableID     string      `json:"aliasable_id"`
	AliasableType   string      `json:"aliasable_type"`
	LocalPart       string      `json:"local_part"`
	Extension       string      `json:"extension"`
	Domain          string      `json:"domain"`
	Email           string      `json:"email"`
	Active          bool        `json:"active"`
	Description     string      `json:"description"`
	EmailsForwarded uint        `json:"emails_forwarded"`
	EmailsBlocked   uint        `json:"emails_blocked"`
	EmailsReplied   uint        `json:"emails_replied"`
	EmailsSent      uint        `json:"emails_sent"`
	Recipients      []Recipient `json:"recipients"`
	CreatedAt       UnixTime    `json:"created_at"`
	UpdatedAt       *UnixTime   `json:"updated_at"`
	DeletedAt       *UnixTime   `json:"deleted_at"`
}

type AliasFormat

type AliasFormat string

type AliasNewArgs

type AliasNewArgs struct {
	// The domain of the alias.
	Domain string `json:"domain"`
	// The description of the alias
	Desc string `json:"description,omitempty"`
	// The chosen format for the alias.
	Format AliasFormat `json:"format,omitempty"`
	// The chosen local part for the alias (only required if you have the
	// format as custom)
	LocalPart string `json:"local_part,omitempty"`
	// An array of recipient ids to add (the default recipient will be used
	// if none provided)
	Recipients []string `json:"recipient_ids,omitempty"`
}

type AliasRecipientArgs

type AliasRecipientArgs struct {
	AliasID      string   `json:"alias_id"`
	RecipientIDs []string `json:"recipient_ids"`
}

type AliasSortCond

type AliasSortCond string

type AliasUpdateArgs

type AliasUpdateArgs struct {
	Desc     string `json:"description,omitempty"`
	FromName string `json:"from_name,omitempty"`
}

type AliasWrap

type AliasWrap struct {
	Data Alias `json:"data"`
}

type AliasesGetArgs

type AliasesGetArgs struct {
	// Include deleted or only deleted:
	// Filter[deleted] = with | only
	//
	// Choose to return active or unactive aliases:
	// Filter[active] = true | false
	//
	// Search aliases by email and description.
	// Filter[search] = <search_string>
	Filter map[string]string
	// Paginate the alias results, default 100, min 1 max 100.
	PageSize uint
	// Paginate the alias results; what page number do you want?
	PageNumber uint
	// Sort aliases based on this given condition.
	SortCond AliasSortCond
	// Descending sort?
	SortDesc bool
	// Return aliases with recipients?
	WithRecipients bool
	// Return aliases using the recipient with the specified ID.
	Recipient string
	// Return aliases using the custom domain with the specified ID.
	Domain string
	// Return aliases using the username with the specified ID.
	Username string
}
type AliasesLinks struct {
	First string `json:"first"`
	Last  string `json:"last"`
	Prev  string `json:"prev"`
	Next  string `json:"next"`
}

type AliasesMeta

type AliasesMeta struct {
	CurrentPage int                `json:"current_page"`
	From        int                `json:"from"`
	LastPage    int                `json:"last_page"`
	Links       []AliasesMetaLinks `json:"links"`
	Path        string             `json:"path"`
	PerPage     int                `json:"per_page"`
	To          int                `json:"to"`
	Total       int                `json:"total"`
}
type AliasesMetaLinks struct {
	URL    any    `json:"url"`
	Label  string `json:"label"`
	Active bool   `json:"active"`
}

type AliasesWrap

type AliasesWrap struct {
	Data  []Alias      `json:"data"`
	Links AliasesLinks `json:"links"`
	Meta  AliasesMeta  `json:"meta"`
}

type AppVersion

type AppVersion struct {
	Version string `json:"version"`
	Major   int    `json:"major"`
	Minor   int    `json:"minor"`
	Patch   int    `json:"patch"`
}

type Bulk

type Bulk struct {
	Message string   `json:"message"`
	IDs     []string `json:"ids"`
}

type BulkWrap

type BulkWrap struct {
	Data Bulk `json:"data"`
}

Responce from bulk actions.

type Client

type Client struct {
	BaseURL string
	Token   string
	Ctx     context.Context
}

func NewClient

func NewClient(token string) *Client

Initialize a new default API client, only provide the token.

func NewCustomClient

func NewCustomClient(ctx context.Context, url, token string) *Client

Initialize a new API client.

func (*Client) AppGetVersion

func (c *Client) AppGetVersion() (*AppVersion, error)

func (*Client) BulkAliasesUpdRecipients

func (c *Client) BulkAliasesUpdRecipients(aliasIDs, recipientIDs []string) (*BulkWrap, error)

https://app.addy.io/docs/#alias-bulk-actions-POSTapi-v1-aliases-recipients-bulk

func (*Client) DomainGetOpts

func (c *Client) DomainGetOpts() (*DomainOptions, error)

type Condition

type Condition struct {
	Type   string   `json:"type"`
	Match  string   `json:"match,omitempty"`
	Values []string `json:"values"`
}

type Conditions

type Conditions struct {
	Type   string   `json:"type"`
	Match  string   `json:"match"`
	Values []string `json:"values"`
}

type Domain

type Domain struct {
	ID                      string    `json:"id"`
	UserID                  string    `json:"user_id"`
	Domain                  string    `json:"domain"`
	Description             string    `json:"description"`
	Aliases                 []Alias   `json:"aliases"`
	DefaultRecipient        Recipient `json:"default_recipient"`
	Active                  bool      `json:"active"`
	CatchAll                bool      `json:"catch_all"`
	DomainVerifiedAt        *UnixTime `json:"domain_verified_at"`
	DomainMxValidatedAt     *UnixTime `json:"domain_mx_validated_at"`
	DomainSendingVerifiedAt *UnixTime `json:"domain_sending_verified_at"`
	CreatedAt               UnixTime  `json:"created_at"`
	UpdatedAt               *UnixTime `json:"updated_at"`
}

type DomainOptions

type DomainOptions struct {
	Data               []string `json:"data"`
	DefaultAliasDomain string   `json:"defaultAliasDomain"`
	DefaultAliasFormat string   `json:"defaultAliasFormat"`
}

type DomainUpdateArgs

type DomainUpdateArgs struct {
	Desc     string `json:"description,omitempty"`
	FromName string `json:"from_name,omitempty"`
}

type DomainWrap

type DomainWrap struct {
	Data Domain `json:"data"`
}

type DomainsWrap

type DomainsWrap struct {
	Data []Domain `json:"data"`
}

type FailedDeliveriesWrap

type FailedDeliveriesWrap struct {
	Data []FailedDelivery `json:"data"`
}

type FailedDelivery

type FailedDelivery struct {
	ID             string    `json:"id"`
	UserID         string    `json:"user_id"`
	RecipientID    string    `json:"recipient_id"`
	RecipientEmail string    `json:"recipient_email"`
	AliasID        string    `json:"alias_id"`
	AliasEmail     string    `json:"alias_email"`
	BounceType     string    `json:"bounce_type"`
	RemoteMta      string    `json:"remote_mta"`
	Sender         string    `json:"sender"`
	EmailType      string    `json:"email_type"`
	Status         string    `json:"status"`
	Code           string    `json:"code"`
	AttemptedAt    UnixTime  `json:"attempted_at"`
	CreatedAt      *UnixTime `json:"created_at"`
	UpdatedAt      *UnixTime `json:"updated_at"`
}

type FailedDeliveryWrap

type FailedDeliveryWrap struct {
	Data FailedDelivery `json:"data"`
}

type IDGeneric

type IDGeneric struct {
	ID string `json:"id"`
}

Multiple methods require either ID or an array of IDs as arguments.

type IDsGeneric

type IDsGeneric struct {
	IDs []string `json:"ids"`
}

type Recipient

type Recipient struct {
	ID               string    `json:"id"`
	UserID           string    `json:"user_id"`
	Email            string    `json:"email"`
	CanReplySend     bool      `json:"can_reply_send"`
	ShouldEncrypt    bool      `json:"should_encrypt"`
	InlineEncryption bool      `json:"inline_encryption"`
	ProtectedHeaders bool      `json:"protected_headers"`
	Fingerprint      string    `json:"fingerprint"`
	EmailVerifiedAt  *UnixTime `json:"email_verified_at"`
	Aliases          []Alias   `json:"aliases"`
	CreatedAt        UnixTime  `json:"created_at"`
	UpdatedAt        *UnixTime `json:"updated_at"`
}

type RecipientWrap

type RecipientWrap struct {
	Data Recipient `json:"data"`
}

type RecipientsGetArgs

type RecipientsGetArgs struct {
	Filter map[string]string
}

type RecipientsWrap

type RecipientsWrap struct {
	Data []Recipient `json:"data"`
}

type Rule

type Rule struct {
	ID         string       `json:"id"`
	UserID     string       `json:"user_id"`
	Name       string       `json:"name"`
	Order      int          `json:"order"`
	Conditions []Conditions `json:"conditions"`
	Actions    []Actions    `json:"actions"`
	Operator   string       `json:"operator"`
	Forwards   bool         `json:"forwards"`
	Replies    bool         `json:"replies"`
	Sends      bool         `json:"sends"`
	Active     bool         `json:"active"`
	CreatedAt  UnixTime     `json:"created_at"`
	UpdatedAt  *UnixTime    `json:"updated_at"`
}

type RuleNewParams

type RuleNewParams struct {
	Name       string      `json:"name"`
	Conditions []Condition `json:"conditions"`
	Actions    []Action    `json:"actions"`
	Operator   string      `json:"operator,omitempty"`
	Forwards   bool        `json:"forwards,omitempty"`
	Replies    bool        `json:"replies,omitempty"`
	Sends      bool        `json:"sends,omitempty"`
}

type RuleUpdateArgs

type RuleUpdateArgs struct {
	Name       string       `json:"name"`
	Conditions []Condition  `json:"conditions"`
	Actions    []Action     `json:"actions"`
	Operator   AddyOperator `json:"operator,omitempty"`
	Forwards   bool         `json:"forwards,omitempty"`
	Replies    bool         `json:"replies,omitempty"`
	Sends      bool         `json:"sends,omitempty"`
}

type RuleWrap

type RuleWrap struct {
	Data Rule `json:"data"`
}

type RulesWrap

type RulesWrap struct {
	Data []Rule `json:"data"`
}

type TokenAPIDetails

type TokenAPIDetails struct {
	Name      string    `json:"name"`
	CreatedAt UnixTime  `json:"created_at"`
	ExpiresAt *UnixTime `json:"expires_at"`
}

type UnixTime

type UnixTime struct {
	time.Time
}

Time format returned by Addy.

func (*UnixTime) UnmarshalJSON

func (ut *UnixTime) UnmarshalJSON(b []byte) error

type User

type User struct {
	ID               string    `json:"id"`
	UserID           string    `json:"user_id"`
	Username         string    `json:"username"`
	Description      string    `json:"description"`
	Aliases          []Alias   `json:"aliases"`
	DefaultRecipient string    `json:"default_recipient"`
	Active           bool      `json:"active"`
	CatchAll         bool      `json:"catch_all"`
	CanLogin         bool      `json:"can_login"`
	CreatedAt        UnixTime  `json:"created_at"`
	UpdatedAt        *UnixTime `json:"updated_at"`
}

type UserUpdateArgs

type UserUpdateArgs struct {
	Desc     string `json:"description,omitempty"`
	FromName string `json:"from_name,omitempty"`
}

type UserWrap

type UserWrap struct {
	Data User `json:"data"`
}

type UsersWrap

type UsersWrap struct {
	Data []User `json:"data"`
}

Jump to

Keyboard shortcuts

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