Documentation
¶
Overview ¶
Package printix provides a client for the Printix Cloud Print API.
The Printix API allows applications to submit print jobs to cloud-connected printers. It supports various document formats including PDF, PCL, PostScript, and plain text.
Basic usage:
client := printix.New(clientID, clientSecret, printix.WithTestMode(true)) // Print a PDF file err := client.PrintFile(ctx, printerID, "My Document", "/path/to/document.pdf", nil) // Get available printers printers, err := client.GetPrinters(ctx)
The package handles OAuth authentication automatically and provides methods for:
- Submitting print jobs
- Uploading documents
- Managing printers
- Tracking job status
For ZPL label printing, the content type should be set appropriately, though full ZPL support depends on the printer capabilities.
Index ¶
- Constants
- type Client
- func (c *Client) AddGroupMember(ctx context.Context, groupID, userID string) error
- func (c *Client) CancelJob(ctx context.Context, jobID string) error
- func (c *Client) CompleteUpload(ctx context.Context, completeURL string) error
- func (c *Client) CreateGroup(ctx context.Context, group *Group) (*Group, error)
- func (c *Client) CreateUser(ctx context.Context, user *User) (*User, error)
- func (c *Client) DeleteGroup(ctx context.Context, groupID string) error
- func (c *Client) DeleteJob(ctx context.Context, jobID string) error
- func (c *Client) DeleteUser(ctx context.Context, userID string) error
- func (c *Client) FindPrinterByName(ctx context.Context, name string) (*Printer, error)
- func (c *Client) GetAllPrinters(ctx context.Context, query string) ([]Printer, error)
- func (c *Client) GetGroup(ctx context.Context, groupID string) (*Group, error)
- func (c *Client) GetGroups(ctx context.Context, opts *GetGroupsOptions) (*GroupsResponse, error)
- func (c *Client) GetJob(ctx context.Context, jobID string) (*Job, error)
- func (c *Client) GetJobs(ctx context.Context, opts *GetJobsOptions) ([]Job, error)
- func (c *Client) GetPrinter(ctx context.Context, printerID string) (*Printer, error)
- func (c *Client) GetPrinters(ctx context.Context, opts *GetPrintersOptions) (*PrintersResponse, error)
- func (c *Client) GetRateLimitInfo() (remaining int, reset time.Time)
- func (c *Client) GetTenantID() string
- func (c *Client) GetTenants(ctx context.Context) (*TenantsResponse, error)
- func (c *Client) GetUser(ctx context.Context, userID string) (*User, error)
- func (c *Client) GetUsers(ctx context.Context, opts *GetUsersOptions) (*UsersResponse, error)
- func (c *Client) PrintData(ctx context.Context, printerID, title string, data []byte, pdl string, ...) error
- func (c *Client) PrintFile(ctx context.Context, printerID, title, filePath string, options *PrintOptions) error
- func (c *Client) RemoveGroupMember(ctx context.Context, groupID, userID string) error
- func (c *Client) SetTenant(tenantID string)
- func (c *Client) Submit(ctx context.Context, job *PrintJob) (*SubmitResponse, error)
- func (c *Client) UpdateGroup(ctx context.Context, groupID string, group *Group) (*Group, error)
- func (c *Client) UpdateUser(ctx context.Context, userID string, user *User) (*User, error)
- func (c *Client) UploadDocument(ctx context.Context, uploadLink string, headers map[string]string, data []byte) error
- type ColorOption
- type CompleteUploadRequest
- type ContentType
- type GetGroupsOptions
- type GetJobsOptions
- type GetPrintersOptions
- type GetUsersOptions
- type Group
- type GroupsResponse
- type Job
- type JobsResponse
- type LocalizedString
- type MediaSizeOption
- type Option
- type PrintJob
- type PrintOptions
- type Printer
- type PrinterCapabilities
- type PrintersResponse
- type Response
- type SubmitResponse
- type Tenant
- type TenantsResponse
- type User
- type UsersResponse
- type VendorCapability
- type WebhookEvent
- type WebhookJobStatusChange
- type WebhookPayload
- type WebhookValidator
Constants ¶
const ( JobStatusPending = "pending" JobStatusProcessing = "processing" JobStatusPrinting = "printing" JobStatusCompleted = "completed" JobStatusFailed = "failed" JobStatusCancelled = "cancelled" )
JobStatus represents possible job statuses.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a Printix API client.
func (*Client) AddGroupMember ¶
AddGroupMember adds a user to a group.
func (*Client) CompleteUpload ¶
CompleteUpload notifies Printix that the document upload is complete.
func (*Client) CreateGroup ¶
CreateGroup creates a new group.
func (*Client) CreateUser ¶
CreateUser creates a new user.
func (*Client) DeleteGroup ¶
DeleteGroup deletes a group.
func (*Client) DeleteUser ¶
DeleteUser deletes a user.
func (*Client) FindPrinterByName ¶
FindPrinterByName finds a printer by its name.
func (*Client) GetAllPrinters ¶
GetAllPrinters retrieves all available printers by automatically handling pagination.
func (*Client) GetGroups ¶
func (c *Client) GetGroups(ctx context.Context, opts *GetGroupsOptions) (*GroupsResponse, error)
GetGroups retrieves groups based on the provided options.
func (*Client) GetPrinter ¶
GetPrinter retrieves details for a specific printer.
func (*Client) GetPrinters ¶
func (c *Client) GetPrinters(ctx context.Context, opts *GetPrintersOptions) (*PrintersResponse, error)
GetPrinters retrieves the list of available printers with pagination.
func (*Client) GetRateLimitInfo ¶
GetRateLimitInfo returns the current rate limit status.
func (*Client) GetTenantID ¶
GetTenantID returns the tenant ID.
func (*Client) GetTenants ¶
func (c *Client) GetTenants(ctx context.Context) (*TenantsResponse, error)
GetTenants retrieves the list of accessible tenants for the authenticated client. This is typically used when a client has access to multiple tenants.
func (*Client) GetUsers ¶
func (c *Client) GetUsers(ctx context.Context, opts *GetUsersOptions) (*UsersResponse, error)
GetUsers retrieves users based on the provided options.
func (*Client) PrintData ¶
func (c *Client) PrintData(ctx context.Context, printerID, title string, data []byte, pdl string, options *PrintOptions) error
PrintData prints raw data using Printix.
func (*Client) PrintFile ¶
func (c *Client) PrintFile(ctx context.Context, printerID, title, filePath string, options *PrintOptions) error
PrintFile prints a file using Printix.
func (*Client) RemoveGroupMember ¶
RemoveGroupMember removes a user from a group.
func (*Client) SetTenant ¶
SetTenant sets the active tenant for subsequent API calls. This is useful when the client has access to multiple tenants.
func (*Client) UpdateGroup ¶
UpdateGroup updates an existing group.
func (*Client) UpdateUser ¶
UpdateUser updates an existing user.
type ColorOption ¶
ColorOption represents a color option.
type CompleteUploadRequest ¶
type CompleteUploadRequest struct {
JobID string `json:"jobId"`
}
CompleteUploadRequest represents the request to complete an upload.
type ContentType ¶
type ContentType struct { ContentType string `json:"content_type"` MinVersion string `json:"min_version,omitempty"` }
ContentType represents a supported content type.
type GetGroupsOptions ¶
GetGroupsOptions represents options for retrieving groups.
type GetJobsOptions ¶
GetJobsOptions represents options for retrieving jobs.
type GetPrintersOptions ¶
type GetPrintersOptions struct { Query string // Search query for printer names Page int // Page number (0-based) PageSize int // Number of printers per page }
GetPrintersOptions represents options for listing printers.
type GetUsersOptions ¶
type GetUsersOptions struct { Email string UserName string Active *bool GroupID string Page int PageSize int }
GetUsersOptions represents options for retrieving users.
type Group ¶
type Group struct { ID string `json:"id"` Name string `json:"name"` Description string `json:"description,omitempty"` Members []string `json:"members,omitempty"` Created string `json:"created,omitempty"` Updated string `json:"updated,omitempty"` Properties map[string]any `json:"properties,omitempty"` }
Group represents a Printix group.
type GroupsResponse ¶
type GroupsResponse struct { Response Groups []Group `json:"groups"` Page struct { Size int `json:"size"` TotalElements int `json:"totalElements"` TotalPages int `json:"totalPages"` Number int `json:"number"` } `json:"page"` }
GroupsResponse represents the response from listing groups.
type Job ¶
type Job struct { ID string `json:"id"` PrinterID string `json:"printerId"` PrinterName string `json:"printerName,omitempty"` Title string `json:"title"` Status string `json:"status"` Source string `json:"source,omitempty"` CreatedAt string `json:"createdAt,omitempty"` UpdatedAt string `json:"updatedAt,omitempty"` UserID string `json:"userId,omitempty"` UserName string `json:"userName,omitempty"` Properties map[string]any `json:"properties,omitempty"` }
Job represents a print job.
type JobsResponse ¶
JobsResponse represents the response from listing jobs.
type LocalizedString ¶
LocalizedString represents a localized string.
type MediaSizeOption ¶
type MediaSizeOption struct { HeightMicrons int `json:"heightMicrons"` WidthMicrons int `json:"widthMicrons"` Name string `json:"name"` IsContinuousFeed bool `json:"isContinuousFeed"` IsDefault bool `json:"isDefault"` }
MediaSizeOption represents a media size option.
type Option ¶
type Option func(*Client)
Option is a function that configures the client.
func WithAuthURL ¶
WithAuthURL sets a custom auth URL for the client.
func WithBaseURL ¶
WithBaseURL sets a custom base URL for the API.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
func WithTenantID ¶
WithTenantID sets the tenant ID for the client.
type PrintJob ¶
type PrintJob struct { PrinterID string `json:"-"` // Not sent in body, used in URL Title string `json:"title,omitempty"` User string `json:"user,omitempty"` PDL string `json:"PDL,omitempty"` // v1.1 properties Color *bool `json:"color,omitempty"` Duplex string `json:"duplex,omitempty"` // NONE, SHORT_EDGE, LONG_EDGE PageOrientation string `json:"page_orientation,omitempty"` // PORTRAIT, LANDSCAPE, AUTO Copies *int `json:"copies,omitempty"` MediaSize string `json:"media_size,omitempty"` Scaling string `json:"scaling,omitempty"` // NOSCALE, SHRINK, FIT TestMode bool `json:"-"` // Not sent to API UseV11 bool `json:"-"` // Use v1.1 API }
PrintJob represents a print job submission.
type PrintOptions ¶
type PrintOptions struct { Copies int `json:"copies,omitempty"` Color bool `json:"color,omitempty"` Duplex string `json:"duplex,omitempty"` // "none", "long-edge", "short-edge" PageRange string `json:"pageRange,omitempty"` Orientation string `json:"orientation,omitempty"` // "portrait", "landscape" }
PrintOptions represents print job options.
type Printer ¶
type Printer struct { ID string `json:"id"` Name string `json:"name"` ConnectionStatus string `json:"connectionStatus,omitempty"` PrinterSignID string `json:"printerSignId,omitempty"` Location string `json:"location,omitempty"` Model string `json:"model,omitempty"` Vendor string `json:"vendor,omitempty"` SerialNo string `json:"serialNo,omitempty"` Capabilities PrinterCapabilities `json:"capabilities,omitempty"` Links map[string]interface{} `json:"_links,omitempty"` }
Printer represents a Printix printer.
func (*Printer) SupportsContentType ¶
SupportsContentType checks if a printer supports a specific content type.
type PrinterCapabilities ¶
type PrinterCapabilities struct { Printer struct { MediaSize struct { Option []MediaSizeOption `json:"option,omitempty"` } `json:"media_size,omitempty"` SupportedContentType []ContentType `json:"supported_content_type,omitempty"` Copies struct { Default int `json:"default,omitempty"` Max int `json:"max,omitempty"` } `json:"copies,omitempty"` Color struct { Option []ColorOption `json:"option,omitempty"` } `json:"color,omitempty"` VendorCapability []VendorCapability `json:"vendor_capability,omitempty"` } `json:"printer,omitempty"` }
PrinterCapabilities represents printer capabilities.
type PrintersResponse ¶
type PrintersResponse struct { Links map[string]interface{} `json:"_links"` Success bool `json:"success"` Message string `json:"message"` Printers []Printer `json:"printers"` Page struct { Size int `json:"size"` TotalElements int `json:"totalElements"` TotalPages int `json:"totalPages"` Number int `json:"number"` } `json:"page"` }
PrintersResponse represents the HAL+JSON response from listing printers.
type Response ¶
type Response struct { Success bool `json:"success"` ErrorDescription string `json:"errorDescription,omitempty"` ErrorID string `json:"errorId,omitempty"` }
Response represents a generic API response.
type SubmitResponse ¶
type SubmitResponse struct { Response Job struct { ID string `json:"id"` CreateTime int64 `json:"createTime"` UpdateTime int64 `json:"updateTime"` Status string `json:"status"` OwnerID string `json:"ownerId"` ContentType string `json:"contentType"` Title string `json:"title"` } `json:"job"` UploadLinks []struct { URL string `json:"url"` Headers map[string]string `json:"headers"` Type string `json:"type"` // "Azure" or "GCP" } `json:"uploadLinks"` Links struct { Self struct { Href string `json:"href"` } `json:"self"` UploadCompleted struct { Href string `json:"href"` } `json:"uploadCompleted"` } `json:"_links"` }
SubmitResponse represents the response from submitting a print job.
type Tenant ¶
type Tenant struct { ID string `json:"id"` Name string `json:"name"` Description string `json:"description,omitempty"` Properties map[string]any `json:"properties,omitempty"` Links map[string]interface{} `json:"_links,omitempty"` }
Tenant represents a Printix tenant.
type TenantsResponse ¶
type TenantsResponse struct { Links map[string]interface{} `json:"_links"` Success bool `json:"success"` Message string `json:"message,omitempty"` Tenants []Tenant `json:"tenants"` }
TenantsResponse represents the HAL+JSON response from the root endpoint.
type User ¶
type User struct { ID string `json:"id"` Email string `json:"email"` Name string `json:"name,omitempty"` FullName string `json:"fullName,omitempty"` // For guest users UserName string `json:"userName,omitempty"` DisplayName string `json:"displayName,omitempty"` Role string `json:"role,omitempty"` // e.g., "GUEST_USER" PIN string `json:"pin,omitempty"` // 4-digit PIN for guest users Password string `json:"password,omitempty"` // Password for guest users Active bool `json:"active"` Created string `json:"created,omitempty"` Updated string `json:"updated,omitempty"` Groups []string `json:"groups,omitempty"` Properties map[string]any `json:"properties,omitempty"` }
User represents a Printix user.
type UsersResponse ¶
type UsersResponse struct { Response Users []User `json:"users"` Page struct { Size int `json:"size"` TotalElements int `json:"totalElements"` TotalPages int `json:"totalPages"` Number int `json:"number"` } `json:"page"` }
UsersResponse represents the response from listing users.
type VendorCapability ¶
type VendorCapability struct { ID string `json:"id"` DisplayName string `json:"display_name"` Type string `json:"type"` DisplayNameLocalized []LocalizedString `json:"display_name_localized,omitempty"` TypedValueCap map[string]interface{} `json:"typed_value_cap,omitempty"` }
VendorCapability represents a vendor-specific capability.
type WebhookEvent ¶
type WebhookEvent struct { Name string `json:"name"` // e.g., "RESOURCE.TENANT_USER.CREATE" Href string `json:"href"` // Link to the resource Time float64 `json:"time"` // Unix timestamp with milliseconds }
WebhookEvent represents a Printix webhook event.
func (*WebhookEvent) GetTimestamp ¶
func (e *WebhookEvent) GetTimestamp() time.Time
GetTimestamp returns the event timestamp as a time.Time.
func (*WebhookEvent) IsJobStatusChangeEvent ¶
func (e *WebhookEvent) IsJobStatusChangeEvent() bool
IsJobStatusChangeEvent checks if the event is a job status change event.
func (*WebhookEvent) IsUserCreateEvent ¶
func (e *WebhookEvent) IsUserCreateEvent() bool
IsUserCreateEvent checks if the event is a user creation event.
type WebhookJobStatusChange ¶
type WebhookJobStatusChange struct { JobID string `json:"jobId"` PrinterID string `json:"printerId"` Status string `json:"status"` Message string `json:"message,omitempty"` }
WebhookJobStatusChange represents a job status change event.
type WebhookPayload ¶
type WebhookPayload struct { Emitted float64 `json:"emitted"` // Unix timestamp when webhook was emitted Events []WebhookEvent `json:"events"` // Array of events }
WebhookPayload represents the full webhook payload.
func ParseWebhookPayload ¶
func ParseWebhookPayload(r *http.Request) (*WebhookPayload, error)
ParseWebhookPayload parses a webhook payload from the request body.
type WebhookValidator ¶
type WebhookValidator struct {
// contains filtered or unexported fields
}
WebhookValidator validates incoming webhook requests.
func NewWebhookValidator ¶
func NewWebhookValidator(sharedSecret string) *WebhookValidator
NewWebhookValidator creates a new webhook validator.
func (*WebhookValidator) SetOldSecret ¶
func (v *WebhookValidator) SetOldSecret(oldSecret string)
SetOldSecret sets the old shared secret for key rotation.
func (*WebhookValidator) ValidateRequest ¶
func (v *WebhookValidator) ValidateRequest(r *http.Request) error
ValidateRequest validates an incoming webhook request.