Documentation
¶
Index ¶
- func IsAuthError(err error) bool
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsGone(err error) bool
- func IsLocked(err error) bool
- func IsNotFound(err error) bool
- func IsPreconditionRequired(err error) bool
- func IsRateLimited(err error) bool
- func IsServerError(err error) bool
- func NewAPIError(resp *http.Response, body []byte) error
- func ParseResponse(resp *http.Response, v interface{}) error
- type APIError
- type AuthError
- type Client
- func (c *Client) GetAccessToken() string
- func (c *Client) GetHTTPClient() *http.Client
- func (c *Client) GetLogger() Logger
- func (c *Client) GetPlugin(name string) (Plugin, bool)
- func (c *Client) PageFromCursor(cursorURL string) (*Page, error)
- func (c *Client) RegisterPlugin(plugin Plugin)
- func (c *Client) Request(method, path string, params url.Values, body interface{}) (*http.Response, error)
- func (c *Client) RequestMultipart(path string, fields []MultipartField, files []MultipartFile) (*http.Response, error)
- func (c *Client) RequestMultipartWithRetry(ctx context.Context, path string, fields []MultipartField, ...) (*http.Response, error)
- func (c *Client) RequestURL(method, fullURL string, body interface{}) (*http.Response, error)
- func (c *Client) RequestURLWithRetry(ctx context.Context, method, fullURL string, body interface{}) (*http.Response, error)
- func (c *Client) RequestWithContext(ctx context.Context, method, path string, params url.Values, body interface{}) (*http.Response, error)
- func (c *Client) RequestWithRetry(ctx context.Context, method, path string, params url.Values, body interface{}) (*http.Response, error)
- type Config
- type ConflictError
- type FieldError
- type ForbiddenError
- type GoneError
- type LockedError
- type Logger
- type MultipartField
- type MultipartFile
- type NotFoundError
- type Page
- type Plugin
- type PreconditionRequiredError
- type RateLimitError
- type Resource
- type ResourceErrors
- type ServerError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAuthError ¶ added in v2.0.14
IsAuthError reports whether err is an authentication error (HTTP 401).
func IsConflict ¶ added in v2.0.14
IsConflict reports whether err is a conflict error (HTTP 409).
func IsForbidden ¶ added in v2.0.14
IsForbidden reports whether err is a forbidden error (HTTP 403).
func IsNotFound ¶ added in v2.0.14
IsNotFound reports whether err is a not found error (HTTP 404).
func IsPreconditionRequired ¶ added in v2.0.14
IsPreconditionRequired reports whether err is a precondition required error (HTTP 428).
func IsRateLimited ¶ added in v2.0.14
IsRateLimited reports whether err is a rate limit error (HTTP 429).
func IsServerError ¶ added in v2.0.14
IsServerError reports whether err is a server error (HTTP 5xx).
func NewAPIError ¶ added in v2.0.14
NewAPIError creates a structured error from an HTTP response and its body. It parses the JSON body for message and trackingId fields, reads the Retry-After header, and returns the appropriate error sub-type based on the HTTP status code.
func ParseResponse ¶
ParseResponse parses an HTTP response into the given interface
Types ¶
type APIError ¶ added in v2.0.14
type APIError struct {
// StatusCode is the HTTP status code from the response.
StatusCode int
// Status is the HTTP status line (e.g., "404 Not Found").
Status string
// Message is the error message from the Webex API response body.
Message string
// TrackingID is the Webex tracking identifier for support debugging.
TrackingID string
// RetryAfter is the duration to wait before retrying, parsed from
// the Retry-After header. Zero if not applicable.
RetryAfter time.Duration
// RawBody is the raw response body bytes, preserved for debugging.
RawBody []byte
// Err is an optional wrapped error for errors.Unwrap support.
Err error
}
APIError is the base error type for all Webex API errors. It provides structured access to the HTTP status code, error message, tracking ID, and raw response body. All specific error sub-types embed this struct, so consumers can use errors.As(err, &apiErr) to access common fields regardless of the specific error type.
type AuthError ¶ added in v2.0.14
type AuthError struct {
*APIError
}
AuthError is returned for HTTP 401 Unauthorized responses.
type Client ¶
type Client struct {
// Base URL for API requests
BaseURL *url.URL
// Configuration for the client
Config *Config
// contains filtered or unexported fields
}
Client is the main Webex client struct
func NewClient ¶
NewClient creates a new Webex client with the given access token and optional configuration If config is nil, the default configuration will be used.
func (*Client) GetAccessToken ¶
GetAccessToken returns the access token used for API authentication
func (*Client) GetHTTPClient ¶
GetHTTPClient returns the HTTP client used for API requests
func (*Client) PageFromCursor ¶ added in v2.0.16
PageFromCursor fetches a page directly from a cursor URL (e.g., a previously saved NextPage or PrevPage). This enables direct navigation to any page without sequential traversal — useful for bookmarking or resuming pagination.
Usage:
page, _ := webhooksClient.List(&ListOptions{Max: 10})
cursor := page.NextPage // save this to a database, cache, etc.
// Later — jump directly to that page:
resumedPage, _ := client.PageFromCursor(cursor)
func (*Client) RegisterPlugin ¶
RegisterPlugin registers a plugin with the client
func (*Client) Request ¶
func (c *Client) Request(method, path string, params url.Values, body interface{}) (*http.Response, error)
Request performs an HTTP request to the Webex API with automatic retry for transient errors (429, 502, 503, 504). The caller is responsible for closing the response body when done.
func (*Client) RequestMultipart ¶
func (c *Client) RequestMultipart(path string, fields []MultipartField, files []MultipartFile) (*http.Response, error)
RequestMultipart performs a multipart/form-data POST request to the Webex API with automatic retry for transient errors (429, 502, 503, 504). This is required for local file uploads (e.g., sending messages with attachments). The caller is responsible for closing the response body when done.
func (*Client) RequestMultipartWithRetry ¶ added in v2.0.14
func (c *Client) RequestMultipartWithRetry(ctx context.Context, path string, fields []MultipartField, files []MultipartFile) (*http.Response, error)
RequestMultipartWithRetry performs a multipart/form-data POST with retry support. The multipart body is rebuilt on each retry attempt.
func (*Client) RequestURL ¶ added in v2.0.14
RequestURL performs an HTTP GET request to a full URL (not relative to BaseURL). This is used for pagination where Link headers contain absolute URLs. The request includes the same authentication and default headers as regular requests. The caller is responsible for closing the response body when done.
func (*Client) RequestURLWithRetry ¶ added in v2.0.14
func (c *Client) RequestURLWithRetry(ctx context.Context, method, fullURL string, body interface{}) (*http.Response, error)
RequestURLWithRetry performs an HTTP request to a full URL with retry logic.
func (*Client) RequestWithContext ¶
func (c *Client) RequestWithContext(ctx context.Context, method, path string, params url.Values, body interface{}) (*http.Response, error)
RequestWithContext performs an HTTP request to the Webex API with the given context. The context can be used for per-request timeouts and cancellation. The caller is responsible for closing the response body when done.
func (*Client) RequestWithRetry ¶
func (c *Client) RequestWithRetry(ctx context.Context, method, path string, params url.Values, body interface{}) (*http.Response, error)
RequestWithRetry performs an HTTP request with automatic retry for transient errors. It retries on HTTP 429 (Too Many Requests, respecting Retry-After header) and transient server errors (502, 503, 504) using exponential backoff. The caller is responsible for closing the response body when done.
type Config ¶
type Config struct {
// BaseURL is the base URL of the Webex API
BaseURL string
// Timeout for API requests
Timeout time.Duration
// Default headers to include in API requests
DefaultHeaders map[string]string
// Custom HTTP client to use instead of the default one
// If nil, a default client will be created with the specified Timeout
HttpClient *http.Client
// MaxRetries is the maximum number of retries for transient errors (429, 502, 503, 504).
// Set to 0 to disable retries. Default: 3.
MaxRetries int
// RetryBaseDelay is the initial delay between retries. Default: 1s.
// Subsequent retries use exponential backoff (delay * 2^attempt).
RetryBaseDelay time.Duration
// Logger is the logger for SDK operations. If nil, the standard library's
// default logger (log.Default()) is used.
Logger Logger
}
Config holds the configuration for the Webex client
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a default configuration for the Webex client
type ConflictError ¶ added in v2.0.14
type ConflictError struct {
*APIError
}
ConflictError is returned for HTTP 409 Conflict responses.
func (*ConflictError) Unwrap ¶ added in v2.0.14
func (e *ConflictError) Unwrap() error
Unwrap returns the underlying APIError for errors.As traversal.
type FieldError ¶ added in v2.0.14
type FieldError struct {
// Code is the error code (e.g., "kms_failure").
Code string `json:"code"`
// Reason describes why the field could not be retrieved.
Reason string `json:"reason"`
}
FieldError represents an error on a specific field of a resource. When the Webex API encounters a partial failure retrieving a resource in a list response, individual fields may contain errors instead of their normal values.
type ForbiddenError ¶ added in v2.0.14
type ForbiddenError struct {
*APIError
}
ForbiddenError is returned for HTTP 403 Forbidden responses.
func (*ForbiddenError) Unwrap ¶ added in v2.0.14
func (e *ForbiddenError) Unwrap() error
Unwrap returns the underlying APIError for errors.As traversal.
type GoneError ¶ added in v2.0.14
type GoneError struct {
*APIError
}
GoneError is returned for HTTP 410 Gone responses. For the Contents API, this indicates an infected file that was removed.
type LockedError ¶ added in v2.0.14
type LockedError struct {
*APIError
}
LockedError is returned for HTTP 423 Locked responses. For the Contents API, this indicates a file is being scanned for malware. The RetryAfter field (inherited from APIError) indicates when to retry.
func (*LockedError) Unwrap ¶ added in v2.0.14
func (e *LockedError) Unwrap() error
Unwrap returns the underlying APIError for errors.As traversal.
type Logger ¶
Logger is the interface for SDK logging. Any logger that implements Printf (such as the standard library's *log.Logger) can be used.
type MultipartField ¶
MultipartField represents a text field in a multipart request.
type MultipartFile ¶
type MultipartFile struct {
FieldName string // Form field name (e.g., "files")
FileName string // Original filename (e.g., "report.pdf")
Content []byte // Raw file bytes
}
MultipartFile represents a file to upload in a multipart request.
type NotFoundError ¶ added in v2.0.14
type NotFoundError struct {
*APIError
}
NotFoundError is returned for HTTP 404 Not Found responses.
func (*NotFoundError) Unwrap ¶ added in v2.0.14
func (e *NotFoundError) Unwrap() error
Unwrap returns the underlying APIError for errors.As traversal.
type Page ¶
type Page struct {
Items []json.RawMessage `json:"items"`
NextPage string `json:"-"`
PrevPage string `json:"-"`
HasNext bool `json:"-"`
HasPrev bool `json:"-"`
Client *Client `json:"-"`
Resource Resource `json:"-"`
}
Page represents a paginated response from the Webex API. Pagination follows RFC 5988 (Web Linking) — next/prev URLs are parsed from the response's Link header.
func NewPage ¶
NewPage creates a new Page from an HTTP response. It parses the Link header (RFC 5988) for pagination URLs and the JSON body for the items array.
type Plugin ¶
type Plugin interface {
// Name returns the name of the plugin
Name() string
}
Plugin represents a Webex API plugin
type PreconditionRequiredError ¶ added in v2.0.14
type PreconditionRequiredError struct {
*APIError
}
PreconditionRequiredError is returned for HTTP 428 Precondition Required responses. For the Contents API, this indicates an unscannable file. Adding the query parameter allow=unscannable will enable the download.
func (*PreconditionRequiredError) Unwrap ¶ added in v2.0.14
func (e *PreconditionRequiredError) Unwrap() error
Unwrap returns the underlying APIError for errors.As traversal.
type RateLimitError ¶ added in v2.0.14
type RateLimitError struct {
*APIError
}
RateLimitError is returned for HTTP 429 Too Many Requests responses. The RetryAfter field (inherited from APIError) indicates how long to wait.
func (*RateLimitError) Unwrap ¶ added in v2.0.14
func (e *RateLimitError) Unwrap() error
Unwrap returns the underlying APIError for errors.As traversal.
type Resource ¶ added in v2.0.16
type Resource string
Resource is a typed string identifying a Webex API resource collection.
const ( ResourceRooms Resource = "rooms" ResourceMessages Resource = "messages" ResourceTeams Resource = "teams" ResourceWebhooks Resource = "webhooks" ResourceMeetings Resource = "meetings" ResourceMeetingParticipants Resource = "meetingParticipants" ResourceMemberships Resource = "memberships" ResourcePeople Resource = "people" ResourceTeamMemberships Resource = "team/memberships" ResourceRecordings Resource = "recordings" ResourceTranscripts Resource = "meetingTranscripts" ResourceEvents Resource = "events" ResourceRoomTabs Resource = "room/tabs" ResourceItems Resource = "items" )
type ResourceErrors ¶ added in v2.0.14
type ResourceErrors map[string]FieldError
ResourceErrors maps field names to their errors within a single resource. Present in list response items when partial failures occur (HTTP 200 with some items having field-level errors).
Example JSON:
"errors": {
"title": {
"code": "kms_failure",
"reason": "Key management server failed to respond appropriately."
}
}
func (ResourceErrors) HasErrors ¶ added in v2.0.14
func (re ResourceErrors) HasErrors() bool
HasErrors returns true if this ResourceErrors map contains any errors.
func (ResourceErrors) HasFieldError ¶ added in v2.0.14
func (re ResourceErrors) HasFieldError(field string) bool
HasFieldError returns true if the specified field has an error.
type ServerError ¶ added in v2.0.14
type ServerError struct {
*APIError
}
ServerError is returned for HTTP 5xx responses (500, 502, 503, 504).
func (*ServerError) Unwrap ¶ added in v2.0.14
func (e *ServerError) Unwrap() error
Unwrap returns the underlying APIError for errors.As traversal.