airtable

package module
v0.0.0-...-649974b Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: 0BSD Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionMetadata

type ActionMetadata struct {
	Source         string `json:"source"`
	SourceMetadata struct {
		User WebhookUser `json:"user"`
	} `json:"sourceMetadata"`
}

ActionMetadata represents metadata about the webhook action.

type Client

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

func New

func New(apiKey string, opts ...Option) (*Client, error)

func (*Client) CreateWebhook

func (c *Client) CreateWebhook(baseId string, notificationUrl string, spec *WebhookSpecification) (*CreateWebhookResponse, error)

CreateWebhook creates a new webhook in Airtable.

func (*Client) DeleteWebhook

func (c *Client) DeleteWebhook(baseId, webhookId string) error

DeleteWebhook deletes an existing webhook in Airtable.

func (*Client) NewWebhookHandler

func (c *Client) NewWebhookHandler(macSecretBase64 string) (*WebhookHandler, error)

NewWebhookHandler creates a new WebhookHandler as a method of the Client type.

func (*Client) NewWebhookManager

func (c *Client) NewWebhookManager(ch chan InitialWebhookResponse) *WebhookManager

NewWebhookManager creates a new WebhookManager as a method of the Client type.

func (*Client) RefreshWebhook

func (c *Client) RefreshWebhook(baseId, webhookId string) (*RefreshWebhookResponse, error)

RefreshWebhook extends the life of a webhook. The new expiration time will be 7 days after the refresh time.

func (*Client) SetWebhookNotifications

func (c *Client) SetWebhookNotifications(baseId, webhookId string, enable bool) error

SetWebhookNotifications enables or disables notification pings for a webhook.

type CreateWebhookResponse

type CreateWebhookResponse struct {
	Id              string    `json:"id"`
	MacSecretBase64 string    `json:"macSecretBase64"`
	ExpirationTime  time.Time `json:"expirationTime"`
}

CreateWebhookResponse defines the expected structure of the response from the Airtable API.

type Email

type Email string

type InitialWebhookResponse

type InitialWebhookResponse struct {
	Base struct {
		Id string `json:"id"`
	} `json:"base"`
	Webhook struct {
		Id string `json:"id"`
	} `json:"webhook"`
	Timestamp time.Time `json:"timestamp"`
}

InitialWebhookResponse represents the structure of the initial payload received by the webhook.

type InitialWebhookResponseHandler

type InitialWebhookResponseHandler struct {
	C chan InitialWebhookResponse
	// contains filtered or unexported fields
}

InitialWebhookResponseHandler is a struct that holds a channel for InitialWebhookResponse payloads.

func NewInitialWebhookResponseHandler

func NewInitialWebhookResponseHandler(macSecretBase64 string) (*InitialWebhookResponseHandler, error)

NewInitialWebhookResponseHandler creates a new InitialWebhookResponseHandler with a channel for InitialWebhookPayloads.

func (*InitialWebhookResponseHandler) ServeHTTP

type LongText

type LongText string

type Number

type Number float64

type Option

type Option func(option *options) error

func WithHost

func WithHost(host string) Option

func WithHttpClient

func WithHttpClient(hc http.Client) Option

func WithRateLimit

func WithRateLimit(rl ratelimit.Limiter) Option

type Page

type Page[T any] struct {
	Records []Record[T] `json:"records"`
	Offset  string      `json:"offset"`
}

type Phone

type Phone string

type Record

type Record[T any] struct {
	ID          string     `json:"id,omitempty"`
	CreatedTime *time.Time `json:"createdTime,omitempty"`
	Fields      *T         `json:"fields"`
}

type RefreshWebhookResponse

type RefreshWebhookResponse struct {
	ExpirationTime time.Time `json:"expirationTime"`
}

RefreshWebhookResponse defines the expected structure of the response from refreshing a webhook.

type Relation

type Relation []string

type ShortText

type ShortText string

type SingleSelect

type SingleSelect string

type Table

type Table[T any] struct {
	// contains filtered or unexported fields
}

func NewTable

func NewTable[T any](c *Client, baseId, tableId string) *Table[T]

func (*Table[T]) Create

func (l *Table[T]) Create(items []T) ([]Record[T], error)

func (*Table[T]) Delete

