printix

package module
v0.0.0-...-280d961 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

Printix Go Client

A Go client library for the Printix Cloud Print API.

Installation

go get github.com/enthus-golang/printix

Usage

Authentication

The client uses OAuth 2.0 Client Credentials flow for authentication. You'll need to obtain a client ID and client secret from your Printix Administrator dashboard.

import "github.com/enthus-golang/printix"

// Create a new client
client := printix.New(clientID, clientSecret)

// Use test environment
client := printix.New(clientID, clientSecret, printix.WithTestMode())

// Set tenant ID if known
client := printix.New(clientID, clientSecret, printix.WithTenantID("your-tenant-id"))
Basic Print Job
ctx := context.Background()

// Print a PDF file
err := client.PrintFile(ctx, printerID, "My Document", "/path/to/document.pdf", nil)
if err != nil {
    log.Fatal(err)
}

// Print with options (automatically uses v1.1 API)
options := &printix.PrintOptions{
    Copies:  2,
    Color:   true,
    Duplex:  "long-edge",
}
err = client.PrintFile(ctx, printerID, "My Document", "/path/to/document.pdf", options)
Advanced Print Job Submission

For more control over the print job submission, you can use the Submit method directly:

// v1.0 API (query parameters)
job := &printix.PrintJob{
    PrinterID: printerID,
    Title:     "My Document",
    User:      "john.doe",
    PDL:       "PCL5", // For non-PDF documents
}

// v1.1 API (JSON body with print settings)
copies := 2
job := &printix.PrintJob{
    PrinterID:       printerID,
    Title:          "My Document", 
    User:           "john.doe",
    UseV11:         true,
    Color:          &[]bool{true}[0],
    Duplex:         "LONG_EDGE", // NONE, SHORT_EDGE, LONG_EDGE
    PageOrientation: "PORTRAIT",  // PORTRAIT, LANDSCAPE, AUTO
    Copies:         &copies,
    MediaSize:      "A4",
    Scaling:        "FIT", // NOSCALE, SHRINK, FIT
}

submitResp, err := client.Submit(ctx, job)
if err != nil {
    log.Fatal(err)
}

// Upload document and complete
// ... (upload process)
Managing Printers
// Get all printers
printers, err := client.GetAllPrinters(ctx, "")
if err != nil {
    log.Fatal(err)
}

for _, printer := range printers {
    fmt.Printf("Printer: %s (ID: %s)\n", printer.Name, printer.ID)
}

// Find printer by name
printer, err := client.FindPrinterByName(ctx, "Office Printer")
if err != nil {
    log.Fatal(err)
}

// Get printer details
printer, err := client.GetPrinter(ctx, printerID)
if err != nil {
    log.Fatal(err)
}

// Check if printer supports a content type
if printer.SupportsContentType("application/pdf") {
    fmt.Println("Printer supports PDF")
}
Managing Jobs
// Get all jobs
jobs, err := client.GetJobs(ctx, nil)
if err != nil {
    log.Fatal(err)
}

// Get jobs with filters
opts := &printix.GetJobsOptions{
    PrinterID: "printer-123",
    Status:    printix.JobStatusPending,
    Limit:     10,
}
jobs, err := client.GetJobs(ctx, opts)

// Get specific job
job, err := client.GetJob(ctx, jobID)
if err != nil {
    log.Fatal(err)
}

// Cancel a job
err = client.CancelJob(ctx, jobID)

// Delete a job
err = client.DeleteJob(ctx, jobID)
Managing Users
// Get all users
usersResp, err := client.GetUsers(ctx, nil)
if err != nil {
    log.Fatal(err)
}

// Find user by email
opts := &printix.GetUsersOptions{
    Email: "user@example.com",
}
usersResp, err := client.GetUsers(ctx, opts)

// Create a new user (regular user)
user := &printix.User{
    Email:       "newuser@example.com",
    Name:        "New User",
    DisplayName: "New User",
    Active:      true,
}
createdUser, err := client.CreateUser(ctx, user)

// Create a guest user
guestUser := &printix.User{
    Email:    "guest@example.com",
    FullName: "Guest User",
    Role:     "GUEST_USER",
    PIN:      "1234",     // Optional 4-digit PIN
    Password: "password", // Optional password
}
createdGuest, err := client.CreateUser(ctx, guestUser)

