UNPKG

tenorjs

Version:

TenorJS is a lightweight NodeJS wrapper around the Tenor.com API.

103 lines (87 loc) 6.2 kB
## TenorJS v1.0.6 There's a [development branch](https://github.com/Jinzulen/TenorJS/tree/development) now! **--** Pushing everything into the [master branch]() was just insane and was simply not working out, so in order to organize things a bit and give myself some room to get real messy but maintain the neat outlook of the repo, 2 branches were necessary. Please, keep in mind that using the development branch for a tool in a production environment is **strongly not recommended**, this is because more often than not, changes will be made in the development branch that are not entirely complete, which means certain parts won't necessarily be functioning until a later time when I push an update to it that sorts out any related bugs/inconsistencies, so always use the master branch (which will always be tested and bug-free). ### 1. Library re-structure So, this may upset some people but the library has seen a full re-structure recently that affected a whole lot of stuff, most notably, function names and routes. The reason behind this massive re-structure was to make TenorJS easily maintainable by both me (the developer) and you (the user). The directories and files are now a lot more organized and neat, and contain very clear, very easily understood code that just simplifies everything for the both of us. The changes to the functions are as such (the changes in case-sensitivity are important and **will** break your app if you don't adjust your existing code): * Tenor.Search.query() **->** Tenor.Search.Query() * Tenor.Search.trending **->** Tenor.Trending.GIFs() * Tenor.Search.random() **->** Tenor.Search.Random() * Tenor.Search.category() **->** Tenor.Categories.Find() * Tenor.Search.categories() **->** Tenor.Categories.List() **-** [Learn more about changes made to categories.](https://github.com/Jinzulen/TenorJS/tree/development#22a-search) * Tenor.Search.trending_terms() **->** Tenor.Trending.Terms() * Tenor.Suggest.autocomplete **->** Tenor.Suggest.Autocomplete() * Tenor.Suggest.suggestions() **->** Tenor.Suggest.Suggestions() The changes to the overall app directories and files structure: * Before: ``` --> src/ -> index.js -> search.js -> suggest.js -> utilities.js -> index.js ``` * After: ``` --> src/ --> Methods/ --> Categories/ -> Find.js -> Tags.js --> Search/ -> Find.js -> Query.js -> Random.js --> Suggest/ -> Autocomplete.js -> Suggestions.js --> Trending/ -> GIFs.js -> Terms.js --> Tools/ -> Utilities.js -> Categories.js -> Search.js -> Suggest.js -> Trending.js -> index.js -> index.js ``` ### 2. Native Operations When I first released TenorJS, I made it clear in the code snippets of the *Usage & Guides* examples that there were certain operations I will probably have the wrapper perform natively to spare developers the inconvenience of dealing with them. Let's take a look at what has improved since then! 1. **Native date formatting:** Tenor's API, when you make a request of it that pertains to a GIF, returns a number of very useful information; however, when it comes to the GIF's creation date, it returns a UNIX timestamp that a developer then has to make another step to format. **--** Personally, I wasn't a fan of it and considered it bad UX, so I did something about it. Prior to returning the requested information to the developer, TenorJS intercepts it and makes some modifications pertaining to dates. **1-** TenorJS automatically formats the UNIX timestamp into human readable dates, like such: `14/10/2015 - 1:08:25 AM` and pushes the change back into the JSON response. To further expand upon this point, you should note that you can configure the date format according to your preferences or those of your users. Simply configure the TenorJS client as such: ```js const Tenor = require("tenorjs").client({ "Key": "YOUR DEVELOPER KEY HERE", // https://tenor.com/developer/keyregistration "Filter": "off", // "off", "low", "medium", "high", not case sensitive "Locale": "en_US", // Your locale here, case-sensitivity depends on input "MediaFilter": "minimal", // either minimal or basic, not case sensitive "DateFormat": "D/MM/YYYY - H:mm:ss A" // Change this accordingly }); ``` Keep in mind that if you do not set a custom date format, the library is set to use the date format used in the example above as the default. **2-** To ensure the UNIX timestamp is still there for anyone that wants to make use of it, TenorJS does re-insert the original timestamp back into the JSON response under the `created_stamp` object. Please note that date formatting is handled by [moment](https://npmjs.com/package/moment). 2. **Native GIF title checking:** Another thing I noticed about JSON responses was that when the GIF had no title, the `title` object would be returned blank. Again, I wasn't a personal fan of this so I dedcided to do something about it. In v1.0.6, TenorJS now automatically checks the `title` object upon receiving a response and gives it a value of "Untitled" if it turned out to be blank. ### 3. More search! New search functionality! You can now offer your users the ability to specifically search for a GIF (or a group of GIFs, up to a total amount of 50 GIFs) using their respective IDs. Example: > Please note that the IDs object always has to be an array. So `GIFs(["ID"])` not `GIFs("ID")`. ```js Tenor.Search.GIFs(["9411482", "5152678", "12175525"]).then(GIF => { GIF.forEach(Post => { console.log(`Item #${Post.id} @ ${Post.url}`); }); }).catch(console.error); // Item #9411482 @ https://tenor.com/NEwg.gif // Item #5152678 @ https://tenor.com/vMBS.gif // Item #12175525 @ https://tenor.com/ZfzB.gif ```