0.4.2 • Published 2 years ago

@miyajan/garoon-rest v0.4.2

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

garoon-rest

npm version

Rest API Client for Garoon

WIP.

Installation

1. Install with npm

This library is distributed on npm.

npm install @miyajan/garoon-rest

You can then use require or import to import the library.

// CommonJS
const { GaroonRestAPIClient } = require("@miyajan/garoon-rest");
// ES modules
import { GaroonRestAPIClient } from "@miyajan/garoon-rest";

2. UMD files (for browser environment)

This library also provides two Universal Module Definition (UMD) files:

After loading this, you can use GaroonRestAPIClient directly. In Garoon customization, please add this URL in "JavaScript and CSS customization" setting.

NOTE: The UMD links are using the latest tag to point to the latest version of the library. This pointer is unstable, it shifts as we release new versions. You should consider pointing to a specific version, such as 1.0.0.

Usage

Here is a sample code that retrieves a schedule event.

const client = new GaroonRestAPIClient({
  baseUrl: "https://example.cybozu.com/g",
  // Use password authentication
  auth: {
    username: process.env.GAROON_USERNAME,
    password: process.env.GAROON_PASSWORD,
  },
  // Use OAuth token authentication
  // auth: { oAuthToken: process.env.GAROON_OAUTH_TOKEN }

  // Use session authentication if `auth` is omitted (in browser only)
});

client.schedule
  .getEvent({ id: "1" })
  .then((resp) => {
    console.log(resp);
  })
  .catch((err) => {
    console.log(err);
  });

Parameters for GaroonRestAPIClient

NameTypeRequiredDescription
baseUrlStringConditionallyRequiredThe base URL for your Garoon environment.On cybozu.com, it must end with /g. (e.g. https://example.cybozu.com/g) If you use on-premise Garoon environment, it must end with grn.cgi or grn.exe (e.g. http://example.com/cgi-bin/cbgrn/grn.cgi) Required in Node.js environment. If you omit it in browser environment, the base URL will be determined from location.
authObjectConditionallyRequiredThe object for authentication. See Authentication.
basicAuthObjectIf your Garoon environment uses Basic authentication, please specify its username and password.
basicAuth.usernameStringThe username of Basic authentication.
basicAuth.passwordStringThe password of Basic authentication.
clientCertAuthObjectThis parameter is available only in Node.js environment.If your Garoon environment uses Client Certificate authentication, please specify the certificate file and password.
clientCertAuth.pfxBufferThe client certificate file. Required, unless you specify pfxFilePath.
clientCertAuth.pfxFilePathStringThe path to client certificate file. Required, unless you specify pfx.
clientCertAuth.passwordStringThe password of client certificate.
proxyObjectThis parameter is available only in Node.js environment.If you use a proxy, please specify its configuration.
proxy.hostStringThe host of the proxy server.
proxy.portNumberThe port of the proxy server.
proxy.authObjectIf the proxy server requires Basic authentication, please specify its username and password.
proxy.auth.usernameStringThe username of Basic authentication for the proxy server.
proxy.auth.passwordStringThe password of Basic authentication for the proxy server.

Authentication

The client supports three authentication methods:

  1. Password authentication
  2. OAuth authentication
  3. Session authentication

The required parameters inside auth are different by the methods. The client determines which method to use by passed parameters.

1. Parameters for Password authentication

NameTypeRequiredDescription
usernameStringYes
passwordStringYes

2. Parameters for OAuth authentication

NameTypeRequiredDescription
oAuthTokenStringYesAn OAuth access token you get through the OAuth process flow.

3. Session authentication

Supported in browser environment only. If you omit auth parameter, the client uses Session authentication.

Error Handling

See Error Handling

References

Contribution Guide

License

Disclaimer

This OSS is my own personal work and does not have any relationship with Cybozu Inc. or any other organization which I belong to.

0.4.1

2 years ago

0.4.2

2 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago