Skip to content

Commit

Permalink
Merge pull request #6 from ParadoxalCorp/indev
Browse files Browse the repository at this point in the history
Update 2.0.2
  • Loading branch information
ParadoxOrigins authored Aug 19, 2018
2 parents bdb016f + 5e6c953 commit d5d8624
Show file tree
Hide file tree
Showing 12 changed files with 800 additions and 1,001 deletions.
39 changes: 39 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:10

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mongo:3.4.4

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: npm install

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

# run tests!
- run: npm test


2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
test.js
38 changes: 16 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Taihou - A weeb.sh wrapper

[![CircleCI](https://circleci.com/gh/ParadoxalCorp/Taihou.svg?style=svg)](https://circleci.com/gh/ParadoxalCorp/Taihou)

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/dcde3c99ed014a1284391aee2abc04b6)](https://www.codacy.com/app/paradoxalcorp/Taihou?utm_source=github.com&utm_medium=referral&utm_content=ParadoxalCorp/Taihou&utm_campaign=Badge_Grade)

Taihou is a promise-returning Node.js wrapper for [weeb.sh](https://docs.weeb.sh/#introduction). Taihou is easy to use but also has
Expand All @@ -11,6 +13,7 @@ Special thanks to [MrLar](https://github.com/MrLar) (MrLar 🌺#0611) who helped

* [Features](#features)
* [Requirements](#requirements)
* [Changelog](#changelog)
* [Usage](#usage)
- * [Passing options to specific services/methods](#passing-options-to-specifc-services-or-methods)
- * [Sending generated images to Discord](#sending-generated-images-to-discord)
Expand Down Expand Up @@ -43,6 +46,17 @@ Special thanks to [MrLar](https://github.com/MrLar) (MrLar 🌺#0611) who helped

The lowest known Node.js version supported is Node.js `8.3.0`

## Changelog

### Update 2.0.2

> 1.0.2 => 2.0.2
This update optimize a bit the internal code documentation and document the responses of all methods, which should make any code editor that supports JSDoc able to provide
decent Intellisense

The reason why this is a major update is because of the potentially breaking rework of error handling, rejected/thrown errors are no longer instances of the `TaihouError` class, but instances of Node.js's Error class. Errors that are directly originating from the request sent to the weeb.sh servers are following [Axios's error scheme](https://www.npmjs.com/package/axios#handling-errors)

## Usage

While the size of this readme may make it look complicated, Taihou is fairly easy to use:
Expand Down Expand Up @@ -98,7 +112,7 @@ weebSH.toph.getRandomImage('pat', {timeout: 3000}) //Set 3000ms instead of 5000

### Sending generated images to Discord

Especially if it's your first time dealing with buffers, sending the images generated by korra might be a little confusing. The two examples below
Especially if it's your first time dealing with buffers, sending the images generated by Korra might be a little confusing. The two examples below
show how to do it in the most probable context (when a command is called)

#### With Eris
Expand Down Expand Up @@ -1226,27 +1240,7 @@ In most cases the sequential mode is more suited, which is why it's the default,
### Error handling
All errors rejected from a Taihou method are an instance of the TaihouError class, as described below, additional properties may be added to the error
if the error originate from a request. Otherwise, if the error is caused to invalid arguments when calling a method, only the `message` and `stack` properties
are guaranteed
<a name="TaihouError"></a>
## TaihouError ⇐ <code>Error</code>
Only the message and stack property are guaranteed, as all the other properties can appear only if the error originated from the request
**Kind**: global class
**Extends**: <code>Error</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| message | <code>string</code> | A message describing the error |
| stack | <code>string</code> | The stacktrace of the error |
| [code] | <code>number</code> | If the error originated from the request made, the HTTP status code of the request |
| [data] | <code>string</code> \| <code>object</code> | The data returned by the weeb.sh servers |
| [originalRequest] | <code>any</code> | The sent request |
| [config] | <code>any</code> | The config of the sent request |
Malformed requests errors are instances of Node.js's Error class while errors that are directly originating from the request sent to the weeb.sh servers are following [Axios's error scheme](https://www.npmjs.com/package/axios#handling-errors)
### Tama caching behavior
Expand Down
38 changes: 29 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,38 @@ const constants = require('./src/constants.js');

const axios = require('axios');

/** @typedef {import("./src/Toph/Toph.js").TophOptions} TophOptions
* @typedef {import("./src/Korra/Korra.js").KorraOptions} KorraOptions
* @typedef {import("./src/Shimakaze/Shimakaze").ShimakazeOptions} ShimakazeOptions
* @typedef {import("./src/Tama/Tama.js").TamaOptions} TamaOptions
*/

/**
* @typedef TaihouOptions
* @prop {string} baseURL The base URL to use for each request, you may change this if you want to use staging or if you run a local instance (like: 'https://api.weeb.sh')
* @prop {string} userAgent Strongly recommended, this should follow a BotName/Version/Environment pattern, or at least the bot name
* @prop {number} timeout Time in milliseconds before a request should be aborted
* @prop {any} headers An object of additional headers following a {'header': 'value'} format, note that those must not be content-type, user-agent or authorization header
* @typedef {Object} TaihouOptions
* @prop {String} baseURL The base URL to use for each request, you may change this if you want to use staging or if you run a local instance (like: 'https://api.weeb.sh')
* @prop {String} userAgent Strongly recommended, this should follow a BotName/Version/Environment pattern, or at least the bot name
* @prop {Number} timeout Time in milliseconds before a request should be aborted
* @prop {Object} headers An object of additional headers following a {'header': 'value'} format, note that those must not be content-type, user-agent or authorization header
*/

/** @typedef {Object} PerServicesOptions
* @prop {TophOptions & TaihouOptions} toph Additional options to pass to Toph
* @prop {TophOptions & TaihouOptions} images Additional options to pass to Toph
* @prop {KorraOptions & TaihouOptions} korra Additional options to pass to Korra
* @prop {KorraOptions & TaihouOptions} imageGeneration Additional options to pass to Korra
* @prop {ShimakazeOptions & TaihouOptions} shimakaze Additional options to pass to Shimakaze
* @prop {ShimakazeOptions & TaihouOptions} reputation Additional options to pass to Shimakaze
* @prop {TamaOptions & TaihouOptions} tama Additional options to pass to Tama
* @prop {TamaOptions & TaihouOptions} settings Additional options to pass to Tama
*/

/** @typedef {TaihouOptions & PerServicesOptions} ConstructorOptions */

/**
*
*
* @class Taihou
* @prop {any} token The token given in the constructor, formatted according to whether it is a wolke token or not
* @prop {String} token The token given in the constructor, formatted according to whether it is a wolke token or not
* @prop {Toph} toph The Toph class - gives access to toph methods
* @prop {Korra} korra The Korra class - gives access to korra methods
* @prop {Shimakaze} shimakaze The Shimakaze class - gives access to shimakaze methods
Expand All @@ -29,13 +48,14 @@ const axios = require('axios');
* @prop {Korra} imageGeneration - Equivalent for korra
* @prop {Shimakaze} reputation - Equivalent for reputation
* @prop {Tama} settings - Equivalent for tama
* @prop {TaihouOptions} options - The options for this Taihou instance
*/
class Taihou {
/**
* Creates an instance of Taihou.
* @param {string} token - The token, required to use weeb.sh
* @param {boolean} wolken - A boolean representing whether the token is a wolke token or not, needed for taihou to work properly
* @param {TaihouOptions} options - An object of options
* @param {String} token - The token, required to use weeb.sh
* @param {Boolean} wolken - A boolean representing whether the token is a wolke token or not, needed for taihou to work properly
* @param {ConstructorOptions} [options] - An object of options
* @memberof Taihou
*/
constructor(token, wolken, options = {}) {
Expand Down
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taihou",
"version": "1.0.2",
"version": "2.0.2",
"description": "A wrapper for weeb.sh",
"main": "index.js",
"repository": {
Expand All @@ -15,4 +15,4 @@
"dependencies": {
"axios": "^0.18.0"
}
}
}
11 changes: 5 additions & 6 deletions src/Base.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';

const RequestHandler = require('./RequestHandler');
const Error = require('./Error');
const fs = require('fs');

class Base {
constructor(options) {
this.requestHandler = new RequestHandler(options);
this.Error = Error;
}

/**
Expand All @@ -19,8 +17,8 @@ class Base {
* @private
* @returns {void}
*/
status(url, options) {
return this.requestHandler.queueRequest(this.formatRequest(url, 'get', options), { beforeNextRequest: options.beforeNextRequest || 60 });
_status(url, options) {
return this.requestHandler.queueRequest(this._formatRequest(url, 'get', options), { beforeNextRequest: options.beforeNextRequest || 60 });
}

/**
Expand All @@ -33,7 +31,7 @@ class Base {
* @memberof Base
* @private
*/
formatRequest(url, method, options) {
_formatRequest(url, method, options) {
return async() => {
const config = {
timeout: options.timeout,
Expand All @@ -58,7 +56,7 @@ class Base {
* @memberof Base
* @private
*/
addURLParams(baseParams, paramsToAdd, options) {
_addURLParams(baseParams, paramsToAdd, options) {
if (!Array.isArray(paramsToAdd)) {
baseParams = Object.assign(baseParams, paramsToAdd);
} else {
Expand All @@ -76,6 +74,7 @@ class Base {
*
* @param {string} path - The path
* @returns {Promise<any>} The file
* @private
* @memberof Base
*/
_readFileAsync(path) {
Expand Down
29 changes: 0 additions & 29 deletions src/Error.js

This file was deleted.

Loading

0 comments on commit d5d8624

Please sign in to comment.