torchprint

package module
v0.0.0-...-05894f7 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: MIT Imports: 12 Imported by: 0

README

torchprint

CLI and library to manage your printer job queue in Pharos Print Center (for GNU/Linux, Windows, MacOS)

Disclaimer: this project is not affiliated or endorsed by NYU or Pharos.

The API is reverse engineered from NYU Pharos Print Center web interface and may not work on all Pharos Print Center systems. (it's fair use)

CLI

Why

Because there's no Pharos Popup installer for GNU/Linux. (also it's proprietary)

Usage

  • Login
    • torchprint login then follow prompt
  • Add a document (pdf, doc, txt, etc) to printer job queue
    • torchprint add [file-to-print]
    • --side single or --side double. Default is double
    • --color for color, otherwise monochrome.
  • View printer job queue
    • torchprint ls
  • Delete a job from queue
    • torchprint rm [job-id]
    • Delete everything with --all
  • Edit a job in queue (coming soon)

Don't worry, you can always use torchprint help. (And no it won't call the help desk for you)

Example

$ torchprint login
Enter username: johndoe
Enter password:
success: userid deadbeef balance 4.20

$ torchprint add pirated_textbook.pdf
success: /printjobs/c29tZXRoaW5nLXlvdS13YW50LXRvLXByaW50LW1heWJlLXBpcmF0ZWQtc3R1ZmY= pirated_textbook.pdf Queued

$ torchprint ls
JOB ID                                                             NAME                SUBMISSION TIME             STATE
c29tZXRoaW5nLXlvdS13YW50LXRvLXByaW50LW1heWJlLXBpcmF0ZWQtc3R1ZmY=   test.txt            2018-10-29T18:12:07-04:00   Queued

$ torchprint rm c29tZXRoaW5nLXlvdS13YW50LXRvLXByaW50LW1heWJlLXBpcmF0ZWQtc3R1ZmY=
/printjobs/c29tZXRoaW5nLXlvdS13YW50LXRvLXByaW50LW1heWJlLXBpcmF0ZWQtc3R1ZmY= 200

Building

$ go get -u github.com/libertylocked/torchprint/cmd/torchprint
$ $GOPATH/bin/torchprint version

FAQ

Can I use it for my school?

It has not been tested outside NYU, but if your school uses Pharos, chances are it will work. Just fork it and change the baseURL in api.go.

Can I save my username and password so I don't have to login every time?

It is not recommended for security reasons, but yes you can. Run login command with --save will save your username and password in cleartext in config file.

Where is config file stored?

It is stored in one of the two places

  • $HOME/.config/torchprint/.torchprint.json
  • $HOME/.torchprint.json

Library

Example

import (
	"fmt"

	"github.com/libertylocked/torchprint"
)

func main() {
	// To get your user ID and token
	logon, token, _ := torchprint.NewAPI("").SetUserPass("username", "password")
	userID := logon.Identifier // User ID

	// To make requests using User ID and Session Token
	api := torchprint.NewAPI(userID).SetToken(token)
	// You can also make requests using User ID and Username:Password (instead of token)
	// api := torchprint.NewAPI(userID).SetUserPass("username", "password")

	// View all printjobs in queue
	api.GetPrintJobs()
	// Upload a document and create a printjob
	api.AddPrintJob("/home/liberty/Documents/pirated_textbook.pdf", torchprint.FinishingOptions{
		Mono:            true,
		Duplex:          true,
		PagesPerSide:    1,
		Copies:          1,
		DefaultPageSize: "Letter",
	})
}

API Documentation

None ;)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	UserID string // required
	// contains filtered or unexported fields
}

API is printer API wrapper

func NewAPI

func NewAPI(userID string) *API

NewAPI returns a new print API

func (*API) AddPrintJob

func (api *API) AddPrintJob(filename string, options FinishingOptions) (*PrintJobItem, error)

AddPrintJob adds a printjob

func (*API) DeletePrintJobs

func (api *API) DeletePrintJobs(locations []PrintJobDeleteLocation) ([]*PrintJobDeleteStatus, error)

