Documentation
¶
Overview ¶
Package client is the hand-written base client the generated SDKs, lib/emby and lib/jf, send every request through, after go-azure-sdk's sdk/client. The two servers speak the same HTTP API family and differ here only in how the token is sent (EmbyToken, JellyfinToken).
A generated method builds RequestOptions (method, path, the status codes the operation is documented to answer, its options object), makes a Request, marshals the body into it, executes it and unmarshals the Response into its model:
opts := client.RequestOptions{
ContentType: "application/json",
ExpectedStatusCodes: []int{http.StatusOK},
HttpMethod: http.MethodGet,
OptionsObject: options,
Path: "/Items",
}
req, err := c.Client.NewRequest(ctx, opts)
resp, err := req.Execute(ctx)
err = resp.Unmarshal(&model)
A status the operation does not document is an error (*StatusError), even another 2xx: that is how a document that has drifted from its server shows up, and the fix belongs in the importer's workarounds. The response is returned alongside the error, its body still readable.
Index ¶
- Constants
- func CSV[T ~string | ~int | ~int64](values []T) string
- func IsNotFound(err error) bool
- func JSONObject[T any](value map[string]T) string
- func StatusCode(err error) int
- func WasNotFound(resp *http.Response) bool
- type Authorizer
- type Client
- type EmbyToken
- type Headers
- type JellyfinToken
- type Options
- type QueryParams
- type Request
- type RequestOptions
- type Response
- type StatusError
Constants ¶
const ( // MaxResponseBytes caps a buffered (non-stream) response body. MaxResponseBytes = 64 << 20 // DefaultPageSize is the page a Complete method asks for when the // options leave Limit unset. DefaultPageSize = 500 // UserAgent is sent with every request, and names the client to the // server in the MediaBrowser authorization header. UserAgent = "embyfin-mcp" )
Variables ¶
This section is empty.
Functions ¶
func CSV ¶
CSV joins a list parameter the way both servers read arrays in a query string: comma-separated.
func IsNotFound ¶
IsNotFound reports whether err is a 404 from the server.
func JSONObject ¶
JSONObject renders an object query parameter as the JSON string the servers bind it from.
func StatusCode ¶
StatusCode returns the status of a *StatusError in err's chain, or 0.
func WasNotFound ¶
WasNotFound reports whether a response is a 404.
Types ¶
type Authorizer ¶
Authorizer adds credentials to a request.
type Client ¶
type Client struct {
// BaseURL is the server address without a trailing slash.
BaseURL string
HTTPClient *http.Client
Authorizer Authorizer
}
Client sends requests to one server.
func New ¶
func New(baseURL string, authorizer Authorizer) (*Client, error)
New returns a client for the server at baseURL (scheme and host, optionally a path prefix such as /emby).
func (*Client) NewRequest ¶
NewRequest builds a request with authentication, the fixed client headers and the options object applied.
type EmbyToken ¶
type EmbyToken string
EmbyToken authenticates to Emby with an API key or a user access token. Emby reads the token from X-Emby-Token and identifies the client from X-Emby-Authorization, which carries the token as well.
type Headers ¶
type Headers struct {
// contains filtered or unexported fields
}
Headers are request headers from an options object.
type JellyfinToken ¶
type JellyfinToken string
JellyfinToken authenticates to Jellyfin with an API key or a user access token. Jellyfin takes the token and the client identity from one MediaBrowser Authorization header (Jellyfin 12 answers 401 to a key sent only as X-Emby-Token).
func (JellyfinToken) Authorize ¶
func (t JellyfinToken) Authorize(req *http.Request)
type Options ¶
type Options interface {
ToHeaders() *Headers
ToQuery() *QueryParams
}
Options is what a generated options struct implements: the query and header parameters it holds.
type QueryParams ¶
type QueryParams struct {
// contains filtered or unexported fields
}
QueryParams are query parameters from an options object.
func (*QueryParams) Append ¶
func (q *QueryParams) Append(key, value string)
Append adds a query parameter.
func (*QueryParams) Values ¶
func (q *QueryParams) Values() url.Values
Values returns the parameters.
type Request ¶
type Request struct {
*http.Request
ExpectedStatusCodes []int
StreamResponse bool
// contains filtered or unexported fields
}
Request is a request being built.
func (*Request) Execute ¶
Execute sends the request. The response is returned whenever the server answered, including with a *StatusError, so the caller can read its status and body. Its body is buffered (and readable again) unless the request streams a successful response.
type RequestOptions ¶
type RequestOptions struct {
// ContentType is the media type of the request body, when there is one.
ContentType string
// ExpectedStatusCodes are the statuses the operation documents; any
// other is a *StatusError.
ExpectedStatusCodes []int
HttpMethod string //nolint:revive,staticcheck // go-azure-sdk's spelling, which the generated code mirrors
// OptionsObject supplies query parameters and headers; nil for none.
OptionsObject Options
// Path is the escaped path below BaseURL.
Path string
// StreamResponse leaves a successful response's body unread for the
// caller, for operations that answer a file.
StreamResponse bool
}
RequestOptions describes one request.
type StatusError ¶
type StatusError struct {
Method string
Path string
StatusCode int
ExpectedStatusCodes []int
// Body is the start of the response body.
Body string
}
StatusError is an answer with a status the operation does not document.
func (*StatusError) Error ¶
func (e *StatusError) Error() string