client

package
v0.0.0-...-9f14b0a Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLoggingClient

func NewLoggingClient(level slog.Level) *http.Client

NewLoggingClient creates a new HTTP client with logging

func NewLoggingClientWithLogger

func NewLoggingClientWithLogger(level slog.Level, logger *slog.Logger) *http.Client

NewLoggingClientWithLogger creates a new HTTP client with logging using a custom logger

Types

type BusinessHourService

type BusinessHourService struct {
	*Service[models.BusinessHourResponse, models.BusinessHoursResponse]
}

BusinessHourService handles ticket-related operations

func NewBusinessHourService

func NewBusinessHourService(client *Client) *BusinessHourService

NewBusinessHourService creates a new ticket service

func (*BusinessHourService) Create

Create creates a new businesshour

func (*BusinessHourService) Get

Get retrieves a businesshour by ID

func (*BusinessHourService) List

List retrieves a list of businesshours with optional filters

func (*BusinessHourService) Update

Update updates an existing businesshour

type Client

type Client struct {

	// Services
	BusinessHours    *BusinessHourService
	Companies        *CompanyService
	Customers        *CustomerService
	Files            *FileService
	HelpDocArticles  *HelpDocArticleService
	HelpDocSites     *HelpDocSiteService
	Inboxes          *InboxService
	SLAs             *SLAService
	Spamlists        *SpamlistService
	Tags             *TagService
	TicketPriorities *TicketPriorityService
	Tickets          *TicketService
	TicketSources    *TicketSourceService
	TicketStatuses   *TicketStatusService
	TicketTypes      *TicketTypeService
	Users            *UserService
	// contains filtered or unexported fields
}

Client represents the Desk API client

func NewClient

func NewClient(baseURL string, opts ...Option) *Client

NewClient creates a new Desk.com API client

type CompanyService

type CompanyService struct {
	*Service[models.CompanyResponse, models.CompaniesResponse]
}

CompanyService handles company-related operations

func NewCompanyService

func NewCompanyService(client *Client) *CompanyService

NewCompanyService creates a new company service

func (*CompanyService) Create

Create creates a new company

func (*CompanyService) Get

Get retrieves a company by ID

func (*CompanyService) List

List retrieves a list of companies with optional filters

func (*CompanyService) Update

Update updates an existing company

type Config

type Config struct {
	BaseURL    string
	APIKey     string
	HTTPClient *http.Client
}

Config represents the client configuration

type CustomerService

type CustomerService struct {
	*Service[models.CustomerResponse, models.CustomersResponse]
}

CustomerService handles customer-related operations

func NewCustomerService

func NewCustomerService(client *Client) *CustomerService

NewCustomerService creates a new customer service

func (*CustomerService) Create

Create creates a new customer

func (*CustomerService) Get

Get retrieves a customer by ID

func (*CustomerService) List

List retrieves a list of customers with optional filters

func (*CustomerService) Update

Update updates an existing customer

type DefaultPathHandler

type DefaultPathHandler struct {
	// contains filtered or unexported fields
}

func NewDefaultPathHandler

func NewDefaultPathHandler(base string) DefaultPathHandler

func (DefaultPathHandler) Create

func (d DefaultPathHandler) Create() string

func (DefaultPathHandler) Get

func (d DefaultPathHandler) Get(id int) string

func (DefaultPathHandler) List

func (d DefaultPathHandler) List() string

func (DefaultPathHandler) Update

func (d DefaultPathHandler) Update(id int) string

type FilePathHandler

type FilePathHandler struct {
	DefaultPathHandler
}

func NewFilePathHandler

func NewFilePathHandler() FilePathHandler

func (FilePathHandler) Create

func (f FilePathHandler) Create() string

type FileService

type FileService struct {
	*Service[models.FileResponse, models.FilesResponse]
}

FileService handles ticket-related operations

func NewFileService

func NewFileService(client *Client) *FileService

NewFileService creates a new ticket service

func (*FileService) Create

Create creates a new file reference. This does not upload the file to s3, but returns the necessary information to do so.

