1.2.0 • Published 6 years ago

felix-wrapper v1.2.0

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

This is a wrapper for the API of Felix, a Discord bot

This wrapper covers 100% of Felix's API and will be updated at the same time as Felix's API is

Tables of contents

Constructor Methods Error Handling

Constructor

const FelixWrapper = require("felix-wrapper");

let wrapper = new FelixWrapper({
    url: "",
    token: "",
    timeout: 42,
    autoConversion: false
});
PropertyTypeDescription
urlStringRequired. The base url of the domain to request to
tokenStringOptional. The token (private or public), optional but required for almost all endpoints
timeoutNumberOptional. The time in ms before requests should be aborted, default is 6000
autoConversionBooleanOptional. Whether arrays should be converted to enhanced maps, default is true

Methods

wrapper.status()

Returns: A boolean based on whether Felix's API is up or not

wrapper.getUserData(user, options)

Returns: The user object/array of user objects

ParamsTypeDescription
userString OR ArrayRequired. The user ID or an array of IDs of the user(s) to fetch
optionsObjectOptional. An object of options
options.timeoutNumberOptional. The time in ms before this request should be aborted, default is wrapper.timeout

wrapper.postUserData(user, options)

Restricted to private tokens

Returns: The posted user object if the operation is successful, otherwise reject an error

ParamsTypeDescription
userObjectRequired. The user object to POST, will update or create a new database entry
optionsObjectOptional. An object of options
options.timeoutNumberOptional. The time in ms before this request should be aborted, default is wrapper.timeout

wrapper.getGuildData(guild, options)

Returns: The guild object/array of guild objects

ParamsTypeDescription
guildString OR ArrayRequired. The guild ID or an array of IDs of the guild(s) to fetch
optionsObjectOptional. An object of options
options.timeoutNumberOptional. The time in ms before this request should be aborted, default is wrapper.timeout

wrapper.postGuildData(guild, options)

Restricted to private tokens

Returns: The posted guild object if the operation is successful, otherwise reject an error

ParamsTypeDescription
guildObjectRequired. The guild object to POST, will update or create a new database entry
optionsObjectOptional. An object of options
options.timeoutNumberOptional. The time in ms before this request should be aborted, default is wrapper.timeout

wrapper.fetchClientValue(value)

Restricted to private tokens

Returns: The value

ParamsTypeDescription
valueStringRequired. The value to fetch, this will be interpreted as a property name of the client object

Error Handling

As of update 1.2.0, errors have been standardized and now follow a logical scheme.

All errors are rejected and the rejection structure is the following:

{
  code: 403,
  message: 'Forbidden',
  data: 'Forbidden'
}
PropsTypeDescription
codeNumberThe HTTP error code returned by the server or an appropriate equivalent regarding the error
messageStringThe description of the HTTP error code
data*The error the server returned, this can be a simple "Forbidden" to an array of invalid data the server encountered in a post request

Errors code you are the most likely to encounter:

CodeMessageDescription
400Bad RequestThe object sent along with a method like postUser() is invalid
403ForbiddenYou did not specified a token, the token is invalid or you have a public token and tried to use a method restricted to private tokens
408Request TimeoutThe server did not answered in the time set in the constructor, or in the 6000 default ms
429Too Much RequestsYou use a public token and reached the rate-limit
1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago