DiscordPHP-Http Documentation

Http
in package
implements HttpInterface uses HttpTrait

Discord HTTP client.

Tags
author

David Cole david.cole1340@gmail.com

Table of Contents

Interfaces

HttpInterface
Discord HTTP client.

Constants

BASE_URL  : string = 'https://discord.com/api/v' . self::HTTP_API_VE...
Discord API base URL.
CONCURRENT_REQUESTS  : int = 5
The number of concurrent requests which can be executed.
HTTP_API_VERSION  : string = 10
Current Discord HTTP API version.
VERSION  : string = 'v10.9.4'
DiscordPHP-Http version.

Properties

$buckets  : array<string|int, Bucket>
Array of request buckets.
$driver  : DriverInterface
HTTP driver.
$logger  : LoggerInterface
Logger for HTTP requests.
$loop  : LoopInterface
ReactPHP event loop.
$promiseV3  : mixed
Whether react/promise v3 is used, if false, using v2.
$queue  : SplQueue
Request queue to prevent API overload.
$rateLimit  : RateLimit
The current rate-limit.
$rateLimitReset  : TimerInterface
Timer that resets the current global rate-limit.
$unboundQueue  : SplQueue
Request queue to prevent API overload.
$waiting  : int
Number of requests that are waiting for a response.
$token  : string
Authentication token.

Methods

__construct()  : mixed
Http wrapper constructor.
delete()  : PromiseInterface
Runs a DELETE request.
get()  : PromiseInterface
Runs a GET request.
getDriver()  : DriverInterface|null
Gets the HTTP driver, so another client can share it.
getUserAgent()  : string
Returns the User-Agent of the HTTP client.
handleError()  : Throwable
Returns an exception based on the request.
isUnboundEndpoint()  : bool
Checks if the request is for an endpoint not bound by the global rate limit.
patch()  : PromiseInterface
Runs a PATCH request.
post()  : PromiseInterface
Runs a POST request.
put()  : PromiseInterface
Runs a PUT request.
queueRequest()  : PromiseInterface
Builds and queues a request.
setDriver()  : void
Sets the driver of the HTTP client.
checkQueue()  : void
Checks the request queue to see if more requests can be sent out.
checkunboundQueue()  : void
Checks the interaction queue to see if more requests can be sent out.
executeRequest()  : PromiseInterface
Executes a request.
getBucket()  : Bucket
Gets a bucket.
guessContent()  : mixed
Guesses the headers and transforms the content of a request.
sortIntoBucket()  : void
Sorts a request into a bucket.

Constants

BASE_URL

Discord API base URL.

public string BASE_URL = 'https://discord.com/api/v' . self::HTTP_API_VERSION

CONCURRENT_REQUESTS

The number of concurrent requests which can be executed.

public int CONCURRENT_REQUESTS = 5

HTTP_API_VERSION

Current Discord HTTP API version.

public string HTTP_API_VERSION = 10

VERSION

DiscordPHP-Http version.

public string VERSION = 'v10.9.4'

Properties

$buckets

Array of request buckets.

protected array<string|int, Bucket> $buckets = []

$logger

Logger for HTTP requests.

protected LoggerInterface $logger

$loop

ReactPHP event loop.

protected LoopInterface $loop

$promiseV3

Whether react/promise v3 is used, if false, using v2.

protected mixed $promiseV3 = true

$queue

Request queue to prevent API overload.

protected SplQueue $queue

$rateLimitReset

Timer that resets the current global rate-limit.

protected TimerInterface $rateLimitReset

$unboundQueue

Request queue to prevent API overload.

protected SplQueue $unboundQueue

$waiting

Number of requests that are waiting for a response.

protected int $waiting = 0

$token

Authentication token.

private string $token

Methods

__construct()

Http wrapper constructor.

public __construct(string $token, LoopInterface $loop, LoggerInterface $logger[, DriverInterface|null $driver = null ]) : mixed
Parameters
$token : string
$loop : LoopInterface
$logger : LoggerInterface
$driver : DriverInterface|null = null

delete()

Runs a DELETE request.

public delete(string|Endpoint $url[, mixed $content = null ][, array<string|int, mixed> $headers = [] ]) : PromiseInterface
Parameters
$url : string|Endpoint
$content : mixed = null
$headers : array<string|int, mixed> = []
Return values
PromiseInterface

get()

Runs a GET request.

public get(string|Endpoint $url[, mixed $content = null ][, array<string|int, mixed> $headers = [] ]) : PromiseInterface
Parameters
$url : string|Endpoint
$content : mixed = null
$headers : array<string|int, mixed> = []
Return values
PromiseInterface

getUserAgent()

Returns the User-Agent of the HTTP client.

public getUserAgent() : string
Return values
string

handleError()

Returns an exception based on the request.

public handleError(ResponseInterface $response) : Throwable
Parameters
$response : ResponseInterface
Return values
Throwable

patch()

Runs a PATCH request.

public patch(string|Endpoint $url[, mixed $content = null ][, array<string|int, mixed> $headers = [] ]) : PromiseInterface
Parameters
$url : string|Endpoint
$content : mixed = null
$headers : array<string|int, mixed> = []
Return values
PromiseInterface

post()

Runs a POST request.

public post(string|Endpoint $url[, mixed $content = null ][, array<string|int, mixed> $headers = [] ]) : PromiseInterface
Parameters
$url : string|Endpoint
$content : mixed = null
$headers : array<string|int, mixed> = []
Return values
PromiseInterface

put()

Runs a PUT request.

public put(string|Endpoint $url[, mixed $content = null ][, array<string|int, mixed> $headers = [] ]) : PromiseInterface
Parameters
$url : string|Endpoint
$content : mixed = null
$headers : array<string|int, mixed> = []
Return values
PromiseInterface

queueRequest()

Builds and queues a request.

public queueRequest(string $method, Endpoint $url, mixed $content[, array<string|int, mixed> $headers = [] ]) : PromiseInterface
Parameters
$method : string
$url : Endpoint
$content : mixed
$headers : array<string|int, mixed> = []
Return values
PromiseInterface

checkQueue()

Checks the request queue to see if more requests can be sent out.

protected checkQueue([bool $check_interactions = true ]) : void
Parameters
$check_interactions : bool = true

checkunboundQueue()

Checks the interaction queue to see if more requests can be sent out.

protected checkunboundQueue() : void

executeRequest()

Executes a request.

protected executeRequest(Request $request[, Deferred|null $deferred = null ]) : PromiseInterface
Parameters
$request : Request
$deferred : Deferred|null = null
Return values
PromiseInterface

getBucket()

Gets a bucket.

protected getBucket(string $key) : Bucket
Parameters
$key : string
Return values
Bucket

guessContent()

Guesses the headers and transforms the content of a request.

protected guessContent(mixed &$content) : mixed
Parameters
$content : mixed

sortIntoBucket()

Sorts a request into a bucket.

protected sortIntoBucket(Request $request) : void
Parameters
$request : Request
On this page

Search results