@tollbit/client v0.1.0
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:
Name | Type | Description |
---|---|---|
secretKey | string | The secret key for your organization |
userAgent | string | The Agent ID you registered to access content through TollBit |
organizationID | string | Your 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:
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: 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:
Name | Type | Description |
---|---|---|
token | string | A 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");
5 months ago
5 months ago
5 months ago
11 months ago
11 months ago
12 months ago
12 months ago