cloudprint

package
v0.0.0-...-358c88a Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2014 License: Apache-2.0, BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package cloudprint implements sending and receiving print jobs using Google Cloud Print (https://developers.google.com/cloud-print/).

Index

Constants

This section is empty.

Variables

View Source
var ErrUnclaimed = fmt.Errorf("printer not yet claimed")

Functions

func RandomID

func RandomID() (string, error)

RandomID returns a new random ID, for use as a proxy ID or printer ID.

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.

func AuthUser

func AuthUser(auth Auth) (Auth, error)

AuthUser launches a web browser to ask the user to authenticate and records the resulting token.

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 NewClient

func NewClient(auth Auth) (*Client, error)

NewClient returns a new client using the given auth information.

func (*Client) DeleteJob

func (c *Client) DeleteJob(j *Job) error

DeleteJob deletes the given print job.

func (*Client) Jobs

func (c *Client) Jobs(p *Printer) ([]*Job, error)

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

func (c *Client) Print(p *Printer, info *JobInfo, data []byte) (*Job, error)

Print creates a new print job printing to p with the given job information. The data is the raw PDF to print.

func (*Client) Printer

func (c *Client) Printer(id string) (*Printer, error)

Printer searches for the printer with the given ID.

func (*Client) Search

func (c *Client) Search(query string, all bool) ([]*Printer, error)

Search searches for printers the client can use. The query can be empty to return all printers. By default only printers that have been online recently are returned. To return all printers, pass all = true.

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 JobInfo

type JobInfo struct {
	Title        string
	Tags         []string
	Capabilities []byte
}

A JobInfo describes settings for creating a new print job.

type JobStatus

type JobStatus string
const (
	JobQueued     JobStatus = "QUEUED"
	JobInProgress JobStatus = "IN_PROGRESS"
	JobDone       JobStatus = "DONE"
	JobError      JobStatus = "ERROR"
)

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

func NewServer(auth Auth) (*Server, error)

NewServer returns a print server managing the printers owned by the user denoted by the auth token.

func (*Server) Auth

func (s *Server) Auth() 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

func (s *Server) DeletePrinter(p *Printer) error

DeletePrinter deletes the given printer.

func (*Server) Jobs

func (s *Server) Jobs(p *Printer) ([]*Job, error)

Jobs returns a list of jobs waiting to be printed on the given printer.

func (*Server) Printers

func (s *Server) Printers() ([]*Printer, error)

Printers returns a list of printers managed by this server.

func (*Server) ReadFile

func (s *Server) ReadFile(j *Job) ([]byte, error)

ReadFile reads the raw data to be printed by the given job.

func (*Server) UpdateJob

func (s *Server) UpdateJob(j *Job, status JobStatus, code int, message string) error

UpdateJob updates information about the given job. The only field that is stored back to the server is j.Status.

Jump to

Keyboard shortcuts

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