DeletePrintJobs removes printjobs from job queue

func (*API) GetDevice

func (api *API) GetDevice(deviceID int) (*Device, error)

GetDevice gets info about a printing device

func (*API) GetDevices

func (api *API) GetDevices(skip, pageSize int) (*DevicesResponseData, error)

GetDevices gets printing devices

func (*API) GetJSON

func (api *API) GetJSON(url string, params interface{}, successDat interface{}) (*http.Response, error)

GetJSON populates a struct with JSON response data

func (*API) GetPrintJobs

func (api *API) GetPrintJobs() (*PrintJobsResponseData, error)

GetPrintJobs sends a request to view print jobs

func (*API) GetTransactions

func (api *API) GetTransactions(skip, pageSize int) (*TransactionResponseData, error)

GetTransactions returns transaction history

func (*API) Logon

func (api *API) Logon() (respData *LogonResponseData, token string, err error)

Logon sends a request to get token. Credential must be set in API object

func (*API) PostJSON

func (api *API) PostJSON(url string, params interface{}, postBody interface{}, successDat interface{}) (*http.Response, error)

PostJSON posts a JSON and populates a struct with JSON response

func (*API) SetCredential

func (api *API) SetCredential(credential string) *API

SetCredential set logon credentials

func (*API) SetToken

func (api *API) SetToken(token string) *API

SetToken set Pharos user token. If token is set, credential will be ignored

func (*API) SetUserPass

func (api *API) SetUserPass(user, pass string) *API

SetUserPass set logon credentials from username and password

type Device

type Device struct {
	Identifier   string `json:"Identifier"`
	Name         string `json:"Name"`
	Description  string `json:"Description"`
	Make         string `json:"Make"`
	Model        string `json:"Model"`
	Capabilities struct {
		DuplexSupported bool `json:"DuplexSupported"`
		ColorSupported  bool `json:"ColorSupported"`
	} `json:"Capabilities"`
	Server       string    `json:"Server"`
	DeviceGroups []string  `json:"DeviceGroups"`
	Active       bool      `json:"Active"`
	LastModified time.Time `json:"LastModified"`
	Location     string    `json:"Location"`
}

Device a printing device

type DevicesResponseData

type DevicesResponseData struct {
	PreviousPageLink string   `json:"PreviousPageLink"`
	NextPageLink     string   `json:"NextPageLink"`
	Count            int      `json:"Count"`
	Items            []Device `json:"Items"`
}

DevicesResponseData is response of devices request

type FinishingOptions

type FinishingOptions struct {
	Mono            bool   `json:"Mono"`
	Duplex          bool   `json:"Duplex"`
	PagesPerSide    int    `json:"PagesPerSide"`
	Copies          int    `json:"Copies"`
	DefaultPageSize string `json:"DefaultPageSize"` // Letter or something
	PageRange       string `json:"PageRange"`
}

FinishingOptions finishing options of a printjob

type LogonRequestData

type LogonRequestData struct {
	KeepMeLoggedIn        string `url:"KeepMeLoggedIn"`
	IncludePrintJobs      string `url:"includeprintjobs"`
	IncludeDeviceActivity string `url:"includedeviceactivity"`
	IncludePrivileges     string `url:"includeprivileges"`
	IncludeCostCenters    string `url:"includecostcenters"`
}

LogonRequestData is query params of logon request

type LogonResponseData

type LogonResponseData struct {
	Identifier     string   `json:"Identifier"` // this is user ID!
	LogonID        string   `json:"LogonId"`
	DisplayName    string   `json:"DisplayName"`
	EmailAddresses []string `json:"EmailAddresses"`
	Roles          []string `json:"Roles"`
	Active         bool     `json:"Active"`
	Alias          string   `json:"Alias"`
	AccountType    string   `json:"AccountType"`
	Balance        struct {
		Amount string `json:"Amount"`
		Purses []struct {
			Name   string `json:"Name"`
			Amount string `json:"Amount"`
		} `json:"Purses"`
	} `json:"Balance"`
	Location      string `json:"Location"`
	Group         string `json:"Group"`
	Comment       string `json:"Comment"`
	Custom1       string `json:"Custom1"`
	Custom2       string `json:"Custom2"`
	OfflineAmount string `json:"OfflineAmount"`
	OfflineLimit  string `json:"OfflineLimit"`
	ID            int    `json:"Id"`
}