func (*FileService) Get

func (s *FileService) Get(ctx context.Context, id int) (*models.FileResponse, error)

Get retrieves a file by ID

func (*FileService) List

func (s *FileService) List(ctx context.Context, params url.Values) (*models.FilesResponse, error)

List retrieves a list of files with optional filters

func (*FileService) Update

func (s *FileService) Update(ctx context.Context, id int, file *models.FileResponse) (*models.FileResponse, error)

Update updates an existing file

func (*FileService) Upload

func (s *FileService) Upload(ctx context.Context, file *models.FileResponse, f []byte) error

Upload uploads a file to s3. This is a helper method that uses the information returned from the Create method.

type FilterBuilder

type FilterBuilder struct {
	// contains filtered or unexported fields
}

FilterBuilder helps build MongoDB-style filters

func NewFilter

func NewFilter() *FilterBuilder

NewFilter creates a new FilterBuilder

func (*FilterBuilder) And

func (f *FilterBuilder) And(filters ...*FilterBuilder) *FilterBuilder

And adds an AND condition

func (*FilterBuilder) Build

func (f *FilterBuilder) Build() string

Build returns the filter as a JSON string

func (*FilterBuilder) Eq

func (f *FilterBuilder) Eq(field string, value any) *FilterBuilder

Eq adds an equality condition

func (*FilterBuilder) Gt

func (f *FilterBuilder) Gt(field string, value any) *FilterBuilder

Gt adds a greater-than condition

func (*FilterBuilder) Gte

func (f *FilterBuilder) Gte(field string, value any) *FilterBuilder

Gte adds a greater-than-or-equal condition

func (*FilterBuilder) In

func (f *FilterBuilder) In(field string, values []any) *FilterBuilder

In adds an in-list condition

func (*FilterBuilder) Lt

func (f *FilterBuilder) Lt(field string, value any) *FilterBuilder

Lt adds a less-than condition

func (*FilterBuilder) Lte

func (f *FilterBuilder) Lte(field string, value any) *FilterBuilder

Lte adds a less-than-or-equal condition

func (*FilterBuilder) Ne

func (f *FilterBuilder) Ne(field string, value any) *FilterBuilder

Ne adds a not-equal condition

func (*FilterBuilder) Nin

func (f *FilterBuilder) Nin(field string, values []any) *FilterBuilder

Nin adds a not-in-list condition

func (*FilterBuilder) Or

func (f *FilterBuilder) Or(filters ...*FilterBuilder) *FilterBuilder

Or adds an OR condition

type FilterOperator

type FilterOperator string

FilterOperator represents the available filter operators

const (
	// Comparison operators
	OpEq  FilterOperator = "$eq"
	OpNe  FilterOperator = "$ne"
	OpLt  FilterOperator = "$lt"
	OpLte FilterOperator = "$lte"
	OpGt  FilterOperator = "$gt"
	OpGte FilterOperator = "$gte"
	OpIn  FilterOperator = "$in"
	OpNin FilterOperator = "$nin"

	// Logical operators
	OpAnd FilterOperator = "$and"
	OpOr  FilterOperator = "$or"
)

type HelpDocArticleService

type HelpDocArticleService struct {
	*Service[models.HelpDocArticleResponse, models.HelpDocArticlesResponse]
}

HelpDocArticleService handles help doc article-related operations

func NewHelpDocArticleService

func NewHelpDocArticleService(client *Client) *HelpDocArticleService

NewHelpDocArticleService creates a new help doc article service

func (*HelpDocArticleService) Create

Create creates a new help doc article

func (*HelpDocArticleService) Get

Get retrieves a help doc article by ID

func (*HelpDocArticleService) List

List retrieves a list of help doc articles with optional filters

func (*HelpDocArticleService) Update

Update updates an existing help doc article

type HelpDocSiteService

type HelpDocSiteService struct {
	*Service[models.HelpDocSiteResponse, models.HelpDocSitesResponse]
}

HelpDocSiteService handles help doc site-related operations

func NewHelpDocSiteService

