Skip to content

interaapps/js-api-clients

Repository files navigation

InteraApps JS API Clients

Packages

Pastefy

npm i @interaapps/pastefy

Usage

import { PastefyClient } from '@interaapps/pastefy';
const client = new PastefyClient('api-token')

const paste = await client.getPaste('...')

Accounts

npm i @interaapps/accounts

Usage

import { AccountsClient } from '@interaapps/accounts';
const client = new AccountsClient('api-token')

const currentUser = await client.getCurrentUser('...')

Punyshort

npm i @interaapps/punyshort

Usage

import { PunyshortClient } from '@interaapps/punyshort';
const client = new PunyshortClient('api-token')

const shortenLink = await client.shortenLink('...')

Example: Login in browser and access pastefy pastes

npm i @interaapps/accounts @interaapps/pastefy

Usage

export const oauthClient = new InteraAppsOAuth2Client('jw7tpy97etwd0jn', undefined)

const redirectUri = oauthClient
    .urlBuilder()
    .setRedirectUri(window.location.protocol + '//' + window.location.host + '/login-app.html')
    .setResponseType('token')
    .setScopes(['user:read', 'pastefy|pastes', 'pastefy|folders'])
    .build()

window.location.href = redirectUri

login-app.html

const token = (new URLSearchParams(window.location.hash.replace('#', ''))).get('access_token')

const client = new AccountsClient(token)

const pastefy = new PastefyClient(await client.getKeyFor('pastefy'))

console.log('User pastes:', await pastefy.getUserPastes())