Documentation
¶
Overview ¶
Package manager is the babelforce manager SDK for Go.
It provides an intuitive, hand-written client over the babelforce manager APIs — auth, user & agent management, call reporting, metrics, and task automations. Configure one ManagerClient with Connect, authenticate once, and use its resource namespaces.
mgr, err := manager.Connect(ctx, manager.Options{
Environment: manager.Production,
Auth: manager.APIKey(accessID, accessToken),
})
for user, err := range mgr.Users.List(ctx, manager.ListUsersQuery{}) {
if err != nil { return err }
fmt.Println(user.Email)
}
The low-level clients under gen/ are generated from the OpenAPI specs and are an internal detail; this package is the public surface.
Index ¶
- type APIError
- type Auth
- type Environment
- type InterruptTarget
- type ListTasksQuery
- type ListUsersQuery
- type ManagerClient
- type Options
- type TaskSchedulesResource
- func (r *TaskSchedulesResource) Create(ctx context.Context, schedule taskscheduleapi.SubmitTaskSchedule) error
- func (r *TaskSchedulesResource) Delete(ctx context.Context, name string) error
- func (r *TaskSchedulesResource) Get(ctx context.Context, name string) (*taskscheduleapi.TaskSchedule, error)
- func (r *TaskSchedulesResource) List(ctx context.Context) (*taskscheduleapi.TaskScheduleList, error)
- type TasksResource
- func (r *TasksResource) Create(ctx context.Context, task taskautomationapi.SubmitTask) (*taskautomationapi.Task, error)
- func (r *TasksResource) CreateFromTemplate(ctx context.Context, template string, ...) (*taskautomationapi.Task, error)
- func (r *TasksResource) Get(ctx context.Context, taskID string) (*taskautomationapi.Task, error)
- func (r *TasksResource) Interrupt(ctx context.Context, taskID string, target InterruptTarget, ...) error
- func (r *TasksResource) List(ctx context.Context, q ListTasksQuery) iter.Seq2[taskautomationapi.Task, error]
- func (r *TasksResource) ListAll(ctx context.Context, q ListTasksQuery) ([]taskautomationapi.Task, error)
- func (r *TasksResource) Update(ctx context.Context, taskID string, task taskautomationapi.Task) (*taskautomationapi.Task, error)
- type TokenResponse
- type UsersResource
- func (r *UsersResource) Create(ctx context.Context, user managerapi.CreateManagedUserRequest) (*managerapi.ManagedUserItemResponse, error)
- func (r *UsersResource) Delete(ctx context.Context, emails []string) error
- func (r *UsersResource) Disable(ctx context.Context, emails []string) error
- func (r *UsersResource) Enable(ctx context.Context, emails []string) error
- func (r *UsersResource) List(ctx context.Context, q ListUsersQuery) iter.Seq2[managerapi.ManagedUser, error]
- func (r *UsersResource) ListAll(ctx context.Context, q ListUsersQuery) ([]managerapi.ManagedUser, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
// Status is the HTTP status code.
Status int
// Code is the API error code, when the body carries one.
Code string
// Message is a human-readable message (from the body when available, else the status text).
Message string
// Body is the raw response body.
Body []byte
}
APIError is returned when the manager API responds with a non-2xx status.
type Auth ¶
type Auth interface {
// contains filtered or unexported methods
}
Auth describes how the SDK authenticates. Construct one with APIKey, Bearer, or Password.
func APIKey ¶
APIKey authenticates with the X-Auth-Access-Id / X-Auth-Access-Token header pair (the primary server-to-server mode).
type Environment ¶
type Environment int
Environment selects a named babelforce host. Target other (e.g. per-customer or non-production) hosts with Options.BaseURL.
const ( // Production targets https://services.babelforce.com. Production Environment = iota )
type InterruptTarget ¶ added in v0.2.0
type InterruptTarget = taskautomationapi.InterruptionTargetStates
InterruptTarget is the state a manager-interrupt transitions a task to.
const ( InterruptCancel InterruptTarget = taskautomationapi.InterruptionTargetStatesCanceled InterruptComplete InterruptTarget = taskautomationapi.InterruptionTargetStatesCompleted InterruptFail InterruptTarget = taskautomationapi.InterruptionTargetStatesFailed )
type ListTasksQuery ¶ added in v0.2.0
type ListTasksQuery struct {
// Filter is a server-side filter expression.
Filter *string
// PageSize is the page size (1..100); defaults to 100.
PageSize int
}
ListTasksQuery filters a task listing.
type ListUsersQuery ¶
type ListUsersQuery struct {
// Email filters by email address.
Email *string
}
ListUsersQuery filters a user listing.
type ManagerClient ¶
type ManagerClient struct {
// Users is the user-management namespace (/api/v2/users).
Users *UsersResource
// Tasks is the task-automation namespace (/api/v3/tasks).
Tasks *TasksResource
}
ManagerClient is the babelforce manager SDK client. Create one with Connect.
type Options ¶
type Options struct {
// Environment selects a named host. Ignored when BaseURL is set. Defaults to Production.
Environment Environment
// BaseURL overrides the host explicitly (e.g. a per-customer URL).
BaseURL string
// Auth is how the client authenticates. Required.
Auth Auth
// HTTPClient is the underlying HTTP client. Defaults to http.DefaultClient.
HTTPClient *http.Client
}
Options configures a ManagerClient.
type TaskSchedulesResource ¶ added in v0.2.0
type TaskSchedulesResource struct {
// contains filtered or unexported fields
}
TaskSchedulesResource is the recurring task-schedule namespace (/api/v3/tasks/schedules).
func (*TaskSchedulesResource) Create ¶ added in v0.2.0
func (r *TaskSchedulesResource) Create(ctx context.Context, schedule taskscheduleapi.SubmitTaskSchedule) error
Create creates a task schedule.
func (*TaskSchedulesResource) Delete ¶ added in v0.2.0
func (r *TaskSchedulesResource) Delete(ctx context.Context, name string) error
Delete deletes a task schedule by name.
func (*TaskSchedulesResource) Get ¶ added in v0.2.0
func (r *TaskSchedulesResource) Get(ctx context.Context, name string) (*taskscheduleapi.TaskSchedule, error)
Get returns a task schedule by name.
func (*TaskSchedulesResource) List ¶ added in v0.2.0
func (r *TaskSchedulesResource) List(ctx context.Context) (*taskscheduleapi.TaskScheduleList, error)
List returns all task schedules.
type TasksResource ¶ added in v0.2.0
type TasksResource struct {
// Schedules is the recurring task-schedule namespace (/api/v3/tasks/schedules).
Schedules *TaskSchedulesResource
// contains filtered or unexported fields
}
TasksResource is the task-automation namespace (/api/v3/tasks).
func (*TasksResource) Create ¶ added in v0.2.0
func (r *TasksResource) Create(ctx context.Context, task taskautomationapi.SubmitTask) (*taskautomationapi.Task, error)
Create creates a task.
func (*TasksResource) CreateFromTemplate ¶ added in v0.2.0
func (r *TasksResource) CreateFromTemplate(ctx context.Context, template string, overrides taskautomationapi.TemplateOverride) (*taskautomationapi.Task, error)
CreateFromTemplate creates a task from a template, with overrides.
func (*TasksResource) Get ¶ added in v0.2.0
func (r *TasksResource) Get(ctx context.Context, taskID string) (*taskautomationapi.Task, error)
Get returns a task by id.
func (*TasksResource) Interrupt ¶ added in v0.2.0
func (r *TasksResource) Interrupt(ctx context.Context, taskID string, target InterruptTarget, action taskautomationapi.ManualActionRequest) error
Interrupt manager-interrupts a task, transitioning it to the given target state.
func (*TasksResource) List ¶ added in v0.2.0
func (r *TasksResource) List(ctx context.Context, q ListTasksQuery) iter.Seq2[taskautomationapi.Task, error]
List returns an iterator over tasks, auto-paginating across pages.
func (*TasksResource) ListAll ¶ added in v0.2.0
func (r *TasksResource) ListAll(ctx context.Context, q ListTasksQuery) ([]taskautomationapi.Task, error)
ListAll collects every task into a slice.
func (*TasksResource) Update ¶ added in v0.2.0
func (r *TasksResource) Update(ctx context.Context, taskID string, task taskautomationapi.Task) (*taskautomationapi.Task, error)
Update updates a task.
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
TokenType string `json:"token_type"`
}
TokenResponse is the OAuth2 token endpoint response.
func PasswordGrant ¶
func PasswordGrant(ctx context.Context, hc *http.Client, baseURL, user, pass, clientID string) (*TokenResponse, error)
PasswordGrant exchanges a username/password for a token via {baseURL}/oauth/token. Exposed for callers who want to manage tokens themselves.
type UsersResource ¶
type UsersResource struct {
// contains filtered or unexported fields
}
UsersResource is the user-management namespace (/api/v2/users).
func (*UsersResource) Create ¶
func (r *UsersResource) Create(ctx context.Context, user managerapi.CreateManagedUserRequest) (*managerapi.ManagedUserItemResponse, error)
Create creates a user.
func (*UsersResource) Delete ¶
func (r *UsersResource) Delete(ctx context.Context, emails []string) error
Delete deletes the given users (by email).
func (*UsersResource) Disable ¶
func (r *UsersResource) Disable(ctx context.Context, emails []string) error
Disable disables the given users (by email).
func (*UsersResource) Enable ¶
func (r *UsersResource) Enable(ctx context.Context, emails []string) error
Enable enables the given users (by email).
func (*UsersResource) List ¶
func (r *UsersResource) List(ctx context.Context, q ListUsersQuery) iter.Seq2[managerapi.ManagedUser, error]
List returns an iterator over users, auto-paginating across pages.
for user, err := range mgr.Users.List(ctx, manager.ListUsersQuery{}) {
if err != nil { return err }
fmt.Println(user.Email)
}
func (*UsersResource) ListAll ¶
func (r *UsersResource) ListAll(ctx context.Context, q ListUsersQuery) ([]managerapi.ManagedUser, error)
ListAll collects every user into a slice (convenience over List).
Directories
¶
| Path | Synopsis |
|---|---|
|
Command example lists users against a babelforce environment.
|
Command example lists users against a babelforce environment. |
|
gen
|
|
|
manager
Package manager provides primitives to interact with the openapi HTTP API.
|
Package manager provides primitives to interact with the openapi HTTP API. |
|
taskautomation
Package taskautomation provides primitives to interact with the openapi HTTP API.
|
Package taskautomation provides primitives to interact with the openapi HTTP API. |
|
taskschedule
Package taskschedule provides primitives to interact with the openapi HTTP API.
|
Package taskschedule provides primitives to interact with the openapi HTTP API. |
|
user
Package user provides primitives to interact with the openapi HTTP API.
|
Package user provides primitives to interact with the openapi HTTP API. |