func (l *Table[T]) Delete(recordId string) error

func (*Table[T]) List

func (l *Table[T]) List() ([]Record[T], error)

func (*Table[T]) Retrieve

func (l *Table[T]) Retrieve(recordId string) (*Record[T], error)

func (*Table[T]) Update

func (l *Table[T]) Update(records []Record[T]) ([]Record[T], error)

type URL

type URL string

type User

type User struct {
	Id    string `json:"id,omitempty"`
	Email string `json:"email,omitempty"`
	Name  string `json:"name,omitempty"`
}

type WebhookHandler

type WebhookHandler struct {
	C chan WebhookPayload
	// contains filtered or unexported fields
}

WebhookHandler encapsulates InitialWebhookResponseHandler and WebhookManager.

func (*WebhookHandler) Run

func (h *WebhookHandler) Run() error

Run starts the process of listening for and fetching webhook payloads.

func (*WebhookHandler) ServeHTTP

func (h *WebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

type WebhookManager

type WebhookManager struct {
	C chan WebhookPayload
	// contains filtered or unexported fields
}

WebhookManager is responsible for handling the entire webhook process.

func (*WebhookManager) FetchWebhookPayloads

func (h *WebhookManager) FetchWebhookPayloads(baseId, webhookId string) error

FetchWebhookPayloads fetches the detailed WebhookPayloads from Airtable.

func (*WebhookManager) Run

func (h *WebhookManager) Run() error

Run starts listening on the InitialResponseChan for incoming initial webhook responses.

type WebhookPayload

type WebhookPayload struct {
	Timestamp             time.Time      `json:"timestamp"`
	BaseTransactionNumber int            `json:"baseTransactionNumber"`
	ActionMetadata        ActionMetadata `json:"actionMetadata"`
	PayloadFormat         string         `json:"payloadFormat"`
	ChangedTablesById     any            `json:"changedTablesById,omitempty"`
	CreatedTablesById     any            `json:"createdTablesById,omitempty"`
	DestroyedTableIds     []string       `json:"destroyedTableIds,omitempty"`
	Error                 bool           `json:"error,omitempty"`
	Code                  string         `json:"code,omitempty"`
}

WebhookPayload represents the common structure of a webhook payload.

type WebhookResponse

type WebhookResponse struct {
	Payloads      []WebhookPayload `json:"payloads"`
	Cursor        int              `json:"cursor"`
	MightHaveMore bool             `json:"mightHaveMore"`
}

WebhookResponse represents the response containing one or more payloads.

type WebhookSpecification

type WebhookSpecification struct {
	Options struct {
		Filters filters `json:"filters"`
	} `json:"options"`
}

WebhookSpecification defines the structure for the webhook creation request.

func NewWebhookSpecification

func NewWebhookSpecification() *WebhookSpecification

func (*WebhookSpecification) AddChangeType

func (w *WebhookSpecification) AddChangeType(changeType string) *WebhookSpecification

AddChangeType adds a changeType to the list.

func (*WebhookSpecification) AddDataType

func (w *WebhookSpecification) AddDataType(dataType string) *WebhookSpecification

AddDataType adds a dataType to the list.

func (*WebhookSpecification) AddFromSource

func (w *WebhookSpecification) AddFromSource(source string) *WebhookSpecification

AddFromSource adds a fromSource to the list.

func (*WebhookSpecification) AddWatchDataInField

func (w *WebhookSpecification) AddWatchDataInField(fieldId string) *WebhookSpecification

AddWatchDataInField adds a field Id to watch data in.

func (*WebhookSpecification) AddWatchSchemaOfField

func (w *WebhookSpecification) AddWatchSchemaOfField(fieldId string) *WebhookSpecification

AddWatchSchemaOfField adds a field Id to watch schema changes in.

func (*WebhookSpecification) SetRecordChangeScope

func (w *WebhookSpecification) SetRecordChangeScope(scope string) *WebhookSpecification

SetRecordChangeScope sets the recordChangeScope.

type WebhookUser

type WebhookUser struct {
	Id              string `json:"id"`
	Email           string `json:"email"`
	PermissionLevel string `json:"permissionLevel"`
}

WebhookUser represents a user associated with a webhook action.

Jump to

Keyboard shortcuts

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