func NewHelpDocSiteService(client *Client) *HelpDocSiteService

NewHelpDocSiteService creates a new help doc site service

func (*HelpDocSiteService) Create

Create creates a new ticket

func (*HelpDocSiteService) Get

Get retrieves a help doc site by ID

func (*HelpDocSiteService) List

List retrieves a list of help doc sites with optional filters

func (*HelpDocSiteService) Update

Update updates an existing ticket

type InboxService

type InboxService struct {
	*Service[models.InboxResponse, models.InboxesResponse]
}

InboxService handles ticket-related operations

func NewInboxService

func NewInboxService(client *Client) *InboxService

NewInboxService creates a new ticket service

func (*InboxService) Create

Create creates a new inbox

func (*InboxService) Get

Get retrieves an inbox by ID

func (*InboxService) List

func (s *InboxService) List(ctx context.Context, params url.Values) (*models.InboxesResponse, error)

List retrieves a list of inboxes with optional filters

func (*InboxService) Update

func (s *InboxService) Update(ctx context.Context, id int, inbox *models.InboxResponse) (*models.InboxResponse, error)

Update updates an existing inbox

type ListOptions

type ListOptions struct {
	Page    int
	PerPage int
	SortBy  string
	SortDir string
	Embed   string
	Fields  string
	Q       string
}

ListOptions represents options for list operations

func (*ListOptions) Encode

func (o *ListOptions) Encode() string

Encode encodes the options into a query string

type LoggingTransport

type LoggingTransport struct {
	Transport http.RoundTripper
	Logger    *slog.Logger
}

LoggingTransport wraps an http.RoundTripper and logs the request and response

func (*LoggingTransport) RoundTrip

