-
Couldn't load subscription status.
- Fork 15
Implement banned company members endpoint #36
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
Merged
ShawnCZek
merged 7 commits into
TruckersMP:develop
from
iDiegoNL:feature/add-banned-members-to-company
Nov 13, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
838df2b
Implement banned company members endpoint
iDiegoNL 6032f1b
Remove unnecessary newline in CompanyRequest
iDiegoNL 744b1a4
Fix PR docblock comments
iDiegoNL 1f28dc6
Move bans method to MemberIndexRequest
iDiegoNL 656e437
Merge remote-tracking branch 'truckersmp/develop' into feature/add-ba…
iDiegoNL 92a7200
Rename $companyId to $companyKey to be consistent with #37
iDiegoNL 06c635a
Fix StyleCI
iDiegoNL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| namespace TruckersMP\APIClient\Collections\Company; | ||
|
|
||
| use TruckersMP\APIClient\Collections\Collection; | ||
| use TruckersMP\APIClient\Models\CompanyBan; | ||
|
|
||
| class BanCollection extends Collection | ||
| { | ||
| /** | ||
| * Create a new BanCollection instance. | ||
| * | ||
| * @param array $response | ||
| * @return void | ||
| */ | ||
| public function __construct(array $response) | ||
| { | ||
| parent::__construct(); | ||
|
|
||
| foreach ($response['members'] as $key => $ban) { | ||
| $this->items[$key] = new CompanyBan($ban); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| <?php | ||
|
|
||
| namespace TruckersMP\APIClient\Models; | ||
|
|
||
| use Carbon\Carbon; | ||
|
|
||
| class CompanyBan | ||
| { | ||
| /** | ||
| * The player's member ID within the company. | ||
| * | ||
| * @var int | ||
| */ | ||
| protected $id; | ||
|
|
||
| /** | ||
| * The ID of the user. | ||
| * | ||
| * @var int | ||
| */ | ||
| protected $userId; | ||
|
|
||
| /** | ||
| * The username of the user. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $username; | ||
|
|
||
| /** | ||
| * The Steam ID of the user. | ||
| * | ||
| * @var int | ||
| */ | ||
| protected $steamId; | ||
|
|
||
| /** | ||
| * The player's role ID within the company. | ||
| * | ||
| * @var int | ||
| */ | ||
| protected $roleId; | ||
|
|
||
| /** | ||
| * The player's role name within the company. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $roleName; | ||
|
|
||
| /** | ||
| * The date at which the user joined the company. | ||
| * | ||
| * @var Carbon | ||
| */ | ||
| protected $joinDate; | ||
|
|
||
| /** | ||
| * Create a new CompanyBan instance. | ||
| * | ||
| * @param array $ban | ||
| * @return void | ||
| */ | ||
| public function __construct(array $ban) | ||
| { | ||
| $this->id = $ban['id']; | ||
| $this->userId = $ban['user_id']; | ||
| $this->username = $ban['username']; | ||
| $this->steamId = $ban['steam_id']; | ||
| $this->roleId = $ban['role_id']; | ||
| $this->roleName = $ban['role']; | ||
| $this->joinDate = new Carbon($ban['joinDate'], 'UTC'); | ||
| } | ||
|
|
||
| /** | ||
| * Get the player's member ID within the company. | ||
| * | ||
| * @return int | ||
| */ | ||
| public function getId(): int | ||
| { | ||
| return $this->id; | ||
| } | ||
|
|
||
| /** | ||
| * Get the ID of the user. | ||
| * | ||
| * @return int | ||
| */ | ||
| public function getUserId(): int | ||
| { | ||
| return $this->userId; | ||
| } | ||
|
|
||
| /** | ||
| * Get the username of the user. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getUsername(): string | ||
| { | ||
| return $this->username; | ||
| } | ||
|
|
||
| /** | ||
| * Get the Steam ID of the user. | ||
| * | ||
| * @return int | ||
| */ | ||
| public function getSteamId(): int | ||
| { | ||
| return $this->steamId; | ||
| } | ||
|
|
||
| /** | ||
| * Get the ID of the member's role within the company. | ||
| * | ||
| * @return int | ||
| */ | ||
| public function getRoleId(): int | ||
| { | ||
| return $this->roleId; | ||
| } | ||
|
|
||
| /** | ||
| * Get the name of the member's role within the company. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getRoleName(): string | ||
| { | ||
| return $this->roleName; | ||
| } | ||
|
|
||
| /** | ||
| * Get the date the member joined the company. | ||
| * | ||
| * @return Carbon | ||
| */ | ||
| public function getJoinDate(): Carbon | ||
| { | ||
| return $this->joinDate; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| namespace TruckersMP\APIClient\Requests\Company; | ||
|
|
||
| use Psr\Http\Client\ClientExceptionInterface; | ||
| use TruckersMP\APIClient\Collections\Company\BanCollection; | ||
| use TruckersMP\APIClient\Exceptions\ApiErrorException; | ||
| use TruckersMP\APIClient\Models\CompanyBan; | ||
| use TruckersMP\APIClient\Requests\Request; | ||
|
|
||
| class BanIndexRequest extends Request | ||
| { | ||
| /** | ||
| * The ID or slug of the requested company. | ||
| * | ||
| * @var string|int | ||
| */ | ||
| protected $companyKey; | ||
|
|
||
| /** | ||
| * Create a new BanIndexRequest instance. | ||
| * | ||
| * @param string|int $companyKey | ||
| * @return void | ||
| */ | ||
| public function __construct(string $companyKey) | ||
| { | ||
| parent::__construct(); | ||
|
|
||
| $this->companyKey = $companyKey; | ||
| } | ||
|
|
||
| /** | ||
| * Get the endpoint of the request. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getEndpoint(): string | ||
| { | ||
| return 'vtc/' . $this->companyKey . '/members/banned'; | ||
| } | ||
|
|
||
| /** | ||
| * Get the data for the request. | ||
| * | ||
| * @return BanCollection|CompanyBan[] | ||
| * | ||
| * @throws ApiErrorException | ||
| * @throws ClientExceptionInterface | ||
| */ | ||
| public function get(): BanCollection | ||
| { | ||
| return new BanCollection( | ||
| $this->send()['response'] | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\Unit; | ||
|
|
||
| use Tests\TestCase; | ||
| use TruckersMP\APIClient\Collections\Company\BanCollection; | ||
| use TruckersMP\APIClient\Models\CompanyBan; | ||
|
|
||
| class CompanyBanTest extends TestCase | ||
| { | ||
| /** | ||
| * The ID of the company to use in the tests. | ||
| */ | ||
| private const TEST_COMPANY = 2; | ||
|
|
||
| /** @test */ | ||
| public function it_can_get_all_the_bans() | ||
| { | ||
| $bans = $this->companyBans(self::TEST_COMPANY); | ||
|
|
||
| $this->assertInstanceOf(BanCollection::class, $bans); | ||
|
|
||
| if ($bans->count() > 0) { | ||
| $ban = $bans[0]; | ||
|
|
||
| $this->assertInstanceOf(CompanyBan::class, $ban); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.