// Update user
user.DisplayName = "Updated Name"
updatedUser, err := client.UpdateUser(ctx, user.ID, user)

// Delete user
err = client.DeleteUser(ctx, userID)
Managing Groups
// Get all groups
groupsResp, err := client.GetGroups(ctx, nil)
if err != nil {
    log.Fatal(err)
}

// Create a new group
group := &printix.Group{
    Name:        "Engineering",
    Description: "Engineering team",
}
createdGroup, err := client.CreateGroup(ctx, group)

// Add user to group
err = client.AddGroupMember(ctx, groupID, userID)

// Remove user from group
err = client.RemoveGroupMember(ctx, groupID, userID)

// Delete group
err = client.DeleteGroup(ctx, groupID)
Webhook Validation
// Create a webhook validator
validator := printix.NewWebhookValidator(sharedSecret)

// In your webhook handler
func webhookHandler(w http.ResponseWriter, r *http.Request) {
    // Validate the request
    if err := validator.ValidateRequest(r); err != nil {
        http.Error(w, "Invalid webhook", http.StatusUnauthorized)
        return
    }

    // Parse the webhook payload
    payload, err := printix.ParseWebhookPayload(r)
    if err != nil {
        http.Error(w, "Invalid payload", http.StatusBadRequest)
        return
    }

    // Process events
    for _, event := range payload.Events {
        if event.IsUserCreateEvent() {
            fmt.Printf("User created: %s\n", event.Href)
        }
        
        if event.IsJobStatusChangeEvent() {
            fmt.Printf("Job status change: %s\n", event.Href)
        }
        
        // Get event timestamp
        timestamp := event.GetTimestamp()
        fmt.Printf("Event time: %s\n", timestamp)
    }

    w.WriteHeader(http.StatusOK)
}
Advanced Usage
Custom HTTP Client
httpClient := &http.Client{
    Timeout: 60 * time.Second,
}
client := printix.New(clientID, clientSecret, printix.WithHTTPClient(httpClient))
Rate Limiting

The API has a rate limit of 100 requests per minute per user. The client exposes rate limit information:

remaining, reset := client.GetRateLimitInfo()
fmt.Printf("Remaining requests: %d, Reset at: %s\n", remaining, reset)
Multiple Tenants

If your client has access to multiple tenants:

// Get available tenants
tenantsResp, err := client.GetTenants(ctx)
if err != nil {
    log.Fatal(err)
}

// Set active tenant
client.SetTenant(tenantsResp.Tenants[0].ID)

Supported File Types

  • PDF (application/pdf) - Default, no PDL parameter needed
  • PCL (PCL5) - For PCL files, detected automatically by .pcl extension
  • PostScript (POSTSCRIPT) - For .ps files
  • XPS (XPS) - For .xps files
  • ZPL (ZPL) - For .zpl label printer files
  • Plain Text (text/plain) - For .txt files

The client automatically detects file types and sets the appropriate PDL parameter for non-PDF files.

Error Handling

All API errors include a success flag and error description:

jobs, err := client.GetJobs(ctx, nil)
if err != nil {
    // API errors will include description and error ID
    fmt.Printf("Error: %v\n", err)
}

Testing

The client supports test mode which uses the test environment:

client := printix.New(clientID, clientSecret, printix.WithTestMode())

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

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

View Source
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 New

func New(clientID, clientSecret string, opts ...Option) *Client

New creates a new Printix client.

func (*Client) AddGroupMember

func (c *Client) AddGroupMember(ctx context.Context, groupID, userID string) error

AddGroupMember adds a user to a group.

func (*Client) CancelJob

func (c *Client) CancelJob(ctx context.Context, jobID string) error

CancelJob cancels a print job.

func (*Client) CompleteUpload

func (c *Client) CompleteUpload(ctx context.Context, completeURL string) error

CompleteUpload notifies Printix that the document upload is complete.

func (*Client) CreateGroup

func (c *Client) CreateGroup(ctx context.Context, group *Group) (*Group, error)

CreateGroup creates a new group.

func (*Client) CreateUser

