Documentation
¶
Overview ¶
Package dtrpg is the root of the DriveThruRPG Go SDK. It wires together configuration (aliased from the library package), the authentication session lifecycle (package auth), and the library API client (package library) behind a single Sdk entry point.
Index ¶
- Constants
- Variables
- type AuthSession
- type AuthSessionError
- type AuthState
- type AuthTokenResponse
- type Config
- type LibraryClient
- type LibraryItemsParams
- type PageParams
- type Sdk
- func (s *Sdk) ApplyAuthResponse(response AuthTokenResponse) (*auth.AuthSession, error)
- func (s *Sdk) ClearSession()
- func (s *Sdk) Config() *Config
- func (s *Sdk) Configure(config Config)
- func (s *Sdk) InvalidateSession(err AuthSessionError) (AuthSessionError, error)
- func (s *Sdk) LibraryClient() (*library.Client, error)
- func (s *Sdk) RequireConfig() (*Config, error)
- func (s *Sdk) RequireSession() (*auth.AuthSession, error)
- func (s *Sdk) Session() *auth.AuthSession
- type SessionTransition
Constants ¶
const DefaultAPIVersion = library.DefaultAPIVersion
DefaultAPIVersion is the API version path segment used when no custom version is provided.
const DefaultBaseURL = library.DefaultBaseURL
DefaultBaseURL is the production DriveThruRPG API base URL used when no custom URL is provided.
Variables ¶
var ErrUnauthenticated = errors.New("dtrpg: sdk does not have an authenticated session")
ErrUnauthenticated indicates the SDK has no active authentication session.
Obtain a session by calling Sdk.ApplyAuthResponse with a successful token response from the API.
var ErrUnconfigured = errors.New("dtrpg: sdk is not configured")
ErrUnconfigured indicates the SDK has not been configured with a Config yet.
Call Sdk.Configure or construct the SDK with NewSdkWithConfig before making API calls.
Functions ¶
This section is empty.
Types ¶
type AuthSession ¶
type AuthSession = auth.AuthSession
AuthSession is an active authentication session with the DriveThruRPG API. See auth.AuthSession for field documentation.
type AuthSessionError ¶
type AuthSessionError = auth.AuthSessionError
AuthSessionError is a structured authentication error returned by the DriveThruRPG API. See auth.AuthSessionError.
type AuthState ¶
AuthState is the authentication failure state reported by the DriveThruRPG API. See auth.AuthState.
type AuthTokenResponse ¶
type AuthTokenResponse = auth.AuthTokenResponse
AuthTokenResponse is the raw authentication token payload returned by the DriveThruRPG API. See auth.AuthTokenResponse.
func NewAuthTokenResponse ¶
func NewAuthTokenResponse(token, refreshToken string, refreshTokenTTL uint64) AuthTokenResponse
NewAuthTokenResponse constructs a new AuthTokenResponse from its fields.
type Config ¶
Config holds the application-level settings required to make requests to the DriveThruRPG API. See library.Config for field documentation; it lives in the library package to avoid an import cycle between this package, auth, and library, and is aliased here for the common single-import call site.
func NewConfig ¶
NewConfig creates a Config targeting the production API with the given applicationKey.
func NewConfigWithBaseURL ¶
NewConfigWithBaseURL creates a Config with a custom baseURL, overriding the production endpoint.
type LibraryClient ¶
LibraryClient is an authenticated HTTP client for DriveThruRPG library endpoints. See library.Client.
type LibraryItemsParams ¶
type LibraryItemsParams = library.LibraryItemsParams
LibraryItemsParams holds query parameters for the order-products (library items) endpoint. See library.LibraryItemsParams.
type PageParams ¶
type PageParams = library.PageParams
PageParams holds query parameters for paginated collection endpoints. See library.PageParams.
type Sdk ¶
type Sdk struct {
// contains filtered or unexported fields
}
Sdk is the DriveThruRPG SDK client.
Sdk coordinates SDK-level configuration and authentication session lifecycle. It must be configured before any authenticated API calls can succeed.
Lifecycle ¶
1. Create an Sdk instance, optionally supplying a Config upfront. 2. After a successful API login, call ApplyAuthResponse to store the session. 3. Use RequireSession to obtain the active session before making requests. 4. Call InvalidateSession when the API reports a session error, or ClearSession to log out.
func NewSdk ¶
func NewSdk() *Sdk
NewSdk creates an unconfigured Sdk instance. Call Configure before making any API calls, or prefer NewSdkWithConfig if the configuration is available at construction time.
func NewSdkWithConfig ¶
NewSdkWithConfig creates an Sdk instance pre-loaded with the given Config.
func (*Sdk) ApplyAuthResponse ¶
func (s *Sdk) ApplyAuthResponse(response AuthTokenResponse) (*auth.AuthSession, error)
ApplyAuthResponse stores a new authentication session derived from a raw API token response.
Returns ErrUnconfigured if the SDK has not been configured yet. On success, returns the newly stored session.
func (*Sdk) ClearSession ¶
func (s *Sdk) ClearSession()
ClearSession removes the current authentication session without recording an error.
Use this for voluntary log-out flows. For API-reported session failures, prefer InvalidateSession.
func (*Sdk) Configure ¶
Configure sets or replaces the SDK's configuration.
This can be called at any time, including after the SDK has been used. Replacing the configuration does not automatically clear an existing session.
func (*Sdk) InvalidateSession ¶
func (s *Sdk) InvalidateSession(err AuthSessionError) (AuthSessionError, error)
InvalidateSession removes the current session and records the API-reported error that caused it.
Returns ErrUnauthenticated if there is no session to invalidate. On success, returns the provided err so callers can inspect or propagate it.
func (*Sdk) LibraryClient ¶
LibraryClient creates a library.Client from the current configuration and session.
Returns ErrUnconfigured if the SDK has not been configured, or ErrUnauthenticated if there is no active session.
func (*Sdk) RequireConfig ¶
RequireConfig returns the current configuration, or ErrUnconfigured if absent.
Use this in call chains where a missing config should surface as an error.
func (*Sdk) RequireSession ¶
func (s *Sdk) RequireSession() (*auth.AuthSession, error)
RequireSession returns the current session, or ErrUnauthenticated if absent.
Use this in call chains where a missing session should surface as an error.
func (*Sdk) Session ¶
func (s *Sdk) Session() *auth.AuthSession
Session returns the current authentication session, or nil if unauthenticated.
type SessionTransition ¶
type SessionTransition = auth.SessionTransition
SessionTransition is the outcome of invalidating an AuthSession. See auth.SessionTransition.
Directories
¶
| Path | Synopsis |
|---|---|
|
This file targets www.drivethrurpg.com — not api.drivethrurpg.com.
|
This file targets www.drivethrurpg.com — not api.drivethrurpg.com. |
|
internal
|
|
|
opgen
command
Command opgen reads an OpenAPI YAML spec and writes a Go source file exposing the default server URL and the list of declared operations (method + path).
|
Command opgen reads an OpenAPI YAML spec and writes a Go source file exposing the default server URL and the list of declared operations (method + path). |
|
Package library provides the DriveThruRPG library API client, its request/response types, and the SDK's Config type (kept here rather than the root package to avoid an import cycle between the root, auth, and library packages).
|
Package library provides the DriveThruRPG library API client, its request/response types, and the SDK's Config type (kept here rather than the root package to avoid an import cycle between the root, auth, and library packages). |
|
Package openapi exposes build-time metadata generated from the dtrpg-api submodule's openapi.yaml: the default server URL and the list of operations (method + path) it defines.
|
Package openapi exposes build-time metadata generated from the dtrpg-api submodule's openapi.yaml: the default server URL and the list of operations (method + path) it defines. |