func (t *LoggingTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface

type MiddlewareFunc

type MiddlewareFunc func(ctx context.Context, req *http.Request, next RequestHandler) (*http.Response, error)

MiddlewareFunc represents a middleware function that can modify requests before they are sent

func AuthMiddleware

func AuthMiddleware(token string) MiddlewareFunc

AuthMiddleware creates middleware that adds authentication headers

func ConditionalMiddleware

func ConditionalMiddleware(condition func(*http.Request) bool, middleware MiddlewareFunc) MiddlewareFunc

ConditionalMiddleware creates middleware that only executes when a condition is met

func HeaderMiddleware

func HeaderMiddleware(headers map[string]string) MiddlewareFunc

HeaderMiddleware creates middleware that adds custom headers to requests

func LoggingMiddleware

func LoggingMiddleware(logger *slog.Logger) MiddlewareFunc

LoggingMiddleware creates middleware that logs HTTP requests and responses

func RateLimitMiddleware

func RateLimitMiddleware(requestsPerSecond float64) MiddlewareFunc

RateLimitMiddleware creates middleware that implements rate limiting

func RequestIDMiddleware

func RequestIDMiddleware() MiddlewareFunc

RequestIDMiddleware creates middleware that adds a unique request ID header

func RetryMiddleware

func RetryMiddleware(maxRetries int, retryDelay time.Duration) MiddlewareFunc

RetryMiddleware creates middleware that retries requests on failure

func TimeoutMiddleware

func TimeoutMiddleware(timeout time.Duration) MiddlewareFunc

TimeoutMiddleware creates middleware that enforces request timeouts

func UserAgentMiddleware

func UserAgentMiddleware(userAgent string) MiddlewareFunc

UserAgentMiddleware creates middleware that adds a User-Agent header

type MockReadCloser

type MockReadCloser struct {
	io.Reader
	// contains filtered or unexported fields
}

MockReadCloser implements io.ReadCloser for testing

func NewMockReadCloser

func NewMockReadCloser(s string) *MockReadCloser

NewMockReadCloser creates a new MockReadCloser from a string

func (*MockReadCloser) Close

func (m *MockReadCloser) Close() error

Close implements io.Closer

type MockRoundTripper

type MockRoundTripper struct {
	// contains filtered or unexported fields
}

MockRoundTripper implements http.RoundTripper for testing

func NewMockRoundTripper

func NewMockRoundTripper() *MockRoundTripper

NewMockRoundTripper creates a new mock round tripper

func (*MockRoundTripper) AddResponse

func (m *MockRoundTripper) AddResponse(method, urlPath string, statusCode int, body interface{})

AddResponse adds a mock response for a given method and path

func (*MockRoundTripper) GetRequests

func (m *MockRoundTripper) GetRequests() []*http.Request

GetRequests returns all requests made to the mock

func (*MockRoundTripper) Reset

func (m *MockRoundTripper) Reset()

Reset clears all stored requests and responses

func (*MockRoundTripper) RoundTrip

func (m *MockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper

type Option

type Option func(*Client)

Option is a function that configures a Client

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key for the client

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets a custom HTTP client

func WithLogLevel

func WithLogLevel(level slog.Level) Option

WithLogLevel sets the log level for the client

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets a custom logger for the client

func WithMiddleware

func WithMiddleware(mw MiddlewareFunc) Option

WithMiddleware adds middleware to the client

type PathHandler

type PathHandler interface {
	Get(id int) string
	List() string
	Create() string
	Update(id int) string
}

type RequestHandler

type RequestHandler func(ctx context.Context, req *http.Request) (*http.Response, error)

RequestHandler represents the function that executes the actual HTTP request

type SLAService

type SLAService struct {
	*Service[models.SLAResponse, models.SLAsResponse]
}

SLAService handles ticket-related operations

func NewSLAService

func NewSLAService(client *Client) *SLAService

NewSLAService creates a new ticket service

func (*SLAService) Create

Create creates a new sla

func (*SLAService) Get

func (s *SLAService) Get(ctx context.Context, id int) (*models.SLAResponse, error)

Get retrieves a sla by ID

func (*SLAService) List

func (s *SLAService) List(ctx context.Context, params url.Values) (*models.SLAsResponse, error)

List retrieves a list of slas with optional filters

func (*SLAService) Update

func (s *SLAService) Update(ctx context.Context, id int, sla *models.SLAResponse) (*models.SLAResponse, error)

Update updates an existing sla

type Service

type Service[T any, L any] struct {
	// contains filtered or unexported fields
}

Service handles generic resource operations

func NewService

func NewService[T any, L any](client *Client, router PathHandler) *Service[T, L]

NewService creates a new generic service

func (*Service[T, L]) Create

func (s *Service[T, L]) Create(ctx context.Context, resource *T) (*T, error)

Create creates a new resource

func (*Service[T, L]) Get

func (s *Service[T, L]) Get(ctx context.Context, id int) (*T, error)

Get retrieves a resource by ID

func (*Service[T, L]) List

func (s *Service[T, L]) List(ctx context.Context, params url.Values) (*L, error)

List retrieves a list of resources with optional filters

func (*Service[T, L]) Update

func (s *Service[T, L]) Update(ctx context.Context, id int, resource *T) (*T, error)

Update updates an existing resource

type SpamlistService

type SpamlistService struct {
	*Service[models.SpamlistResponse, models.SpamlistsResponse]
}

SpamlistService handles spamlist-related operations

func NewSpamlistService

func NewSpamlistService(client *Client) *SpamlistService

NewSpamlistService creates a new spamlist service

func (*SpamlistService) Create

Create creates a new spamlist

func (*SpamlistService) Get

Get retrieves a spamlist by ID

func (*SpamlistService) List

List retrieves a list of spamlistes with optional filters

func (*SpamlistService) Update

Update updates an existing spamlist

type TagService

type TagService struct {
	*Service[models.TagResponse, models.TagsResponse]
}

TagService handles ticket-related operations

func NewTagService

func NewTagService(client *Client) *TagService

NewTagService creates a new ticket service

func (*TagService) Create

Create creates a new tag

func (*TagService) Get

func (s *TagService) Get(ctx context.Context, id int) (*models.TagResponse, error)

Get retrieves a tag by ID

func (*TagService) List

func (s *TagService) List(ctx context.Context, params url.Values) (*models.TagsResponse, error)

List retrieves a list of tages with optional filters

func (*TagService) Update

func (s *TagService) Update(ctx context.Context, id int, tag *models.TagResponse) (*models.TagResponse, error)

Update updates an existing tag

type TicketPriorityService

type TicketPriorityService struct {
	*Service[models.TicketPriorityResponse, models.TicketPrioritiesResponse]
}

TicketPriorityService handles ticket-related operations

func NewTicketPriorityService

func NewTicketPriorityService(client *Client) *TicketPriorityService

NewTicketPriorityService creates a new ticket service

func (*TicketPriorityService) Create

Create creates a new ticketpriority

func (*TicketPriorityService) Get

Get retrieves a ticketpriority by ID

func (*TicketPriorityService) List

List retrieves a list of ticketpriorityes with optional filters

func (*TicketPriorityService) Update

Update updates an existing ticketpriority

type TicketService

type TicketService struct {
	*Service[models.TicketResponse, models.TicketsResponse]
	// contains filtered or unexported fields
}

TicketService handles ticket-related operations

func NewTicketService

func NewTicketService(client *Client) *TicketService

NewTicketService creates a new ticket service

func (*TicketService) Create

Create creates a new ticket

func (*TicketService) Get

Get retrieves a ticket by ID

func (*TicketService) List

List retrieves a list of tickets with optional filters

func (*TicketService) Search

Search searches for tickets based on query parameters

func (*TicketService) Update

Update updates an existing ticket

type TicketSourceService

type TicketSourceService struct {
	*Service[models.TicketSourceResponse, models.TicketSourcesResponse]
}

TicketSourceService handles ticket-related operations

func NewTicketSourceService

func NewTicketSourceService(client *Client) *TicketSourceService

NewTicketSourceService creates a new ticket service

func (*TicketSourceService) Create

Create creates a new ticketsource

func (*TicketSourceService) Get

Get retrieves a ticketsource by ID

func (*TicketSourceService) List

List retrieves a list of ticketsources with optional filters

func (*TicketSourceService) Update

Update updates an existing ticketsource

type TicketStatusService

type TicketStatusService struct {
	*Service[models.TicketStatusResponse, models.TicketStatusesResponse]
}

TicketStatusService handles ticket-related operations

func NewTicketStatusService

func NewTicketStatusService(client *Client) *TicketStatusService

NewTicketStatusService creates a new ticket service

func (*TicketStatusService) Create

Create creates a new ticketstatus

func (*TicketStatusService) Get

Get retrieves a ticketstatus by ID

func (*TicketStatusService) List

List retrieves a list of ticketstatuses with optional filters

func (*TicketStatusService) Update

Update updates an existing ticketstatus

type TicketTypeService

type TicketTypeService struct {
	*Service[models.TicketTypeResponse, models.TicketTypesResponse]
}

TicketTypeService handles ticket-related operations

func NewTicketTypeService

func NewTicketTypeService(client *Client) *TicketTypeService

NewTicketTypeService creates a new ticket service

func (*TicketTypeService) Create

Create creates a new tickettype

func (*TicketTypeService) Get

Get retrieves a tickettype by ID

func (*TicketTypeService) List

List retrieves a list of tickettypees with optional filters

func (*TicketTypeService) Update

Update updates an existing tickettype

type UserService

type UserService struct {
	*Service[models.UserResponse, models.UsersResponse]
}

UserService handles user-related operations

func NewUserService

func NewUserService(client *Client) *UserService

NewUserService creates a new user service

func (*UserService) Create

Create creates a new user

func (*UserService) Get

func (s *UserService) Get(ctx context.Context, id int) (*models.UserResponse, error)

Get retrieves a user by ID

func (*UserService) List

func (s *UserService) List(ctx context.Context, params url.Values) (*models.UsersResponse, error)

List retrieves a list of users with optional filters

func (*UserService) Update

func (s *UserService) Update(ctx context.Context, id int, user *models.UserResponse) (*models.UserResponse, error)

Update updates an existing user

Jump to

Keyboard shortcuts

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