Documentation ¶
Overview ¶
Package cloudprint implements sending and receiving print jobs using Google Cloud Print (https://developers.google.com/cloud-print/).
Index ¶
- Variables
- func RandomID() (string, error)
- type Auth
- type Client
- type Job
- type JobInfo
- type JobStatus
- type OpenPrinter
- func (p *OpenPrinter) Auth() Auth
- func (p *OpenPrinter) ClaimPDF() ([]byte, error)
- func (p *OpenPrinter) ClaimURL() string
- func (p *OpenPrinter) ConfirmationPDF() ([]byte, error)
- func (p *OpenPrinter) Printer() *Printer
- func (p *OpenPrinter) Server() *Server
- func (p *OpenPrinter) VerifyClaim() error
- type Printer
- type PrinterInfo
- type PrinterStatus
- type Server
- func (s *Server) Auth() Auth
- func (s *Server) CreatePrinter(info *PrinterInfo) (*Printer, error)
- func (s *Server) DeletePrinter(p *Printer) error
- func (s *Server) Jobs(p *Printer) ([]*Job, error)
- func (s *Server) Printers() ([]*Printer, error)
- func (s *Server) ReadFile(j *Job) ([]byte, error)
- func (s *Server) UpdateJob(j *Job, status JobStatus, code int, message string) error
Constants ¶
This section is empty.
Variables ¶
var ErrUnclaimed = fmt.Errorf("printer not yet claimed")
Functions ¶
Types ¶
type Auth ¶
type Auth struct { // ClientID and ClientSecret identify the client using this code. // They are obtained from the Google APIs Console // (https://code.google.com/apis/console). // These fields are always required. APIClientID string APIClientSecret string // ProxyID identifies a particular server, which might serve multiple printers. // This field is required for servers only. // A ProxyID can be generated using RandomID. ProxyID string // Token is an OAuth 2 token giving permission to manage or // print to a Google account's printers. // TokenUser is the email address of the corresponding email address. // XMPPJID is the XMPP Jabber ID to use when polling for new print jobs. // It overrides TokenUser and is set only when using Auths generated // by CreateOpenPrinter. Token oauth.Token TokenUser string XMPPJID string }
An Auth is an authentication token that can be used to act as a print server or print client.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client can send print jobs to Google Cloud Print and manage those jobs.
func (*Client) Jobs ¶
Jobs returns a list of jobs waiting to be printed. If p is not nil, the list is restricted to jobs sent to the given printer.
func (*Client) Print ¶
Print creates a new print job printing to p with the given job information. The data is the raw PDF to print.
type Job ¶
type Job struct { ID string PrinterID string PrinterName string OwnerID string Title string Pages int64 CreateTime time.Time UpdateTime time.Time Status string FileURL string TicketURL string PrinterType string ContentType string ErrorCode string Tags []string }
A Job represents a document sent to be printed. The fields provide a snapshot of the job metadata.
type OpenPrinter ¶
type OpenPrinter struct {
// contains filtered or unexported fields
}
An OpenPrinter is a printer created without an authenticated Google account and therefore without an owner. A prospective owner claims the printer on the web using the claim URL, after which the printer implementation can obtain a credential corresponding to a one-printer server.
func CreateOpenPrinter ¶
func CreateOpenPrinter(auth Auth, info *PrinterInfo) (*OpenPrinter, error)
CreateOpenPrinter registers a new open printer with Google.
Only the ClientID, ClientSecret, and ProxyID fields need to be set in auth. The Token and TokenUser fields in the auth are ignored.
func (*OpenPrinter) Auth ¶
func (p *OpenPrinter) Auth() Auth
Auth returns a credential that can be used to manage this printer in future invocations of the program.
Auth must be called only after VerifyClaim has succeeded.
func (*OpenPrinter) ClaimPDF ¶
func (p *OpenPrinter) ClaimPDF() ([]byte, error)
ClaimPDF returns the content of a PDF of instructions that can be printed and given to a prospective owner to claim the printer.
func (*OpenPrinter) ClaimURL ¶
func (p *OpenPrinter) ClaimURL() string
ClaimURL returns a URL that a prospective owner can visit to claim the printer.
func (*OpenPrinter) ConfirmationPDF ¶
func (p *OpenPrinter) ConfirmationPDF() ([]byte, error)
ConfirmationPDF returns the content of a PDF that can be printed to confirm to the owner that the printer has been claimed.
func (*OpenPrinter) Printer ¶
func (p *OpenPrinter) Printer() *Printer
Printer returns information about the newly created printer. This method is only a convenience: the returned printer is the (only) one that would be returned by p.Server().Printers().
Printer must be called only after VerifyClaim has succeeded.
func (*OpenPrinter) Server ¶
func (p *OpenPrinter) Server() *Server
Server returns a server that can manage the newly created printer. This method is only a convenience: the returned server is the one that would be returned by NewServer(p.Auth()).
Server must be called only after VerifyClaim has succeeded.
func (*OpenPrinter) VerifyClaim ¶
func (p *OpenPrinter) VerifyClaim() error
VerifyClaim checks that the printer has been claimed. If the printer is claimed, VerifyClaim returns no error. If the printer is unclaimed, VerifyClaim retruns ErrUnclaimed. It is possible for VerifyClaim to return other errors, such as in the case of network problems.
A side effect of verifying that claim is that Google creates a synthetic account that is only useful in a future call to NewServer, to manage just this one printer. The information about that account can be retrieved from the Auth, Printer, and Server methods after VerifyClaim succeeds.
type Printer ¶
type Printer struct { ID string Proxy string Name string DisplayName string DefaultDisplayName string Description string OwnerID string CreateTime time.Time AccessTime time.Time UpdateTime time.Time Status string CapsFormat string CapsHash string Tags []string GCPVersion string IsTOSAccepted bool Type string }
A Printer represents a Google Cloud Print printer. The fields provide a snapshot of the printer metadata.
type PrinterInfo ¶
type PrinterInfo struct { Name string // Capabilities describes the printer capabilties in PPD format. // If Capabilities is nil, a basic default will be assumed. Capabilities []byte }
A PrinterInfo describes settings for creating a new printer.
type PrinterStatus ¶
type PrinterStatus string
const ( PrinterOnline PrinterStatus = "ONLINE" PrinterUnknown PrinterStatus = "UNKNOWN" PrinterOffline PrinterStatus = "OFFLINE" PrinterDormant PrinterStatus = "DORMANT" )
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
A Server can manage one or more Google Cloud Print printers.
func NewServer ¶
NewServer returns a print server managing the printers owned by the user denoted by the auth token.
func (*Server) Auth ¶
Auth returns an auth token that can be passed to NewServer to reconnect to the server.
func (*Server) CreatePrinter ¶
func (s *Server) CreatePrinter(info *PrinterInfo) (*Printer, error)
CreatePrinter creates a new printer. The server must be associated with a real Google account, meaning that it must have been created using NewServer with an auth returned by UserAuth. (Servers created using the auth returned by creating an open printer are limited to that one printer.)
func (*Server) DeletePrinter ¶
DeletePrinter deletes the given printer.