Documentation

Nameless2API
in package

NamelessMC API v2 class

Tags
author

Samerton

author

Aberdeener

version
2.0.0-pr13
license

MIT

Table of Contents

Constants

ERROR_API_DISABLED  = 'nameless:api_is_disabled'
ERROR_CANNOT_FIND_USER  = 'nameless:cannot_find_user'
ERROR_INVALID_API_KEY  = 'nameless:invalid_api_key'
ERROR_INVALID_API_METHOD  = 'nameless:invalid_api_method'
ERROR_INVALID_GET_CONTENTS  = 'nameless:invalid_get_contents'
ERROR_INVALID_POST_CONTENTS  = 'nameless:invalid_post_contents'
ERROR_MISSING_API_KEY  = 'nameless:missing_api_key'
ERROR_NO_SITE_UID  = 'nameless:no_site_uid'
ERROR_NOT_AUTHORIZED  = 'nameless:not_authorized'
ERROR_UNKNOWN_ERROR  = 'nameless:unknown_error'

Properties

$_db  : DB
$_language  : Language

Methods

__construct()  : mixed
Create an instance of the API class and forward the request to the Endpoints class.
getDb()  : DB
getLanguage()  : Language
getUser()  : User
Find a user in the database, or throw an error if not found
returnArray()  : never
Return an array of data to the client.
throwError()  : never
Throw an error to the client
validateParams()  : bool
Validate input data
encodeJson()  : string|false
Encode a value as json, with pretty printing enabled if DEBUGGING is defined.

Constants

ERROR_API_DISABLED

public mixed ERROR_API_DISABLED = 'nameless:api_is_disabled'

ERROR_CANNOT_FIND_USER

public mixed ERROR_CANNOT_FIND_USER = 'nameless:cannot_find_user'

ERROR_INVALID_API_KEY

public mixed ERROR_INVALID_API_KEY = 'nameless:invalid_api_key'

ERROR_INVALID_API_METHOD

public mixed ERROR_INVALID_API_METHOD = 'nameless:invalid_api_method'

ERROR_INVALID_GET_CONTENTS

public mixed ERROR_INVALID_GET_CONTENTS = 'nameless:invalid_get_contents'

ERROR_INVALID_POST_CONTENTS

public mixed ERROR_INVALID_POST_CONTENTS = 'nameless:invalid_post_contents'

ERROR_MISSING_API_KEY

public mixed ERROR_MISSING_API_KEY = 'nameless:missing_api_key'

ERROR_NO_SITE_UID

public mixed ERROR_NO_SITE_UID = 'nameless:no_site_uid'

ERROR_NOT_AUTHORIZED

public mixed ERROR_NOT_AUTHORIZED = 'nameless:not_authorized'

ERROR_UNKNOWN_ERROR

public mixed ERROR_UNKNOWN_ERROR = 'nameless:unknown_error'

Properties

Methods

__construct()

Create an instance of the API class and forward the request to the Endpoints class.

public __construct(string $route, Language $api_language, Endpoints $endpoints) : mixed
Parameters
$route : string

The incoming API request route

$api_language : Language

Instance of the language class

$endpoints : Endpoints

Instance of the Endpoints class

getUser()

Find a user in the database, or throw an error if not found

public getUser(string $column, string $value) : User
Parameters
$column : string

The column to lookup

$value : string

The value to lookup in the specified column

Return values
User

The resolved user

returnArray()

Return an array of data to the client.

public returnArray(array<string|int, mixed> $array[, int $status = Response::HTTP_OK ]) : never
Parameters
$array : array<string|int, mixed>

Array of data to be returned

$status : int = Response::HTTP_OK

HTTP status code

Return values
never

throwError()

Throw an error to the client

public throwError(string $error[, mixed $meta = null ][, int $status = Response::HTTP_BAD_REQUEST ]) : never
Parameters
$error : string

The namespaced error code

$meta : mixed = null

Any additional data to return

$status : int = Response::HTTP_BAD_REQUEST

HTTP status code

Return values
never

validateParams()

Validate input data

public validateParams(array<string|int, mixed> $input, array<string|int, mixed> $required_fields[, string $type = 'post' ]) : bool
Parameters
$input : array<string|int, mixed>

The input array

$required_fields : array<string|int, mixed>

Array of required fields

$type : string = 'post'

Whether to check post or get input

Return values
bool

True if the input is valid, false if not

encodeJson()

Encode a value as json, with pretty printing enabled if DEBUGGING is defined.

private static encodeJson(mixed $value) : string|false
Parameters
$value : mixed

Object to encode

Return values
string|false

JSON encoded string on success or false on failure.


        
On this page

Search results