Files
airtable/base.go

41 lines
758 B
Go
Raw Permalink Normal View History

package airtable
import (
"context"
2024-06-22 21:46:58 -07:00
"fmt"
)
type Base struct {
2024-06-23 16:32:28 -07:00
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
PermissionLevel *string `json:"permissionLevel,omitempty"`
2024-06-22 21:46:58 -07:00
c *Client
}
2024-06-22 21:46:58 -07:00
func (c *Client) ListBases(ctx context.Context) ([]*Base, error) {
return listAll[Base](ctx, c, "meta/bases", nil, "bases", func(b *Base) error {
b.c = c
return nil
})
}
2024-06-22 21:46:58 -07:00
func (c *Client) GetBaseByName(ctx context.Context, name string) (*Base, error) {
bases, err := c.ListBases(ctx)
if err != nil {
return nil, err
}
2024-06-22 21:46:58 -07:00
for _, base := range bases {
2024-06-23 16:32:28 -07:00
if *base.Name == name {
2024-06-22 21:46:58 -07:00
return base, nil
}
}
2024-06-22 21:46:58 -07:00
return nil, fmt.Errorf("base '%s' not found", name)
}
2024-06-22 21:46:58 -07:00
func (b Base) String() string {
2024-06-23 16:32:28 -07:00
return *b.Name
}