manager

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

README

manager-sdk-go

Go SDK for the babelforce manager APIs — auth, user & agent management, call reporting, metrics, and task automations.

One client, configured once, exposes resource namespaces over the API. Authentication, paging, and error handling are handled for you.

📖 Docs: https://babelforce.github.io/manager-sdk/

Install

go get github.com/babelforce/manager-sdk-go
import manager "github.com/babelforce/manager-sdk-go"

Usage

mgr, err := manager.Connect(ctx, manager.Options{
    Environment: manager.Production,
    Auth:        manager.APIKey(accessID, accessToken), // or manager.Password(user, pass)
})
if err != nil {
    log.Fatal(err)
}

// list users (auto-paginated)
for user, err := range mgr.Users.List(ctx, manager.ListUsersQuery{}) {
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(user.Email)
}

_, err = mgr.Users.Create(ctx, manager.CreateManagedUserRequest{Email: "new.user@acme.com"})
Authentication
  • manager.APIKey(id, token) — sends X-Auth-Access-Id / X-Auth-Access-Token.
  • manager.Bearer(token) — a token you already hold.
  • manager.Password(user, pass) — OAuth2 password grant with transparent refresh.
Errors

Non-2xx responses return a typed *manager.APIError (Status, Code, Message, Body).

Custom host
manager.Connect(ctx, manager.Options{
    BaseURL: "https://acme.babelforce.com",
    Auth:    manager.Bearer(token),
})

License

Apache-2.0

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

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.

func (*APIError) Error

func (e *APIError) Error() string

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

func APIKey(accessID, accessToken string) Auth

APIKey authenticates with the X-Auth-Access-Id / X-Auth-Access-Token header pair (the primary server-to-server mode).

func Bearer

func Bearer(token string) Auth

Bearer authenticates with a bearer token you already hold.

func Password

func Password(user, pass string) Auth

Password authenticates via the OAuth2 password grant against /oauth/token. The token is fetched lazily on first use and refreshed transparently before it expires. Convenience for interactive/dev use.

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

InterruptTarget is the state a manager-interrupt transitions a task to.

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.

func Connect

func Connect(_ context.Context, opts Options) (*ManagerClient, error)

Connect creates and configures a client.

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

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

Get returns a task schedule by name.

func (*TaskSchedulesResource) List added in v0.2.0

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

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

Get returns a task by id.

func (*TasksResource) Interrupt added in v0.2.0

Interrupt manager-interrupts a task, transitioning it to the given target state.

func (*TasksResource) List added in v0.2.0

List returns an iterator over tasks, auto-paginating across pages.

func (*TasksResource) ListAll added in v0.2.0

ListAll collects every task into a slice.

func (*TasksResource) Update added in v0.2.0

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

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

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

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.

Jump to

Keyboard shortcuts

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