Home Identifier Source Test Repository
import BufferClient from 'buffer-node-api/src/client.js'
public class | source

BufferClient

Static Method Summary

Static Public Methods
public static

getAuthorizationUrl(client_id: String, redirect_url: String): *

Gets the authorization URL for the current app

Constructor Summary

Public Constructor
public

constructor(params: String, callback: Function)

Builds the BufferClient class

Member Summary

Public Members
public

The OAuth2 client that will be used to automatically authenticate API URLs

public

The Buffer configuration retrieved from the /info/configuration.json endpoint

public

A promise that will return after the BufferClient instance has been built

Method Summary

Public Methods
public

Revokes access for the Buffer Client to access the API on behalf of the currently logged in user

public

get(endpoint: String, params: Object, callback: Function)

Queries an API endpoint using the GET method

public

getAccessToken(access_token: String, callback: Function)

Gets a permanent access token when authenticating the user.

public

Retrieves the current Buffer configuration

public

getProfile(profile_id: String): Object

Returns a profile object with a given ID.

public

getProfiles(callback: Function)

Gets a list of profiles associated with the authenticated user

public

post(endpoint: String, params: Object, callback: Function)

Queries an API endpoint using the POST method

Static Public Methods

public static getAuthorizationUrl(client_id: String, redirect_url: String): * source

Gets the authorization URL for the current app

Params:

NameTypeAttributeDescription
client_id String

The client ID you were assigned when registering your Buffer application

redirect_url String

The redirect URL you set when registering your Buffer application

Return:

*

Public Constructors

public constructor(params: String, callback: Function) source

Builds the BufferClient class

Params:

NameTypeAttributeDescription
params String

The access token associated with the registered app

params.authenticated Boolean
  • optional

Flag to determine whether the user has been authenticated or not. If false, a long-lived access token will be generated and assigned upon instantiation.

params.client_id String

The client ID of your Buffer application

params.client_secret String

The client secret of your Buffer application

params.access_token String

The access token for the user. If the authentication parameter is false, this will be overwritten by the getAccessToken method.

params.redirect_url String

The redirection URL for your Buffer application

callback Function
  • optional

The callback to run when the request has been fulfilled

Example:

Simple instantiation, no authentication needed. E.g. for a user that has already authenticated their account
new BufferClient({
  access_token: '<your_access_token>',
  client_id: '<your_client_id>',
  client_secret: '<your_client_secret>',
  redirect_url: '<your_redirection_url>'
});
Force access_token generation with the `authentication` flag
new BufferClient({
  access_token: '<your_access_token>',
  client_id: '<your_client_id>',
  client_secret: '<your_client_secret>',
  redirect_url: '<your_redirection_url>',
  authenticated: false
}, function (err, res) {
  // Do something here
});

Public Members

public client: Object source

The OAuth2 client that will be used to automatically authenticate API URLs

public config: Object source

The Buffer configuration retrieved from the /info/configuration.json endpoint

public promise: Promise source

A promise that will return after the BufferClient instance has been built

Public Methods

public deauthorizeUser(callback: Function) source

Revokes access for the Buffer Client to access the API on behalf of the currently logged in user

Params:

NameTypeAttributeDescription
callback Function

The callback to run when the request has been fulfilled

public get(endpoint: String, params: Object, callback: Function) source

Queries an API endpoint using the GET method

Params:

NameTypeAttributeDescription
endpoint String

The API endpoint to query. This should not be the full API URL. Example: 'users.json'

params Object

A list of params to be appended to the URL. If omitted, the default Buffer API attributes will be used.

callback Function

The callback to run when the request has been fulfilled

Example:

Using the optional `params` parameter:
this.get('profiles/4eb854340acb04e870000010/updates/sent.json', {
	page: 2,
	count: 100
}, function (err, res) {
	// Do something
});
Omitting the optional `params` parameter
this.get('profiles/4eb854340acb04e870000010/updates/sent.json', function (err, res) {
	// Do something
});

public getAccessToken(access_token: String, callback: Function) source

Gets a permanent access token when authenticating the user.

Params:

NameTypeAttributeDescription
access_token String

The temporary access token assigned when passing through the OAuth gateway

callback Function

The callback to run when the request has been fulfilled

public getConfiguration(callback: Function) source

Retrieves the current Buffer configuration

Params:

NameTypeAttributeDescription
callback Function

The callback to run when the request has been fulfilled

Example:

// ...
client.getConfiguration(function (err, res) {
  // Do something
});

public getProfile(profile_id: String): Object source

Returns a profile object with a given ID. Note that this does not query the API, so a list of profiles must have been retrieved beforehand.

Params:

NameTypeAttributeDescription
profile_id String

The ID of the profile to retrieve

Return:

Object

The queried profile object

public getProfiles(callback: Function) source

Gets a list of profiles associated with the authenticated user

Params:

NameTypeAttributeDescription
callback Function

The callback to run when the request has been fulfilled

public post(endpoint: String, params: Object, callback: Function) source

Queries an API endpoint using the POST method

Params:

NameTypeAttributeDescription
endpoint String

The API endpoint to query. This should not be the full API URL. Example: 'users.json'

params Object

A list of params to be appended to the URL. If omitted, the default Buffer API attributes will be used.

callback Function

The callback to run when the request has been fulfilled

Example:

Using the optional `params` parameter:
this.post('profiles/4eb854340acb04e870000010/schedules/update.json', { ... }, function (err, res) {
	// Do something
});
Omitting the optional `params` parameter
this.post('user/deauthorize.json', function (err, res) {
	// Do something
});