0.1.0 • Published 5 months ago

@tollbit/client v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

TollBit Node SDK

Use this SDK to interact with the suite of TollBit APIs. For more on our APIs and how to interact with TollBit, check out our docs

Constructor

Parameters:

NameTypeDescription
secretKeystringThe secret key for your organization
userAgentstringThe Agent ID you registered to access content through TollBit
organizationIDstringYour organization ID. Available through the developer dashboard

Example

import Tollbit from "@tollbit/client";
const instance = new Tollbit(
  process.env.SECRET_KEY,
  process.env.USER_AGENT,
  process.env.ORG_CUID,
);

Methods

generateToken

Description: Generates a token to interact with TollBit API endpoints

Parameters:

NameTypeDescription
urlstringThe specific page url for the intended content to access.
maxPriceMicrosint64The maximum price, in micro units, that you are willing to pay for this piece of content. Leaving this unset will default the field to 0, which will only allow you to retrieve free content.
currencystringThe three letter currency code. Only USD is supported at the moment.
licenseTypestringThe type of license that you are requesting the data with. Currently only supports ON_DEMAND_LICENSE.

Returns: string - Returns a token that can be used to query for content through TollBit endpoints

Example:

import Tollbit from "@tollbit/client";

const client = new Tollbit(
  process.env.SECRET_KEY,
  process.env.ORGANIZATION_ID,
  process.env.USER_AGENT,
);

const token = client.generateToken({
  url: "https://joshmayer.net/posts/bix",
  maxPriceMicros: 11000000,
  currency: "USD",
  licenseType: "ON_DEMAND_LICENSE",
});

getContentWithToken

Description: Takes in a token and queries for the corresponding content through the /dev/v1/content endpoint

Parameters:

NameTypeDescription
tokenstringA valid token generated by generateToken()

Returns: Promise<ContentResponse>

type ContentResponse = {
  content: Content;
  metadata: string;
  rate: RateResponse;
};

type Content = {
  header: string;
  main: string;
  footer: string;
};

Example:

import Tollbit from "@tollbit/client";

const client = new Tollbit(
  process.env.SECRET_KEY,
  process.env.ORGANIZATION_ID,
  process.env.USER_AGENT,
);

const token = client.generateToken({
  url: "https://joshmayer.net/posts/bix",
  maxPriceMicros: 11000000,
  currency: "USD",
  licenseType: "ON_DEMAND_LICENSE",
});

const content = await client.getContentWithToken(token);

getContent

Description: Generates a token and uses it to fetch content for a given URL from the /dev/v1/content endpoint

Parameters: | Name | Type | Description | | ---------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | url | string | The specific page url for the intended content to access. | | maxPriceMicros | int64 | The maximum price, in micro units, that you are willing to pay for this piece of content. Leaving this unset will default the field to 0, which will only allow you to retrieve free content. | | currency | string | The three letter currency code. Only USD is supported at the moment. | | licenseType | string | The type of license that you are requesting the data with. Currently only supports ON_DEMAND_LICENSE. |

Returns: Promise<ContentResponse>

type ContentResponse = {
  content: Content;
  metadata: string;
  rate: RateResponse;
};

type Content = {
  header: string;
  main: string;
  footer: string;
};

Example:

import Tollbit from "@tollbit/client";

const client = new Tollbit(
  process.env.SECRET_KEY,
  process.env.ORGANIZATION_ID,
  process.env.USER_AGENT,
);

const content = await client.getContent({
  url: "https://joshmayer.net/posts/bix",
  maxPriceMicros: 11000000,
  currency: "USD",
  licenseType: "ON_DEMAND_LICENSE",
});

getContent

Description: Retrieves the rate for accessing content from the target URL.

Parameters: | Name | Type | Description | | ---------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | url | string | The specific page url for the intended content to access. |

Returns: Promise<RateResponse>

type RateResponse = {
  priceMicros: number;
  currency: string;
  licenseType: string;
  licensePath: string;
  error: string;
};

Example:

import Tollbit from "@tollbit/client";

const client = new Tollbit(
  process.env.SECRET_KEY,
  process.env.ORGANIZATION_ID,
  process.env.USER_AGENT,
);

const response = await client.getRate("https://joshmayer.net/posts/bix");
1.0.0-alpha.2

5 months ago

1.0.0-alpha.1

5 months ago

1.0.0-alpha.0

5 months ago

0.1.0

11 months ago

0.0.3

11 months ago

0.0.2

12 months ago

0.0.1

12 months ago