0.1.0 • Published 2 years ago

tenor-api-wrapper v0.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

tenor-api-wrapper

A Lightweight JavaScript wrapper library for the Tenor API, written in Typescript.

A tool used to access the TenorAPI from anywhere using NodeJS. This package supports both CommonJS and ESM.

If you wish to know which features are coming soon, please check out this project.

Installation

If you wish to install and use this package within your project, please make sure you are using the recommended node version or above before installing and are installing the latest version of this package.

# using NPM
npm install tenor-api-wrapper

# or using Yarn
yarn add tenor-api-wrapper

Usage

  • Attribution

    To start of with, to comply with Tenor's policies, you must properly attribute all content retrieved from Tenor. To do so, include one of the following three options:

    • Powered By Tenor ∙ Use this attribution during the GIF browsing experience.
    • Search Tenor ∙ Use this attribution as the placeholder text in your search box.
    • Via Tenor ∙ Use this attribution in the footer of a shared GIF.

You can find attribution logos at the following location: https://media.tenor.com/website/gifapi-assets/index.html

Assuming you have read the Guide above and have your API key, you can get stuck in with fetching content by doing the following:

// using ESM import
import TenorAPI from "tenor-api-wrapper";
const tenor = new TenorAPI("some-api-key");

// using CJS require
const TenorAPI = require("tenor-api-wrapper");
const tenor = new TenorAPI("some-api-key");

Then you can fetch posts made to Tenor.com as simple as:

// .fetch(by, term, options) => Promise<Result[]>
tenor.fetch('query', 'cats')
  .then(res => {
    // do something here...
  })
  .catch(console.error);

This will return a promise object array matching the fetch term and options provided, this would look like:

[
  {
    "id": "7831032585608380585",
    "debug_url": "https://tenor.googleapis.com/v2/search?q=cat&key=some-api-key&locale=en&limit=30",
    "source": "https://tenor.com/view/kitty-gif-25023528",
    "color": null,
    "data": {
      "title": null,
      "description": "Kitty GIF",
      "url: 'https://tenor.com/bQ9Vs.gif",
      "media": [
        {
          "key": "gif",
          "url": "https://c.tenor.com/bK1qpWGyQKkAAAAC/kitty.gif"
          "dims": [ 392, 498 ], // [ Width, Height ]
          "duration": null, // in Secs (only for mp4)
          "size": 5541234 // in Bytes
        },
        ...
      ],
      "hasCaption": false,
      "hasAudio": false, // (only for mp4)
      "flags": [ 'kitty' ],
      "tags": [ 'kitty' ],
      "timestamp": 1646164280.999305 // in Unix
    }
  }
]

Contributing

If you wish to contribute to this project, see the CONTRIBUTING.md file.