Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶ added in v0.1.1
CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range or equal to 202 Accepted. API error responses are expected to have response body, and a JSON response body that maps to ErrorResponse.
The error type will be *RateLimitError for rate limit exceeded errors, *AcceptedError for 202 Accepted status codes, and *TwoFactorAuthError for two-factor authentication errors.
Types ¶
type AcceptedError ¶ added in v0.1.1
type AcceptedError struct { // Raw contains the response body. Raw []byte }
AcceptedError occurs when GitHub returns 202 Accepted response with an empty body, which means a job was scheduled on the GitHub side to process the information needed and cache it. Technically, 202 Accepted is not a real error, it's just used to indicate that results are not ready yet, but should be available soon. The request can be repeated after some time.
func (*AcceptedError) Error ¶ added in v0.1.1
func (*AcceptedError) Error() string
func (*AcceptedError) Is ¶ added in v0.1.1
func (ae *AcceptedError) Is(target error) bool
Is returns whether the provided error equals this error.
type Client ¶
type Client struct { // Base URL for API requests. BaseURL should always be specified with a trailing slash. BaseURL *url.URL // API Key for the Tautulli API APIKey string // User agent used when communicating with the Tautulli API. UserAgent string // Services used for talking to different parts of the Tautulli API. Notifications *NotificationsService // Debug mode. Add Debug bool // contains filtered or unexported fields }
A Client manages communication with the Tautulli API.
func NewClient ¶
func NewClient(httpClient *http.Client, baseURL *url.URL, apiKey string, options *ClientOptions) *Client
NewClient returns a new Tautulli API client. If a nil httpClient is provided, a new http.Client will be used.
func (*Client) BareDo ¶ added in v0.1.1
BareDo sends an API request and lets you handle the api response. If an error or API Error occurs, the error will contain more information. Otherwise you are supposed to read and close the response's Body. If rate limit is exceeded and reset time is in the future, BareDo returns *RateLimitError immediately without making a network API call.
The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.
func (*Client) Do ¶
Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If v is nil, and no error hapens, the response is returned as is. If rate limit is exceeded and reset time is in the future, Do returns *RateLimitError immediately without making a network API call.
The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or times out, ctx.Err() will be returned.
type ClientOptions ¶ added in v0.1.1
type CommonParameters ¶
type CommonParameters struct { APIKey string `url:"apikey"` // API key for the Tautulli API OutType string `url:"out_type,omitempty"` // Output format of the response Debug int `url:"debug,omitempty"` // Debug mode }
CommonParameters are the parameters that are common to all requests.
type Error ¶ added in v0.1.1
type Error struct { Resource string `json:"resource"` // resource on which the error occurred Field string `json:"field"` // field on which the error occurred Code string `json:"code"` // validation error code Message string `json:"message"` // Message describing the error. Errors with Code == "custom" will always have this set. }
An Error reports more details on an individual error in an ErrorResponse. These are the possible validation error codes:
missing: resource does not exist missing_field: a required field on a resource has not been set invalid: the formatting of a field is invalid already_exists: another resource has the same valid as this field custom: some resources return this (e.g. github.User.CreateKey()), additional information is set in the Message field of the Error
GitHub error responses structure are often undocumented and inconsistent. Sometimes error is just a simple string (Issue #540). In such cases, Message represents an error message as a workaround.
GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/#client-errors
func (*Error) UnmarshalJSON ¶ added in v0.1.1
type ErrorResponse ¶ added in v0.1.1
type ErrorResponse struct { Response *http.Response // HTTP response that caused this error Message string `json:"message"` // error message }
An ErrorResponse reports one or more errors caused by an API request.
GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/#client-errors
func (*ErrorResponse) Error ¶ added in v0.1.1
func (r *ErrorResponse) Error() string
type NotificationsService ¶
type NotificationsService service
NotificationsService handles communication with the notification related methods of the Tautulli API.
func (*NotificationsService) Notify ¶
func (s *NotificationsService) Notify(ctx context.Context, params *NotifyParameters) (*Response, error)
Notify sends a notification using the Tautulli API.
type NotifyParameters ¶
type NotifyParameters struct { NotifierID int `url:"notifier_id"` // The ID number of the notification agent Subject string `url:"subject"` // The subject of the message Body string `url:"body"` // The body of the message Headers string `url:"headers,omitempty"` // Optional. The JSON headers for webhook notifications ScriptArgs string `url:"script_args,omitempty"` // Optional. The arguments for script notifications }
NotifyParameters are parameters for sending a notification using the Tautulli API.