Skip to content

Composer package #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Don't include vendor files installed via Composer
/src-composer/vendor/

/vendor/
/.idea/
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "mcwnuq/php-bbb-api-wrapper",
"description": "A PHP wrapper for BuiltByBit's Ultimate REST API.",
"license": "MIT",
"autoload": {
"psr-4": {
"Majored\\PhpBbbApiWrapper\\": "src/"
}
},
"authors": [
{
"name": "Majored"
},
{
"name": "BuiltByBit"
},
{
"name": "mcwnuq"
}
],
"require": {}
}
3 changes: 2 additions & 1 deletion src/APIResponse.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper;

/** Represents a parsed response from BuiltByBit's API. */
class APIResponse {
Expand Down Expand Up @@ -69,7 +70,7 @@ function getError() {
* @param string The raw JSON response.
* @return APIResponse The newly construct response instance.
*/
static function from_json(string $json): Self {
static function from_json(string $json): self {
$data = json_decode($json, true);

if (!array_key_exists("data", $data)) {
Expand Down
10 changes: 1 addition & 9 deletions src/APIToken.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper;

/** Stores data about a particular API token. */
class APIToken {
Expand Down Expand Up @@ -31,12 +32,3 @@ function asHeader(): string {
return sprintf("Authorization: %s %s", $this->type, $this->value);
}
}

/** Holds declarations for different API token types. */
class TokenType {
/** @var string A string value representing the Private token type. */
public const PRIVATE = "Private";

/** @var string A string value representing the Shared token type. */
public const SHARED = "Shared";
}
27 changes: 9 additions & 18 deletions src/APIWrapper.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper;

require __DIR__ . "/APIToken.php";
require __DIR__ . "/APIResponse.php";
require __DIR__ . "/Throttler.php";

require __DIR__ . "/helpers/AlertsHelper.php";
require __DIR__ . "/helpers/ConversationsHelper.php";
require __DIR__ . "/helpers/MembersHelper.php";
require __DIR__ . "/helpers/ThreadsHelper.php";

require __DIR__ . "/helpers/resources/ResourcesHelper.php";
require __DIR__ . "/helpers/resources/LicensesHelper.php";
require __DIR__ . "/helpers/resources/PurchasesHelper.php";
require __DIR__ . "/helpers/resources/DownloadsHelper.php";
require __DIR__ . "/helpers/resources/VersionsHelper.php";
require __DIR__ . "/helpers/resources/UpdatesHelper.php";
require __DIR__ . "/helpers/resources/ReviewsHelper.php";
use CurlHandle;
use Majored\PhpBbbApiWrapper\Helpers\AlertsHelper;
use Majored\PhpBbbApiWrapper\Helpers\ConversationsHelper;
use Majored\PhpBbbApiWrapper\Helpers\MembersHelper;
use Majored\PhpBbbApiWrapper\Helpers\Resources\ResourcesHelper;
use Majored\PhpBbbApiWrapper\Helpers\ThreadsHelper;

/** The primary class for interactions with BuiltByBit's API. */
class APIWrapper {
Expand Down Expand Up @@ -157,9 +148,9 @@ function delete(string $endpoint): APIResponse {
* Handles a CURL response and sets/resets local rate limiting metadata.
*
* @param int The type of request which the response originated from (RequestType).
* @return string The raw JSON response or null if a rate limit was hit.
* @return string|null The raw JSON response or null if a rate limit was hit.
*/
private function handleResponse(int $type): string {
private function handleResponse(int $type): ?string {
list($header, $body) = explode("\r\n\r\n", curl_exec($this->http), 2);
$status = curl_getinfo($this->http, CURLINFO_HTTP_CODE);
$header = APIWrapper::parseHeaders(explode("\r\n", $header));
Expand Down
12 changes: 12 additions & 0 deletions src/RequestType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Majored\PhpBbbApiWrapper;

/** Holds declarations for different request types. */
class RequestType {
/** @var int An integer value representing the read endpoints (ie. GET). */
public const READ = 0;

/** @var int An integer value representing the write endpoints (ie. POST, PATCH, & DELETE). */
public const WRITE = 1;
}
10 changes: 1 addition & 9 deletions src/Throttler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper;

/** Stores metadata needed for local request throttling. */
class Throttler {
Expand Down Expand Up @@ -117,12 +118,3 @@ function stallFor(int $type): int {
return $stall_for;
}
}

/** Holds declarations for different request types. */
class RequestType {
/** @var int An integer value representing the read endpoints (ie. GET). */
public const READ = 0;

/** @var int An integer value representing the write endpoints (ie. POST, PATCH, & DELETE). */
public const WRITE = 1;
}
12 changes: 12 additions & 0 deletions src/TokenType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Majored\PhpBbbApiWrapper;

/** Holds declarations for different API token types. */
class TokenType {
/** @var string A string value representing the Private token type. */
public const PRIVATE = "Private";

/** @var string A string value representing the Shared token type. */
public const SHARED = "Shared";
}
4 changes: 4 additions & 0 deletions src/helpers/AlertsHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for alert-related API endpoints. */
class AlertsHelper {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/ConversationsHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for conversation-related API endpoints. */
class ConversationsHelper {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/MembersHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for member-related API endpoints. */
class MembersHelper {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/ThreadsHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for thread-related API endpoints. */
class ThreadsHelper {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/resources/DownloadsHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers\Resources;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for download-related API endpoints. */
class DownloadsHelper {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/resources/LicensesHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers\Resources;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for license-related API endpoints. */
class LicensesHelper {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/resources/PurchasesHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers\Resources;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for purchase-related API endpoints. */
class PurchasesHelper {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/resources/ResourcesHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers\Resources;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for resource-related API endpoints. */
class ResourcesHelper {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/resources/ReviewsHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers\Resources;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for review-related API endpoints. */
class ReviewsHelper {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/resources/UpdatesHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers\Resources;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for update-related API endpoints. */
class UpdatesHelper {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/resources/VersionsHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
// Copyright (c) 2021 Harry [Majored] [[email protected]]
// MIT License (https://github.com/Majored/php-bbb-api-wrapper/blob/main/LICENSE)
namespace Majored\PhpBbbApiWrapper\Helpers\Resources;

use Majored\PhpBbbApiWrapper\APIResponse;
use Majored\PhpBbbApiWrapper\APIWrapper;

/** A helper class for version-related API endpoints. */
class VersionsHelper {
Expand Down