func (c *Client) CreateUser(ctx context.Context, user *User) (*User, error)

CreateUser creates a new user.

func (*Client) DeleteGroup

func (c *Client) DeleteGroup(ctx context.Context, groupID string) error

DeleteGroup deletes a group.

func (*Client) DeleteJob

func (c *Client) DeleteJob(ctx context.Context, jobID string) error

DeleteJob deletes a print job.

func (*Client) DeleteUser

func (c *Client) DeleteUser(ctx context.Context, userID string) error

DeleteUser deletes a user.

func (*Client) FindPrinterByName

func (c *Client) FindPrinterByName(ctx context.Context, name string) (*Printer, error)

FindPrinterByName finds a printer by its name.

func (*Client) GetAllPrinters

func (c *Client) GetAllPrinters(ctx context.Context, query string) ([]Printer, error)

GetAllPrinters retrieves all available printers by automatically handling pagination.

func (*Client) GetGroup

func (c *Client) GetGroup(ctx context.Context, groupID string) (*Group, error)

GetGroup retrieves details for a specific group.

func (*Client) GetGroups

func (c *Client) GetGroups(ctx context.Context, opts *GetGroupsOptions) (*GroupsResponse, error)

GetGroups retrieves groups based on the provided options.

func (*Client) GetJob

func (c *Client) GetJob(ctx context.Context, jobID string) (*Job, error)

GetJob retrieves details for a specific job.

func (*Client) GetJobs

func (c *Client) GetJobs(ctx context.Context, opts *GetJobsOptions) ([]Job, error)

GetJobs retrieves print jobs based on the provided options.

func (*Client) GetPrinter

func (c *Client) GetPrinter(ctx context.Context, printerID string) (*Printer, error)

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

func (c *Client) GetRateLimitInfo() (remaining int, reset time.Time)

GetRateLimitInfo returns the current rate limit status.

func (*Client) GetTenantID

func (c *Client) GetTenantID() string

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) GetUser

func (c *Client) GetUser(ctx context.Context, userID string) (*User, error)

GetUser retrieves details for a specific user.

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

func (c *Client) RemoveGroupMember(ctx context.Context, groupID, userID string) error

RemoveGroupMember removes a user from a group.

func (*Client) SetTenant

func (c *Client) SetTenant(tenantID string)

SetTenant sets the active tenant for subsequent API calls. This is useful when the client has access to multiple tenants.

func (*Client) Submit

func (c *Client) Submit(ctx context.Context, job *PrintJob) (*SubmitResponse, error)

Submit creates a new print job.

func (*Client) UpdateGroup

func (c *Client) UpdateGroup(ctx context.Context, groupID string, group *Group) (*Group, error)

UpdateGroup updates an existing group.

func (*Client) UpdateUser

func (c *Client) UpdateUser(ctx context.Context, userID string, user *User) (*User, error)

UpdateUser updates an existing user.

func (*Client) UploadDocument

func (c *Client) UploadDocument(ctx context.Context, uploadLink string, headers map[string]string, data []byte) error

UploadDocument uploads a document to the cloud storage.

type ColorOption

type ColorOption struct {
	Type    string `json:"type"`
	Default bool   `json:"default"`
}

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

type GetGroupsOptions struct {
	Name     string
	UserID   string
	Page     int
	PageSize int
}

GetGroupsOptions represents options for retrieving groups.

type GetJobsOptions

type GetJobsOptions struct {
	PrinterID string
	UserID    string
	Status    string
	Limit     int
	Offset    int
}

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

type JobsResponse struct {
	Response
	Jobs []Job `json:"jobs"`
}

JobsResponse represents the response from listing jobs.

type LocalizedString

type LocalizedString struct {
	Locale string `json:"locale"`
	Value  string `json:"value"`
}

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

func WithAuthURL(authURL string) Option

WithAuthURL sets a custom auth URL for the client.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets a custom base URL for the API.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithTenantID

func WithTenantID(tenantID string) Option

WithTenantID sets the tenant ID for the client.

func WithTestMode

func WithTestMode() Option

WithTestMode enables test mode 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

func (p *Printer) SupportsContentType(contentType string) bool

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.

Jump to

Keyboard shortcuts

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