3.1.0-alpha.0 • Published 7 years ago

@motionpicture/sskts-api-javascript-client v3.1.0-alpha.0

Weekly downloads
-
License
ISC
Repository
github
Last release
7 years ago

SSKTS API client library for Javascript

npm (scoped) CircleCI Coverage Status Dependency Status Known Vulnerabilities NSP Status npm

Javascript client library for using Sasaki APIs. Support for authorization and authentication with OAuth 2.0.

Table of Contents

Installation

This library is distributed on npm. In order to add it as a dependency, run the following command:

$ npm install @motionpicture/sskts-api-javascript-client

CommonJS

Include the library in your JavaScript file with

const sasaki = require("@motionpicture/sskts-api-javascript-client");

Browser

Include lib/browser.js in your page.

<script type="text/javascript" src="./node_modules/@motionpicture/sskts-api-javascript-client/lib/browser.js"></script>

Usage

Example: Creates a URL Shortener client and retrieves the long url of the given short url:

var sasaki = require('@motionpicture/sskts-api-javascript-client');
var event = sasaki.service.event({
    endpoint: 'endpoint'.
    auth: auth
});

var conditions = {
    day: '20170817',
    theater: '118'
};

event.url.searchIndividualScreeningEvent({
    searchConditions: conditions
}).then(function (events) {
    console.log('events:', events);
}).catch(function (err) {
    console.error(err);
});

Authorizing and authenticating

OAuth2 client

This client comes with an OAuth2 client that allows you to retrieve an access token and refreshes the token and retry the request seamlessly if you also provide an expiry_date and the token is expired.

In the following examples, you may need a CLIENT_ID, REDIRECT_URI and LOGOUT_URI. You can ask these to the provider.

For more information about OAuth2 and how it works, see here.

A complete sample application that authorizes and authenticates with the OAuth2 client is available at samples/browser/index.html.

Generating an OAuth2 client

redirect them to a consent page. To redirect them a consent page URL:

var sasaki = require('@motionpicture/sskts-api-javascript-client');

// generate a url that asks permissions for Sasai API scopes
var scopes = [
    'phone', 'openid', 'email', 'aws.cognito.signin.user.admin', 'profile',
    'https://IDENTIFIER/events.read-only'
];

var oauth2Client = new sasaki.auth.Implicit({
    domain: DOMAIN,
    clientId: CLIENT_ID,
    responseType: 'token',
    redirectUri: REDIRECT_URI,
    logoutUri: LOGOUT_URI,
    scope: scopes.join(' '),
    state: '12345'
});
Authorize
oauth2Client.authorize().then(function (credentials) {
    console.log('authorize result:', credentials);
}).catch(function (err) {
    console.error(err);
});
Setting service-level auth

You can set the auth as a service-level option.

Example: Setting a service-level auth option.

var sasaki = require('@motionpicture/sskts-api-javascript-client');

// generate a url that asks permissions for Sasai API scopes
var scopes = [
    'phone', 'openid', 'email', 'aws.cognito.signin.user.admin', 'profile',
    'https://IDENTIFIER/events.read-only'
];

var oauth2Client = new sasaki.auth.Implicit({
    domain: DOMAIN,
    clientId: CLIENT_ID,
    responseType: 'token',
    redirectUri: REDIRECT_URI,
    logoutUri: LOGOUT_URI,
    scope: scopes.join(' '),
    state: '12345'
});

oauth2Client.authorize().then(function (credentials) {
    console.log('authorize result:', credentials);

    var event = sasaki.service.event({
        endpoint: 'endpoint'.
        auth: oauth2Client
    });

    var conditions = {
        day: '20170817',
        theater: '118'
    };

    event.url.searchIndividualScreeningEvent({
        searchConditions: conditions
    }).then(function (events) {
        console.log('events:', events);
    }).catch(function (err) {
        console.error(err);
    });
}).catch(function (err) {
    console.error(err);
});
Manually refreshing access token

If you need to manually refresh the access_token associated with your OAuth2 client, make sure you have a refresh_token set in your credentials first and then call:

oauth2Client.refreshToken().then(function (result) {
    console.log('refreshToken result:', result);
}).catch(function (err) {
    console.error(err);
});

License

ISC

8.0.1

6 years ago

8.0.0

6 years ago

7.0.0

6 years ago

7.0.0-alpha.1

6 years ago

7.0.0-alpha.0

6 years ago

6.1.0

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

6.0.0-alpha.1

6 years ago

6.0.0-alpha.0

6 years ago

5.0.0

7 years ago

4.4.0-alpha.0

7 years ago

4.3.0

7 years ago

4.2.0

7 years ago

4.1.1

7 years ago

4.1.0

7 years ago

4.0.1

7 years ago

4.0.0-alpha.1

7 years ago

4.0.0-alpha.0

7 years ago

4.0.0

7 years ago

3.2.0-alpha.3

7 years ago

3.2.0-alpha.2

7 years ago

3.2.0-alpha.1

7 years ago

3.2.0-alpha.0

7 years ago

3.4.0-mocoin.1

7 years ago

3.3.1

7 years ago

3.4.0-mocoin.0

7 years ago

3.3.1-alpha.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.1.0-alpha.9

7 years ago

3.1.0-alpha.8

7 years ago

3.1.0-alpha.7

7 years ago

3.1.0-alpha.6

7 years ago

3.1.0-alpha.5

7 years ago

3.1.0-alpha.4

7 years ago

3.1.0-alpha.3

7 years ago

3.1.0-alpha.2

7 years ago

3.1.0-alpha.1

7 years ago

3.1.0-alpha.0

7 years ago

3.0.0

7 years ago

3.0.0-alpha.0

7 years ago

2.1.2

7 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.1.0-alpha.2

8 years ago

2.1.0-alpha.1

8 years ago

2.1.0-alpha.0

8 years ago

2.0.0

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

1.0.0-alpha.2

8 years ago

1.0.0-alpha.1

8 years ago

1.0.0-alpha.0

8 years ago