LogonResponseData is the response of logon request

type PrintJobDeleteLocation

type PrintJobDeleteLocation struct {
	Location string `json:"Location"`
}

PrintJobDeleteLocation is an entry in delete request array

type PrintJobDeleteRequestData

type PrintJobDeleteRequestData struct {
	PrintJobs []PrintJobDeleteLocation `json:"PrintJobs"`
}

PrintJobDeleteRequestData is the request data to delete printjobs

type PrintJobDeleteStatus

type PrintJobDeleteStatus struct {
	Location string `json:"Location"`
	Status   int    `json:"Status"`
}

PrintJobDeleteStatus the status response of a delete request

type PrintJobItem

type PrintJobItem struct {
	ProtectedBy       string    `json:"ProtectedBy"`
	Owner             string    `json:"Owner"`
	Name              string    `json:"Name"`
	ApplicationName   string    `json:"ApplicationName"`
	JobFormat         string    `json:"JobFormat"`
	SubmissionTimeUtc time.Time `json:"SubmissionTimeUtc"`
	Stats             struct {
		SizeInKb        int `json:"SizeInKb"`
		TotalPages      int `json:"TotalPages"`
		TotalBWPages    int `json:"TotalBWPages"`
		TotalColorPages int `json:"TotalColorPages"`
		TotalSheets     int `json:"TotalSheets"`
	} `json:"Stats"`
	FinishingOptions FinishingOptions `json:"FinishingOptions"`
	// SupportedFinishingOptions FinishingOptions `json:"SupportedFinishingOptions"` // its a bool map, dont need for now
	DeviceGroup          string    `json:"DeviceGroup"`
	PrinterName          string    `json:"PrinterName"`
	DocumentType         string    `json:"DocumentType"`
	AllowableActions     string    `json:"AllowableActions"`
	PrintState           string    `json:"PrintState"` // this is pretty important
	LastModified         time.Time `json:"LastModified"`
	Location             string    `json:"Location"`
	RawPageCounterResult string    `json:"RawPageCounterResult"`
	SubmissionTimeDelta  float64   `json:"SubmissionTimeDelta"`
	Cost                 string    `json:"Cost"`
}

PrintJobItem is an item in printjobs

type PrintJobsResponseData

type PrintJobsResponseData struct {
	PreviousPageLink string         `json:"PreviousPageLink"`
	NextPageLink     string         `json:"NextPageLink"`
	Count            int            `json:"Count"`
	Items            []PrintJobItem `json:"Items"`
}

PrintJobsResponseData is the response of view printjob request

type Transaction

type Transaction struct {
	Identifier      int       `json:"Identifier"`
	User            string    `json:"User"`
	Time            time.Time `json:"Time"`
	Amount          string    `json:"Amount"`
	Device          string    `json:"Device"`
	TransactionType string    `json:"TransactionType"`
	Description     string    `json:"Description"`
	Printer         string    `json:"Printer,omitempty"`
	Pages           int       `json:"Pages,omitempty"`
	Sheets          int       `json:"Sheets,omitempty"`
	Application     string    `json:"Application,omitempty"`
	JobName         string    `json:"JobName,omitempty"`
	Attributes      string    `json:"Attributes,omitempty"`
	Cashier         string    `json:"Cashier,omitempty"`
	Purse           string    `json:"Purse,omitempty"`
}

Transaction is a tx in pharos (print, credit, etc)

type TransactionResponseData

type TransactionResponseData struct {
	PreviousPageLink string        `json:"PreviousPageLink"`
	NextPageLink     string        `json:"NextPageLink"`
	Count            int           `json:"Count"`
	Items            []Transaction `json:"Items"`
}

TransactionResponseData response to get transactions

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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