An open API service indexing awesome lists of open source software.

https://github.com/yhirose/gapi-ez

JavaScript library for easy accessing to the Google APIs Client Library for JavaScript
https://github.com/yhirose/gapi-ez

Last synced: about 1 month ago
JSON representation

JavaScript library for easy accessing to the Google APIs Client Library for JavaScript

Awesome Lists containing this project

README

          

gapi-ez
=======

JavaScript library for easy accessing to the [Google APIs Client Library for JavaScript](https://developers.google.com/api-client-library/javascript/)

`gapiEz` global object has the following methods:

* [gapiEz.authorize(params) -> token](#authorize)
* [gapiEz.load(name, version) -> api](#load)
* [gapiEz.logout()](#logout)

These methods return a `Promise` object instead of taking a callback function.

Setup
-----

```HTML

```

Examples
--------

### Authorize

```JS
gapiEz.authorize({
client_id: '[YOUR CLIENT ID]',
scope: '[SCOPE]',
immediate: true
})
.then(function () {
// authorized
})
.catch(function () {
// failed
});
```

### Load

```JS
gapiEz.load('calendar', 'v3').then(function (api) {
api.calendarList.list().then(function (resp) {
// succeeded
});
});
```

### Logout

```JS
gapiEz.logout().then(function () {
// succeeded
});
```

Sample
------

```HTML






var params = {
apiKey: '[YOUR API KEY]',
client_id: '[YOUR CLIENT ID]',
scope: ['https://www.googleapis.com/auth/calendar']
};

params.immediate = true;
gapiEz.authorize(params).then(function (token) {
$('input').val('logout').click(function () {
gapiEz.logout().then(function () {
$('#message').text('logout');
});
});
}, function () {
$('input').val('login').click(function () {
params.immediate = false;
gapiEz.authorize(params).then(function (token) {
gapiEz.load('calendar', 'v3').then(function (api) {
api.calendarList.list().then(function (resp) {
var s = '<h1>Calendars:</h1>';
resp.result.items.forEach(function (item) {
s += '<p>' + item.summary + '</p>';
});
$('#message').html(s);
});
});
});
});
});

```

References
----------


### gapiEz.authorize(params) -> token

#### Arguments:

| Name | Type | Description |
| ------ | ------ | ---------------------------------------------- |
| params | object | A key/value map of parameters for the request. |

##### `params` object:

| Name | Type | Description |
| --------- | ------------ | ---------------------------- |
| apiKey | string | The application's API key |
| client_id | string | The application's client ID. |
| scope | string/array | The auth scope or scopes |
| immediate | boolean | If true, then login uses "immediate mode", which means that the token is refreshed behind the scenes, and no UI is shown to the user. |

#### Result in Promise:

| Name | Type | Description |
| ----- | ------ | ---------------------- |
| token | object | OAuth 2.0 Token Object |


### gapiEz.load(name, version) -> api

#### Arguments:

| Name | Type | Description |
| ------- | ------ | ------------------------------- |
| name | string | The name of the API to load. |
| version | string | The version of the API to load. |

#### Result in Promise:

| Name | Type | Description |
| ---- | ------ | ----------------- |
| api | object | Google API object |


### gapiEz.logout()

#### Arguments:

None.

#### Result in Promise:

None.