0.1.0-alpha.8 • Published 5 years ago

gcp-js v0.1.0-alpha.8

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

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