1.0.2 • Published 3 months ago

@william-pack/googleapis v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

GoogleAPI Library

Features

  • Google Drive API v3 support
  • Google Realtime Database support
  • Uses fetch for HTTP requests
  • Supports caching access tokens

Installation

Install via npm:

npm install @william-pack/googleapis

or using bun:

bun add @william-pack/googleapis

Usage

Import the Library

ESM

import { GoogleAuth } from "@william-pack/googleapis";

CommonJS

const { GoogleAuth } = require("@william-pack/googleapis");

Initialize API

Support Google Service Account only

const auth = new GoogleAuth({
    credential: {
        project_id: "your_project_id",
        private_key: "your_private_key",
        client_email: "your_client_email"
    }
});

Google Drive API

import { GoogleDrive } from "@william-pack/googleapis";
const drive = new GoogleDrive( auth, ['your_google_drive_folder_id'] );

Create a File

const file = new File(["Hello World"], "hello.txt", { type: "text/plain" });
await drive.create( file );
// return id: string

Remove a File

await drive.remove("your_file_id");
// return file is removed: true | false

Find All Files

await drive.findAll();
// return files: { id:string, name: string }[]

Google Realtime Database API

import { GoogleDatabase } from "@william-pack/googleapis";
const database = new GoogleDatabase( auth, "your_database_url" );

Create Data

await database.create("/path/to/data", { key: "value" });
// return your data

type save data

await database.create<{ key: type }>("/path/to/data", { username:"..." })

Remove Data

await database.remove("/path/to/data");
// return data is removed: true | false

Find All Data

await database.findAll("/path/to/data");
// reurn data

type save response

await database.findAll<{ key: type }>("/path/to/data");

Query Data

await database.query("/path/to/data", {
    orderBy: "your_data_key",
    equalTo: "your_data_value"
});
// return data

type save response

await database.query<{ key: type }>("/path/to/data", {
    orderBy: "your_data_key",
    equalTo: "your_data_value"
});

Transaction

await database.transaction("/path/to/data", ( currentData ) => {
    return { ...currentData, updatedKey: "newValue" };
});
// return data

type save data

await database.transaction<{ key: type }>("/path/to/data", ( currentData ) => {
    return { ...currentData, updatedKey: "newValue" };
});

Repository

GitHub Repository

License

This project is licensed under the MIT License.

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago