2023-01-01 15:18:29 +01:00
|
|
|
package airtable
|
|
|
|
|
|
|
|
|
|
import (
|
2023-01-12 12:54:18 +05:00
|
|
|
"context"
|
2024-06-22 21:46:58 -07:00
|
|
|
"fmt"
|
2023-01-01 15:18:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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"`
|
2023-01-01 15:18:29 +01:00
|
|
|
|
2024-06-22 21:46:58 -07:00
|
|
|
c *Client
|
2023-01-01 15:18:29 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
})
|
2023-01-12 12:54:18 +05:00
|
|
|
}
|
|
|
|
|
|
2024-06-22 21:46:58 -07:00
|
|
|
func (c *Client) GetBaseByName(ctx context.Context, name string) (*Base, error) {
|
|
|
|
|
bases, err := c.ListBases(ctx)
|
2023-01-01 15:18:29 +01:00
|
|
|
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
|
|
|
|
|
}
|
2023-01-01 15:18:29 +01:00
|
|
|
}
|
2023-01-12 12:54:18 +05:00
|
|
|
|
2024-06-22 21:46:58 -07:00
|
|
|
return nil, fmt.Errorf("base '%s' not found", name)
|
2023-01-12 12:54:18 +05:00
|
|
|
}
|
|
|
|
|
|
2024-06-22 21:46:58 -07:00
|
|
|
func (b Base) String() string {
|
2024-06-23 16:32:28 -07:00
|
|
|
return *b.Name
|
2023-01-01 15:18:29 +01:00
|
|
|
}
|