airtable

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 6 Imported by: 0

README

Very simple pure Go Airtable API wrapper

GoDoc Go [Go Report Card] codecov

Installation

    go get github.com/Squirrel-Entreprise/airtable

Aitable API

Airtable uses simple token-based authentication. To generate or manage your API key, visit your account page.

Usage

    package main

    import (
        "fmt"
        "github.com/Squirrel-Entreprise/airtable"
    )

    func main() {
        
        a := airtable.New("api_key_xxx", "id_base_yyy")

        productTable := airtable.Table{
            Name:       "Products", // Name of the table
            MaxRecords: "100", // Max records to return
            View:       "Grid view", // View name
        }

        type productItemAirtable struct {
            ID          string    `json:"id"`
            CreatedTime time.Time `json:"createdTime"`
            Fields      struct {
                Name     string                `json:"Name"`
                Cover    []airtable.Attachment `json:"cover"`
                Category string                `json:"Category"`
                Price    float64               `json:"Price"`
                Carts    []string              `json:"Carts"`
            } `json:"fields"`
        }

        // List products
        type productsListAirtable struct {
            Records []productItemAirtable `json:"records"`
            Offset  string                `json:"offset"`
        }

        products := productsListAirtable{}

        if err := a.List(productTable, &products); err != nil {
            fmt.Println(err)
        }

        for _, p := range products.Records {
            fmt.Println(p.ID, p.Fields.Name, p.Fields.Price)
        }
    }

More examples can be found in EXAMPLE.md.

Documentation

Index

Constants

View Source
const (
	GET    methodHttp = http.MethodGet
	POST   methodHttp = http.MethodPost
	PUT    methodHttp = http.MethodPut
	PATCH  methodHttp = http.MethodPatch
	DELETE methodHttp = http.MethodDelete
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Airtable

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

func New

func New(apiKey, base string) *Airtable

func (*Airtable) Create

func (a *Airtable) Create(table Table, data []byte, response interface{}) error

func (*Airtable) Delete

func (a *Airtable) Delete(table Table, id string) error

func (*Airtable) Get

func (a *Airtable) Get(table Table, id string, response interface{}) error

func (*Airtable) List

func (a *Airtable) List(table Table, response interface{}) error

func (*Airtable) Update

func (a *Airtable) Update(table Table, id string, data []byte, response interface{}) error

type Attachment

type Attachment struct {
	ID         string `json:"id"`
	Width      int    `json:"width"`
	Height     int    `json:"height"`
	URL        string `json:"url"`
	Filename   string `json:"filename"`
	Size       int    `json:"size"`
	Type       string `json:"type"`
	Thumbnails struct {
		Small struct {
			URL    string `json:"url"`
			Width  int    `json:"width"`
			Height int    `json:"height"`
		} `json:"small"`
		Large struct {
			URL    string `json:"url"`
			Width  int    `json:"width"`
			Height int    `json:"height"`
		} `json:"large"`
		Full struct {
			URL    string `json:"url"`
			Width  int    `json:"width"`
			Height int    `json:"height"`
		} `json:"full"`
	} `json:"thumbnails"`
}

Attachment object may contain the following properties

type HTTPClient added in v0.1.3

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}
var (
	Client HTTPClient
)

type Table

type Table struct {
	Name       string `json:"name"`       // table name
	MaxRecords string `json:"maxRecords"` // max 100
	View       string `json:"view"`       // Grid view
}

Jump to

Keyboard shortcuts

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