gcp-js

A Google Cloud Print JavaScript Client.

Usage no npm install needed!

<script type="module">
  import gcpJs from 'https://cdn.skypack.dev/gcp-js';
</script>

README

gcp-js

Work In Progress

A JavsScript Client for Google Cloud Print

The motivation behind this project is Google Cloud Print only supplies REST API for their service interfaces. Also Google API and documentation suck in general.

Installation

$ yarn add gcp-js

As an alternative to using npm, you can use unpkg.com to load our UMD bundle. Alfraid of introducing heavy-loaded bundle? Check out the bundle size at bundlephobia.com.

<script type="text/javascript" src="https://unpkg.com/gcp-js/dist/gcp.umd.js" />

Example

gcp-js does not handle authentication for you. You will need to setup either an OAuth Client or service account on Google Developers Console, then obtain the access token from your client.

To use service account, you should check out this post.

Below it is an example to authenticate with a service account, then print out a list of printers I own.

const { google } = require('googleapis');
const GCP = require('gcp-js');
const privateKey = require('./account.jwt.json');

// init google apis client
const client = await google.auth.getClient({
  credentials: privateKey,
  scopes: 'https://www.googleapis.com/auth/cloudprint',
});
const { token: accessToken } = await client.getAccessToken();

// init GCP instance
const cloudPrinter = new GCP({ accessToken });
const data = await cloudPrinter.search();
console.log(JSON.stringify(data));

Related