├── LICENSE.md ├── README.md ├── composer.json └── src ├── Client.php ├── Exceptions └── ApiErrorException.php ├── Models ├── Ban.php ├── Checksum.php ├── Company.php ├── CompanyBan.php ├── CompanyEventIndex.php ├── CompanyIndex.php ├── CompanyMember.php ├── CompanyMemberIndex.php ├── CompanyPost.php ├── CompanyRole.php ├── Dlc.php ├── Event.php ├── EventAttendance.php ├── EventAttendee.php ├── EventCompany.php ├── EventCompanyAttendee.php ├── EventIndex.php ├── EventLocation.php ├── EventOrganizer.php ├── EventServer.php ├── EventType.php ├── Game.php ├── GameTime.php ├── Model.php ├── Patreon.php ├── Player.php ├── PlayerAchievement.php ├── PlayerAward.php ├── PlayerCompanyHistory.php ├── Rule.php ├── Server.php ├── Social.php └── Version.php └── Requests ├── BanRequest.php ├── Company ├── BanIndexRequest.php ├── EventAttendingRequest.php ├── EventIndexRequest.php ├── EventRequest.php ├── MemberIndexRequest.php ├── MemberRequest.php ├── PostIndexRequest.php ├── PostRequest.php ├── RoleIndexRequest.php └── RoleRequest.php ├── CompanyIndexRequest.php ├── CompanyRequest.php ├── EventIndexRequest.php ├── EventRequest.php ├── EventUserRequest.php ├── GameTimeRequest.php ├── PlayerRequest.php ├── Request.php ├── RuleRequest.php ├── ServerRequest.php └── VersionRequest.php /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 TruckersMP Developers and Contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | Build Status 5 | StyleCI Status 6 | Total Downloads 7 | Latest Stable Version 8 | Latest Unstable Version 9 | License 10 |

11 | 12 | ## Introduction 13 | 14 | The TruckersMP PHP library provides convenient access to the TruckersMP API for applications written in the PHP 15 | language. It includes a pre-defined set of classes for each API endpoint to get the data as a collection or model. 16 | 17 | If you want to use the API without the library, check out the [API Documentation](https://truckersmp.com/developers/api). 18 | 19 | ## Requirements 20 | 21 | - PHP 7.4 or later 22 | - Composer 23 | 24 | ## Composer 25 | 26 | You can install the package via [Composer](https://getcomposer.org). Run the following command: 27 | 28 | ```bash 29 | composer require truckersmp/api-client 30 | ``` 31 | 32 | To use the package, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading): 33 | 34 | ```php 35 | require_once('vendor/autoload.php'); 36 | ``` 37 | 38 | ## Official Documentation 39 | 40 | Documentation for API client can be found on the [Wiki](https://github.com/TruckersMP/API-Client/wiki). 41 | 42 | ## Support 43 | 44 | If you have any questions about the library, you can create a topic on our [forum](https://forum.truckersmp.com/index.php?/forum/198-developer-portal/). 45 | 46 | ## License 47 | 48 | This package is open-source and is licensed under the [MIT license](LICENSE.md). 49 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "truckersmp/api-client", 3 | "description": "TruckersMP API Library helps connecting to and using the TruckersMP API.", 4 | "homepage": "https://truckersmp.com/", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "HumaneWolf", 9 | "email": "humanewolf@truckersmp.com", 10 | "homepage": "https://humanewolf.com/", 11 | "role": "Developer" 12 | }, 13 | { 14 | "name": "Thor Erik (Tuxy Fluffyclaws) Lie", 15 | "email": "tuxy@truckersmp.com", 16 | "homepage": "https://truckersmp.com/", 17 | "role": "Developer" 18 | }, 19 | { 20 | "name": "CJMAXiK", 21 | "email": "me@cjmaxik.ru", 22 | "homepage": "https://cjmaxik.ru", 23 | "role": "Developer" 24 | }, 25 | { 26 | "name": "Alex Blackham (B3none)", 27 | "email": "ablackham2000@gmail.com", 28 | "homepage": "https://github.com/b3none", 29 | "role": "Contributor" 30 | }, 31 | { 32 | "name": "Ben Sherred (Ratcho)", 33 | "email": "me@ratcho.dev", 34 | "homepage": "https://github.com/bensherred", 35 | "role": "Contributor" 36 | }, 37 | { 38 | "name": "Jan Lupčík (ShawnCZek)", 39 | "email": "shawnczek@truckersmp.com", 40 | "homepage": "https://github.com/shawnczek", 41 | "role": "Maintainer" 42 | }, 43 | { 44 | "name": "Diego Relyveld", 45 | "email": "me@diegor.nl", 46 | "homepage": "https://github.com/iDiegoNL", 47 | "role": "Contributor" 48 | } 49 | ], 50 | "require": { 51 | "php": "^7.4|^8.0", 52 | "ext-json": "*", 53 | "nesbot/carbon": "^2.16", 54 | "guzzlehttp/guzzle": "^7.3", 55 | "illuminate/collections": "^8.0|^9.0|^10.0|^11.0|^12.0" 56 | }, 57 | "require-dev": { 58 | "phpunit/phpunit": "^9.3", 59 | "squizlabs/php_codesniffer": "^3.5", 60 | "phpfastcache/phpfastcache": "^8.0", 61 | "mockery/mockery": "^1.5" 62 | }, 63 | "autoload": { 64 | "psr-4": { 65 | "TruckersMP\\APIClient\\": "src/" 66 | }, 67 | "classmap": [ 68 | "src/" 69 | ] 70 | }, 71 | "autoload-dev": { 72 | "psr-4": { 73 | "Tests\\": "tests/" 74 | } 75 | }, 76 | "scripts": { 77 | "test": [ 78 | "./vendor/bin/phpunit", 79 | "./vendor/bin/phpcs src --standard=PSR12" 80 | ] 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Client.php: -------------------------------------------------------------------------------- 1 | $this->domain . '/v' . $this->version . '/', 51 | 'headers' => [ 52 | 'User-Agent' => 'TruckersMP API Client (https://github.com/TruckersMP/API-Client)', 53 | 'Content-Type' => 'application/json', 54 | ], 55 | ]); 56 | 57 | $this->httpClient = new GuzzleClient($config); 58 | } 59 | 60 | /** 61 | * Get the configured HTTP client. 62 | * 63 | * @return ClientInterface 64 | */ 65 | public function getHttpClient(): ClientInterface 66 | { 67 | return $this->httpClient; 68 | } 69 | 70 | /** 71 | * Set the instance of the HTTP client. 72 | * 73 | * @param ClientInterface $httpClient 74 | * @return void 75 | */ 76 | public function setHttpClient(ClientInterface $httpClient): void 77 | { 78 | $this->httpClient = $httpClient; 79 | } 80 | 81 | /** 82 | * Get the information for the player with the specified ID. 83 | * 84 | * https://truckersmp.com/developers/api#operation/get-player-id 85 | * 86 | * @param int $id 87 | * @return PlayerRequest 88 | */ 89 | public function player(int $id): PlayerRequest 90 | { 91 | return new PlayerRequest($this, $id); 92 | } 93 | 94 | /** 95 | * Get the bans for the player with the specified ID. 96 | * 97 | * https://truckersmp.com/developers/api#operation/get-bans-id 98 | * 99 | * @param int $id 100 | * @return BanRequest 101 | */ 102 | public function bans(int $id): BanRequest 103 | { 104 | return new BanRequest($this, $id); 105 | } 106 | 107 | /** 108 | * Get the information about the servers. 109 | * 110 | * https://truckersmp.com/developers/api#operation/get-servers 111 | * 112 | * @return ServerRequest 113 | */ 114 | public function servers(): ServerRequest 115 | { 116 | return new ServerRequest($this); 117 | } 118 | 119 | /** 120 | * Get the current game time. 121 | * 122 | * https://truckersmp.com/developers/api#operation/get-game_time 123 | * 124 | * @return GameTimeRequest 125 | */ 126 | public function gameTime(): GameTimeRequest 127 | { 128 | return new GameTimeRequest($this); 129 | } 130 | 131 | /** 132 | * Get the recent and featured companies. 133 | * 134 | * https://truckersmp.com/developers/api#operation/get-vtc 135 | * 136 | * @return CompanyIndexRequest 137 | */ 138 | public function companies(): CompanyIndexRequest 139 | { 140 | return new CompanyIndexRequest($this); 141 | } 142 | 143 | /** 144 | * Get the information for the company with the specified ID or slug. 145 | * 146 | * https://truckersmp.com/developers/api#operation/get-vtc-id 147 | * 148 | * @param string|int $key 149 | * @return CompanyRequest 150 | */ 151 | public function company(string $key): CompanyRequest 152 | { 153 | return new CompanyRequest($this, $key); 154 | } 155 | 156 | /** 157 | * Get the TruckersMP version for ETS2 and ATS. 158 | * 159 | * https://truckersmp.com/developers/api#operation/get-version 160 | * 161 | * @return VersionRequest 162 | */ 163 | public function version(): VersionRequest 164 | { 165 | return new VersionRequest($this); 166 | } 167 | 168 | /** 169 | * Get the current in-game rules. 170 | * 171 | * https://truckersmp.com/developers/api#operation/get-rules 172 | * 173 | * @return RuleRequest 174 | */ 175 | public function rules(): RuleRequest 176 | { 177 | return new RuleRequest($this); 178 | } 179 | 180 | /** 181 | * Get the featured, current, and upcoming events. 182 | * 183 | * https://truckersmp.com/developers/api#operation/get-v2-events 184 | * 185 | * @return EventIndexRequest 186 | */ 187 | public function events(): EventIndexRequest 188 | { 189 | return new EventIndexRequest($this); 190 | } 191 | 192 | /** 193 | * Get the information for the event with the specified ID. 194 | * 195 | * https://truckersmp.com/developers/api#operation/get-events-id 196 | * 197 | * @param int $id 198 | * @return EventRequest 199 | */ 200 | public function event(int $id): EventRequest 201 | { 202 | return new EventRequest($this, $id); 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /src/Exceptions/ApiErrorException.php: -------------------------------------------------------------------------------- 1 | getValue('expiration'); 73 | $this->expiration = $expiration ? new Carbon($expiration, 'UTC') : null; 74 | 75 | $this->timeAdded = new Carbon($this->getValue('timeAdded'), 'UTC'); 76 | $this->active = $this->getValue('active', false); 77 | 78 | if ($this->expiration !== null && $this->active) { 79 | if ($this->expiration->lessThan(Carbon::now('UTC'))) { 80 | $this->active = false; 81 | } 82 | } 83 | 84 | $this->reason = $this->getValue('reason'); 85 | $this->adminName = $this->getValue('adminName'); 86 | $this->adminId = $this->getValue('adminID'); 87 | } 88 | 89 | /** 90 | * Get the expiration date of the ban. 91 | * 92 | * @return Carbon|null 93 | */ 94 | public function getExpirationDate(): ?Carbon 95 | { 96 | return $this->expiration; 97 | } 98 | 99 | /** 100 | * Get the date which the ban was issued. 101 | * 102 | * @return Carbon 103 | */ 104 | public function getCreatedAt(): Carbon 105 | { 106 | return $this->timeAdded; 107 | } 108 | 109 | /** 110 | * Determine if the ban is active or was disabled. 111 | * 112 | * When a ban was issued by mistake, staff may deactivate it manually, but 113 | * it still shows as inactive in the ban history. 114 | * 115 | * Does not change if the ban expires naturally on the expiration date. 116 | * 117 | * @return bool 118 | */ 119 | public function isActive(): bool 120 | { 121 | return $this->active; 122 | } 123 | 124 | /** 125 | * Get the reason why the player was banned. 126 | * 127 | * @return string 128 | */ 129 | public function getReason(): string 130 | { 131 | return $this->reason; 132 | } 133 | 134 | /** 135 | * Get the name of the admin who banned the player. 136 | * 137 | * This field is generally redacted when accessing the public API. 138 | * 139 | * @return string 140 | */ 141 | public function getAdminName(): string 142 | { 143 | return $this->adminName; 144 | } 145 | 146 | /** 147 | * Get the TMP ID of the admin who banned the player. 148 | * 149 | * This field is generally redacted when accessing the public API. 150 | * 151 | * @return int 152 | */ 153 | public function getAdminId(): int 154 | { 155 | return $this->adminId; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/Models/Checksum.php: -------------------------------------------------------------------------------- 1 | dll = $dll; 31 | $this->adb = $adb; 32 | } 33 | 34 | /** 35 | * Get the DLL value. 36 | * 37 | * @return string 38 | */ 39 | public function getDLL(): string 40 | { 41 | return $this->dll; 42 | } 43 | 44 | /** 45 | * Get the ADB value. 46 | * 47 | * @return string 48 | */ 49 | public function getADB(): string 50 | { 51 | return $this->adb; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Models/Company.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 167 | $this->name = $this->getValue('name'); 168 | $this->ownerId = $this->getValue('owner_id'); 169 | $this->ownerName = $this->getValue('owner_username'); 170 | $this->slogan = $this->getValue('slogan'); 171 | $this->tag = $this->getValue('tag'); 172 | 173 | $this->logo = $this->getValue('logo'); 174 | $this->cover = $this->getValue('cover'); 175 | $this->information = $this->getValue('information'); 176 | $this->rules = $this->getValue('rules'); 177 | $this->requirements = $this->getValue('requirements'); 178 | $this->website = $this->getValue('website'); 179 | 180 | $this->social = new Social( 181 | $this->getValue('socials.twitter'), 182 | $this->getValue('socials.facebook'), 183 | $this->getValue('socials.twitch'), 184 | $this->getValue('socials.discord'), 185 | $this->getValue('socials.youtube'), 186 | ); 187 | 188 | $this->games = new Game( 189 | $this->getValue('games.ats'), 190 | $this->getValue('games.ets'), 191 | ); 192 | 193 | $this->membersCount = $this->getValue('members_count'); 194 | $this->recruitment = $this->getValue('recruitment'); 195 | $this->language = $this->getValue('language'); 196 | $this->verified = $this->getValue('verified'); 197 | $this->validated = $this->getValue('validated'); 198 | $this->createdAt = new Carbon($this->getValue('created'), 'UTC'); 199 | } 200 | 201 | /** 202 | * Get the ID of the company. 203 | * 204 | * @return int 205 | */ 206 | public function getId(): int 207 | { 208 | return $this->id; 209 | } 210 | 211 | /** 212 | * Get the name of the company. 213 | * 214 | * @return string 215 | */ 216 | public function getName(): string 217 | { 218 | return $this->name; 219 | } 220 | 221 | /** 222 | * Get the ID of the player who owns the company. 223 | * 224 | * @return int 225 | */ 226 | public function getOwnerId(): int 227 | { 228 | return $this->ownerId; 229 | } 230 | 231 | /** 232 | * Get the name of the player who owns the company. 233 | * 234 | * @return string 235 | */ 236 | public function getOwnerName(): string 237 | { 238 | return $this->ownerName; 239 | } 240 | 241 | /** 242 | * Get the company slogan. 243 | * 244 | * @return string 245 | */ 246 | public function getSlogan(): string 247 | { 248 | return $this->slogan; 249 | } 250 | 251 | /** 252 | * Get the company tag. 253 | * 254 | * @return string 255 | */ 256 | public function getTag(): string 257 | { 258 | return $this->tag; 259 | } 260 | 261 | /** 262 | * Get the URL to the company's logo. 263 | * 264 | * @return string|null 265 | */ 266 | public function getLogo(): ?string 267 | { 268 | return $this->logo; 269 | } 270 | 271 | /** 272 | * Get the URL to the company's cover image. 273 | * 274 | * @return string|null 275 | */ 276 | public function getCover(): ?string 277 | { 278 | return $this->cover; 279 | } 280 | 281 | /** 282 | * Get the information about the company. 283 | * 284 | * @return string|null 285 | */ 286 | public function getInformation(): ?string 287 | { 288 | return $this->information; 289 | } 290 | 291 | /** 292 | * Get the company's rules. 293 | * 294 | * @return string|null 295 | */ 296 | public function getRules(): ?string 297 | { 298 | return $this->rules; 299 | } 300 | 301 | /** 302 | * Get the company's requirements. 303 | * 304 | * @return string|null 305 | */ 306 | public function getRequirements(): ?string 307 | { 308 | return $this->requirements; 309 | } 310 | 311 | /** 312 | * Get the company's website URL. 313 | * 314 | * @return string|null 315 | */ 316 | public function getWebsite(): ?string 317 | { 318 | return $this->website; 319 | } 320 | 321 | /** 322 | * Get the company's social information. 323 | * 324 | * @return Social 325 | */ 326 | public function getSocial(): Social 327 | { 328 | return $this->social; 329 | } 330 | 331 | /** 332 | * Get the games which the company supports. 333 | * 334 | * @return Game 335 | */ 336 | public function getGames(): Game 337 | { 338 | return $this->games; 339 | } 340 | 341 | /** 342 | * Get the number of members that are part of the company. 343 | * 344 | * @return int 345 | */ 346 | public function getMembersCount(): int 347 | { 348 | return $this->membersCount; 349 | } 350 | 351 | /** 352 | * Get the company's recruitment status i.e. Open or Close. 353 | * 354 | * @return string 355 | */ 356 | public function getRecruitment(): string 357 | { 358 | return $this->recruitment; 359 | } 360 | 361 | /** 362 | * Get the company's primary language. 363 | * 364 | * @return string 365 | */ 366 | public function getLanguage(): string 367 | { 368 | return $this->language; 369 | } 370 | 371 | /** 372 | * Check if the company is verified or not. 373 | * 374 | * @return bool 375 | */ 376 | public function isVerified(): bool 377 | { 378 | return $this->verified; 379 | } 380 | 381 | /** 382 | * Check if the company is validated or not. 383 | * 384 | * @return bool 385 | */ 386 | public function isValidated(): bool 387 | { 388 | return $this->validated; 389 | } 390 | 391 | /** 392 | * Get the date which the company was created. 393 | * 394 | * @return Carbon 395 | */ 396 | public function getCreatedDate(): Carbon 397 | { 398 | return $this->createdAt; 399 | } 400 | 401 | /** 402 | * Determine if recruitment is closed for the company. 403 | * 404 | * @return bool 405 | */ 406 | public function isRecruitmentClosed(): bool 407 | { 408 | return $this->recruitment === self::RECRUITMENT_CLOSED; 409 | } 410 | 411 | /** 412 | * Determine if recruitment is open for the company. 413 | * 414 | * @return bool 415 | */ 416 | public function isRecruitmentOpen(): bool 417 | { 418 | return !$this->isRecruitmentClosed(); 419 | } 420 | } 421 | -------------------------------------------------------------------------------- /src/Models/CompanyBan.php: -------------------------------------------------------------------------------- 1 | events = (new Collection($response)) 27 | ->map(fn (array $event) => new Event($client, $event)); 28 | } 29 | 30 | /** 31 | * Get the collection of company events. 32 | * 33 | * @return Collection 34 | */ 35 | public function getEvents(): Collection 36 | { 37 | return $this->events; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Models/CompanyIndex.php: -------------------------------------------------------------------------------- 1 | new Company($client, $company); 41 | 42 | $this->recent = (new Collection($response['recent']))->map($mapCompany); 43 | $this->featured = (new Collection($response['featured']))->map($mapCompany); 44 | $this->featuredCovered = (new Collection($response['featured_cover']))->map($mapCompany); 45 | } 46 | 47 | /** 48 | * Get the last 4 companies created. 49 | * 50 | * @return Collection 51 | */ 52 | public function getRecent(): Collection 53 | { 54 | return $this->recent; 55 | } 56 | 57 | /** 58 | * Get the featured companies on the VTC page. 59 | * 60 | * @return Collection 61 | */ 62 | public function getFeatured(): Collection 63 | { 64 | return $this->featured; 65 | } 66 | 67 | /** 68 | * Get the companies with featured cover images on the VTC page. 69 | * 70 | * @return Collection 71 | */ 72 | public function getFeaturedCovered(): Collection 73 | { 74 | return $this->featuredCovered; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Models/CompanyMember.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 78 | $this->userId = $this->getValue('user_id'); 79 | $this->username = $this->getValue('username'); 80 | $this->steamId = (string) $this->getValue('steam_id'); 81 | $this->roleId = $this->getValue('role_id'); 82 | $this->role = $this->getValue('role'); 83 | $this->owner = $this->getValue('is_owner', false); 84 | $this->joinDate = new Carbon($this->getValue('joinDate'), 'UTC'); 85 | } 86 | 87 | /** 88 | * Get the company member ID. 89 | * 90 | * @return int 91 | */ 92 | public function getId(): int 93 | { 94 | return $this->id; 95 | } 96 | 97 | /** 98 | * Get the TMP player ID of the member. 99 | * 100 | * @return int 101 | */ 102 | public function getUserId(): int 103 | { 104 | return $this->userId; 105 | } 106 | 107 | /** 108 | * Get the name of the member. 109 | * 110 | * @return string 111 | */ 112 | public function getUsername(): string 113 | { 114 | return $this->username; 115 | } 116 | 117 | /** 118 | * Get the Steam ID of the member. 119 | * 120 | * @return string 121 | */ 122 | public function getSteamId(): string 123 | { 124 | return $this->steamId; 125 | } 126 | 127 | /** 128 | * Get the Role ID of the member. 129 | * 130 | * @return int 131 | */ 132 | public function getRoleId(): int 133 | { 134 | return $this->roleId; 135 | } 136 | 137 | /** 138 | * Get the name of member's role. 139 | * 140 | * @return string 141 | */ 142 | public function getRole(): string 143 | { 144 | return $this->role; 145 | } 146 | 147 | /** 148 | * Check whether the member has owner permissions. 149 | * 150 | * @return bool 151 | */ 152 | public function isOwner(): bool 153 | { 154 | return $this->owner; 155 | } 156 | 157 | /** 158 | * Get the date that the member joined the company. 159 | * 160 | * @return Carbon 161 | */ 162 | public function getJoinDate(): Carbon 163 | { 164 | return $this->joinDate; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/Models/CompanyMemberIndex.php: -------------------------------------------------------------------------------- 1 | members = (new Collection($response['members'])) 34 | ->map(fn (array $member) => new CompanyMember($client, $member)); 35 | 36 | $this->count = $response['members_count']; 37 | } 38 | 39 | /** 40 | * Get the collection of company members. 41 | * 42 | * @return Collection 43 | */ 44 | public function getMembers(): Collection 45 | { 46 | return $this->members; 47 | } 48 | 49 | /** 50 | * Get the member count for the company. 51 | * 52 | * @return int 53 | */ 54 | public function getCount(): int 55 | { 56 | return $this->count; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Models/CompanyPost.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 85 | $this->title = $this->getValue('title'); 86 | $this->summary = $this->getValue('content_summary'); 87 | $this->content = $this->getValue('content'); 88 | $this->authorId = $this->getValue('author_id'); 89 | $this->author = $this->getValue('author'); 90 | $this->pinned = $this->getValue('pinned', false); 91 | $this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC'); 92 | $this->publishedAt = new Carbon($this->getValue('published_at'), 'UTC'); 93 | } 94 | 95 | /** 96 | * Get the ID of the post. 97 | * 98 | * @return int 99 | */ 100 | public function getId(): int 101 | { 102 | return $this->id; 103 | } 104 | 105 | /** 106 | * Get the title of the post. 107 | * 108 | * @return string 109 | */ 110 | public function getTitle(): string 111 | { 112 | return $this->title; 113 | } 114 | 115 | /** 116 | * Get the post summary. 117 | * 118 | * @return string 119 | */ 120 | public function getSummary(): string 121 | { 122 | return $this->summary; 123 | } 124 | 125 | /** 126 | * Get the post content. 127 | * 128 | * @return string|null 129 | */ 130 | public function getContent(): ?string 131 | { 132 | return $this->content; 133 | } 134 | 135 | /** 136 | * Get the TMP ID of the author who made the post. 137 | * 138 | * @return int 139 | */ 140 | public function getAuthorId(): int 141 | { 142 | return $this->authorId; 143 | } 144 | 145 | /** 146 | * Get the name of the author who made the post. 147 | * 148 | * @return string 149 | */ 150 | public function getAuthor(): string 151 | { 152 | return $this->author; 153 | } 154 | 155 | /** 156 | * Check if the post is pinned on the company's page. 157 | * 158 | * @return bool 159 | */ 160 | public function isPinned(): bool 161 | { 162 | return $this->pinned; 163 | } 164 | 165 | /** 166 | * Get the date which the post was last updated at. 167 | * 168 | * @return Carbon 169 | */ 170 | public function getUpdatedAt(): Carbon 171 | { 172 | return $this->updatedAt; 173 | } 174 | 175 | /** 176 | * Get the date which the post was published. 177 | * 178 | * @return Carbon 179 | */ 180 | public function getPublishedAt(): Carbon 181 | { 182 | return $this->publishedAt; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /src/Models/CompanyRole.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 64 | $this->name = $this->getValue('name'); 65 | $this->order = $this->getValue('order'); 66 | $this->owner = $this->getValue('owner', false); 67 | $this->createdAt = new Carbon($this->getValue('created_at'), 'UTC'); 68 | $this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC'); 69 | } 70 | 71 | /** 72 | * Get the ID of the role. 73 | * 74 | * @return int 75 | */ 76 | public function getId(): int 77 | { 78 | return $this->id; 79 | } 80 | 81 | /** 82 | * Get the name of the role. 83 | * 84 | * @return string 85 | */ 86 | public function getName(): string 87 | { 88 | return $this->name; 89 | } 90 | 91 | /** 92 | * Get the order ID for the role. The lower the order ID, the higher it shows in the list. 93 | * 94 | * @return int 95 | */ 96 | public function getOrder(): int 97 | { 98 | return $this->order; 99 | } 100 | 101 | /** 102 | * Check if the role is the role of the company owner. 103 | * 104 | * @return bool 105 | */ 106 | public function isOwner(): bool 107 | { 108 | return $this->owner; 109 | } 110 | 111 | /** 112 | * Get the date which the role was created. 113 | * 114 | * @return Carbon 115 | */ 116 | public function getCreatedAt(): Carbon 117 | { 118 | return $this->createdAt; 119 | } 120 | 121 | /** 122 | * Get the date which the role was last updated. 123 | * 124 | * @return Carbon 125 | */ 126 | public function getUpdatedAt(): Carbon 127 | { 128 | return $this->updatedAt; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/Models/Dlc.php: -------------------------------------------------------------------------------- 1 | id = intval($id); 33 | $this->name = $name; 34 | } 35 | 36 | /** 37 | * Get the DLC ID. 38 | * 39 | * @return int 40 | */ 41 | public function getId(): int 42 | { 43 | return $this->id; 44 | } 45 | 46 | /** 47 | * Get the DLC name. 48 | * 49 | * @return string 50 | */ 51 | public function getName(): string 52 | { 53 | return $this->name; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Models/Event.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 198 | 199 | $this->eventType = new EventType( 200 | $this->getValue('event_type.key'), 201 | $this->getValue('event_type.name'), 202 | ); 203 | 204 | $this->name = $this->getValue('name'); 205 | $this->slug = $this->getValue('slug'); 206 | $this->game = $this->getValue('game'); 207 | 208 | $this->server = new EventServer( 209 | $this->getValue('server.id'), 210 | $this->getValue('server.name'), 211 | ); 212 | 213 | $this->language = $this->getValue('language'); 214 | 215 | $this->departure = new EventLocation( 216 | $this->getValue('departure.location'), 217 | $this->getValue('departure.city'), 218 | ); 219 | 220 | $this->arrive = new EventLocation( 221 | $this->getValue('arrive.location'), 222 | $this->getValue('arrive.city'), 223 | ); 224 | 225 | $this->startAt = new Carbon($this->getValue('start_at'), 'UTC'); 226 | 227 | $meetupAt = $this->getValue('meetup_at'); 228 | $this->meetupAt = $meetupAt ? new Carbon($meetupAt, 'UTC') : null; 229 | 230 | $this->banner = $this->getValue('banner'); 231 | $this->map = $this->getValue('map'); 232 | $this->description = $this->getValue('description'); 233 | $this->rule = $this->getValue('rule'); 234 | $this->voiceLink = $this->getValue('voice_link'); 235 | $this->externalLink = $this->getValue('external_link'); 236 | $this->featured = $this->getValue('featured'); 237 | 238 | if ($this->getValue('vtc.id', 0) !== 0 && $this->getValue('vtc.name')) { 239 | $this->company = new EventCompany( 240 | $this->getValue('vtc.id'), 241 | $this->getValue('vtc.name'), 242 | ); 243 | } 244 | 245 | $this->organizer = new EventOrganizer( 246 | $this->getValue('user.id'), 247 | $this->getValue('user.username'), 248 | ); 249 | 250 | $this->url = $this->getValue('url'); 251 | 252 | $this->attendance = new EventAttendance($client, $this->getValue('attendances', [])); 253 | 254 | $this->dlcs = (new Collection($this->getValue('dlcs', [])))->mapInto(Dlc::class); 255 | 256 | $this->createdAt = new Carbon($this->getValue('created_at'), 'UTC'); 257 | $this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC'); 258 | } 259 | 260 | /** 261 | * Get the ID of the event. 262 | * 263 | * @return int 264 | */ 265 | public function getId(): int 266 | { 267 | return $this->id; 268 | } 269 | 270 | /** 271 | * Get the type of the event. 272 | * 273 | * @return EventType 274 | */ 275 | public function getEventType(): EventType 276 | { 277 | return $this->eventType; 278 | } 279 | 280 | /** 281 | * Get the name of the event. 282 | * 283 | * @return string 284 | */ 285 | public function getName(): string 286 | { 287 | return $this->name; 288 | } 289 | 290 | /** 291 | * Get the slug of the event. 292 | * 293 | * @return string 294 | */ 295 | public function getSlug(): string 296 | { 297 | return $this->slug; 298 | } 299 | 300 | /** 301 | * Get the game the event is hosted on. 302 | * 303 | * @return string 304 | */ 305 | public function getGame(): string 306 | { 307 | return $this->game; 308 | } 309 | 310 | /** 311 | * Get the server the event is hosted on. 312 | * 313 | * @return EventServer 314 | */ 315 | public function getServer(): EventServer 316 | { 317 | return $this->server; 318 | } 319 | 320 | /** 321 | * Get the language of the event. 322 | * 323 | * @return string 324 | */ 325 | public function getLanguage(): string 326 | { 327 | return $this->language; 328 | } 329 | 330 | /** 331 | * Get the departure location of the event. 332 | * 333 | * @return EventLocation 334 | */ 335 | public function getDeparture(): EventLocation 336 | { 337 | return $this->departure; 338 | } 339 | 340 | /** 341 | * Get the arrival location of the event. 342 | * 343 | * @return EventLocation 344 | */ 345 | public function getArrive(): EventLocation 346 | { 347 | return $this->arrive; 348 | } 349 | 350 | /** 351 | * Get the start date of the event. 352 | * 353 | * @return Carbon 354 | */ 355 | public function getStartAt(): Carbon 356 | { 357 | return $this->startAt; 358 | } 359 | 360 | /** 361 | * Get the meetup date of the event. 362 | * 363 | * @return Carbon|null 364 | */ 365 | public function getMeetupAt(): ?Carbon 366 | { 367 | return $this->meetupAt; 368 | } 369 | 370 | /** 371 | * Get the banner of the event. 372 | * 373 | * @return string|null 374 | */ 375 | public function getBanner(): ?string 376 | { 377 | return $this->banner; 378 | } 379 | 380 | /** 381 | * Get the map of the event. 382 | * 383 | * @return string|null 384 | */ 385 | public function getMap(): ?string 386 | { 387 | return $this->map; 388 | } 389 | 390 | /** 391 | * Get the description of the event. 392 | * 393 | * @return string 394 | */ 395 | public function getDescription(): string 396 | { 397 | return $this->description; 398 | } 399 | 400 | /** 401 | * Get the rule of the event. 402 | * 403 | * @return string|null 404 | */ 405 | public function getRule(): ?string 406 | { 407 | return $this->rule; 408 | } 409 | 410 | /** 411 | * Get the voice link of the event. 412 | * 413 | * @return string|null 414 | */ 415 | public function getVoiceLink(): ?string 416 | { 417 | return $this->voiceLink; 418 | } 419 | 420 | /** 421 | * Get the external link of the event. 422 | * 423 | * @return string|null 424 | */ 425 | public function getExternalLink(): ?string 426 | { 427 | return $this->externalLink; 428 | } 429 | 430 | /** 431 | * Get the featured status of the event. 432 | * 433 | * @return string|null 434 | */ 435 | public function getFeatured(): ?string 436 | { 437 | return $this->featured; 438 | } 439 | 440 | /** 441 | * Get the company of the event. 442 | * 443 | * @return EventCompany|null 444 | */ 445 | public function getCompany(): ?EventCompany 446 | { 447 | return $this->company; 448 | } 449 | 450 | /** 451 | * Get the organizer of the event. 452 | * 453 | * @return EventOrganizer 454 | */ 455 | public function getOrganizer(): EventOrganizer 456 | { 457 | return $this->organizer; 458 | } 459 | 460 | /** 461 | * Get the attendance of the event. 462 | * 463 | * @return EventAttendance 464 | */ 465 | public function getAttendance(): EventAttendance 466 | { 467 | return $this->attendance; 468 | } 469 | 470 | /** 471 | * Get the required DLCs of the event. 472 | * 473 | * @return Collection|null 474 | */ 475 | public function getDlcs(): ?Collection 476 | { 477 | return $this->dlcs; 478 | } 479 | 480 | /** 481 | * Get the url of the event. 482 | * 483 | * @return string 484 | */ 485 | public function getUrl(): string 486 | { 487 | return $this->url; 488 | } 489 | 490 | /** 491 | * Get the created at of the event. 492 | * 493 | * @return Carbon 494 | */ 495 | public function getCreatedAt(): Carbon 496 | { 497 | return $this->createdAt; 498 | } 499 | 500 | /** 501 | * Get the updated at of the event. 502 | * 503 | * @return Carbon 504 | */ 505 | public function getUpdatedAt(): Carbon 506 | { 507 | return $this->updatedAt; 508 | } 509 | } 510 | -------------------------------------------------------------------------------- /src/Models/EventAttendance.php: -------------------------------------------------------------------------------- 1 | new EventAttendee($client, $attendee); 43 | $mapCompany = fn (array $attendee) => new EventCompanyAttendee($client, $attendee); 44 | 45 | $this->confirmedUsers = (new Collection($this->getValue('confirmed_users', [])))->map($mapUser); 46 | $this->unsureUsers = (new Collection($this->getValue('unsure_users', [])))->map($mapUser); 47 | $this->confirmedCompanies = (new Collection($this->getValue('confirmed_vtcs', [])))->map($mapCompany); 48 | } 49 | 50 | /** 51 | * Get the confirmed attendee count. 52 | * 53 | * @return int 54 | * 55 | * @deprecated Use the collection of confirmed users instead. 56 | */ 57 | public function getConfirmed(): int 58 | { 59 | return $this->getConfirmedUsers()->count(); 60 | } 61 | 62 | /** 63 | * Get the unsure attendee count. 64 | * 65 | * @return int 66 | * 67 | * @deprecated Use the collection of unsure users instead. 68 | */ 69 | public function getUnsure(): int 70 | { 71 | return $this->getUnsureUsers()->count(); 72 | } 73 | 74 | /** 75 | * Get the confirmed attendees. 76 | * 77 | * @return Collection 78 | */ 79 | public function getConfirmedUsers(): Collection 80 | { 81 | return $this->confirmedUsers; 82 | } 83 | 84 | /** 85 | * Get the unsure attendees. 86 | * 87 | * @return Collection 88 | */ 89 | public function getUnsureUsers(): Collection 90 | { 91 | return $this->unsureUsers; 92 | } 93 | 94 | /** 95 | * Get the confirmed companies. 96 | * 97 | * @return Collection 98 | */ 99 | public function getConfirmedCompanies(): Collection 100 | { 101 | return $this->confirmedCompanies; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/Models/EventAttendee.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 57 | $this->username = $this->getValue('username'); 58 | $this->following = $this->getValue('following', false); 59 | $this->createdAt = new Carbon($this->getValue('created_at'), 'UTC'); 60 | $this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC'); 61 | } 62 | 63 | /** 64 | * Get the ID of the attendee. 65 | * 66 | * @return int 67 | */ 68 | public function getId(): int 69 | { 70 | return $this->id; 71 | } 72 | 73 | /** 74 | * Get the username of the attendee. 75 | * 76 | * @return string 77 | */ 78 | public function getUsername(): string 79 | { 80 | return $this->username; 81 | } 82 | 83 | /** 84 | * Get the event following status of the attendee. 85 | * 86 | * @return bool 87 | */ 88 | public function isFollowing(): bool 89 | { 90 | return $this->following; 91 | } 92 | 93 | /** 94 | * Get the created at date of the attendee. 95 | * 96 | * @return Carbon 97 | */ 98 | public function getCreatedAt(): Carbon 99 | { 100 | return $this->createdAt; 101 | } 102 | 103 | /** 104 | * Get the updated at date of the attendee. 105 | * 106 | * @return Carbon 107 | */ 108 | public function getUpdatedAt(): Carbon 109 | { 110 | return $this->updatedAt; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/Models/EventCompany.php: -------------------------------------------------------------------------------- 1 | id = $id; 33 | $this->name = $name; 34 | } 35 | 36 | /** 37 | * Get the ID. 38 | * 39 | * @return int 40 | */ 41 | public function getId(): int 42 | { 43 | return $this->id; 44 | } 45 | 46 | /** 47 | * Get the name. 48 | * 49 | * @return string 50 | */ 51 | public function getName(): string 52 | { 53 | return $this->name; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Models/EventCompanyAttendee.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 57 | $this->name = $this->getValue('name'); 58 | $this->following = $this->getValue('following', false); 59 | $this->createdAt = new Carbon($this->getValue('created_at'), 'UTC'); 60 | $this->updatedAt = new Carbon($this->getValue('updated_at'), 'UTC'); 61 | } 62 | 63 | /** 64 | * Get the ID of the attending company. 65 | * 66 | * @return int 67 | */ 68 | public function getId(): int 69 | { 70 | return $this->id; 71 | } 72 | 73 | /** 74 | * Get the name of the attending company. 75 | * 76 | * @return string 77 | */ 78 | public function getName(): string 79 | { 80 | return $this->name; 81 | } 82 | 83 | /** 84 | * Get the event following status of the attending company. 85 | * 86 | * @return bool 87 | */ 88 | public function isFollowing(): bool 89 | { 90 | return $this->following; 91 | } 92 | 93 | /** 94 | * Get the date and time the company marked their attendance. 95 | * 96 | * @return Carbon 97 | */ 98 | public function getCreatedAt(): Carbon 99 | { 100 | return $this->createdAt; 101 | } 102 | 103 | /** 104 | * Get the date and time the company updated their attendance. 105 | * 106 | * @return Carbon 107 | */ 108 | public function getUpdatedAt(): Carbon 109 | { 110 | return $this->updatedAt; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/Models/EventIndex.php: -------------------------------------------------------------------------------- 1 | new Event($client, $event); 41 | 42 | $this->featured = (new Collection($response['featured'] ?? []))->map($mapEvent); 43 | $this->today = (new Collection($response['today'] ?? []))->map($mapEvent); 44 | $this->upcoming = (new Collection($response['upcoming'] ?? []))->map($mapEvent); 45 | } 46 | 47 | /** 48 | * Get the featured events. 49 | * 50 | * @return Collection 51 | */ 52 | public function getFeatured(): Collection 53 | { 54 | return $this->featured; 55 | } 56 | 57 | /** 58 | * Get today's events. 59 | * 60 | * @return Collection 61 | */ 62 | public function getToday(): Collection 63 | { 64 | return $this->today; 65 | } 66 | 67 | /** 68 | * Get the upcoming events. 69 | * 70 | * @return Collection 71 | */ 72 | public function getUpcoming(): Collection 73 | { 74 | return $this->upcoming; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Models/EventLocation.php: -------------------------------------------------------------------------------- 1 | location = $location; 33 | $this->city = $city; 34 | } 35 | 36 | /** 37 | * Get the location. 38 | * 39 | * @return string 40 | */ 41 | public function getLocation(): string 42 | { 43 | return $this->location; 44 | } 45 | 46 | /** 47 | * Get the city. 48 | * 49 | * @return string 50 | */ 51 | public function getCity(): string 52 | { 53 | return $this->city; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Models/EventOrganizer.php: -------------------------------------------------------------------------------- 1 | id = $id; 33 | $this->username = $username; 34 | } 35 | 36 | /** 37 | * Get the ID. 38 | * 39 | * @return int 40 | */ 41 | public function getId(): int 42 | { 43 | return $this->id; 44 | } 45 | 46 | /** 47 | * Get the username. 48 | * 49 | * @return string 50 | */ 51 | public function getUsername(): string 52 | { 53 | return $this->username; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Models/EventServer.php: -------------------------------------------------------------------------------- 1 | id = $id; 33 | $this->name = $name; 34 | } 35 | 36 | /** 37 | * Get the ID. 38 | * 39 | * @return int 40 | */ 41 | public function getId(): int 42 | { 43 | return $this->id; 44 | } 45 | 46 | /** 47 | * Get the name. 48 | * 49 | * @return string 50 | */ 51 | public function getName(): string 52 | { 53 | return $this->name; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Models/EventType.php: -------------------------------------------------------------------------------- 1 | key = $key; 33 | $this->name = $name; 34 | } 35 | 36 | /** 37 | * Get the key. 38 | * 39 | * @return string 40 | */ 41 | public function getKey(): string 42 | { 43 | return $this->key; 44 | } 45 | 46 | /** 47 | * Get the value. 48 | * 49 | * @return string 50 | */ 51 | public function getName(): string 52 | { 53 | return $this->name; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Models/Game.php: -------------------------------------------------------------------------------- 1 | ats = $ats; 31 | $this->ets = $ets; 32 | } 33 | 34 | /** 35 | * Determines if the entity has/supports American Truck Simulator. 36 | * 37 | * @return bool 38 | */ 39 | public function isAts(): bool 40 | { 41 | return $this->ats; 42 | } 43 | 44 | /** 45 | * Determines if the entity has/supports Euro Truck Simulator 2. 46 | * 47 | * @return bool 48 | */ 49 | public function isEts(): bool 50 | { 51 | return $this->ets; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Models/GameTime.php: -------------------------------------------------------------------------------- 1 | getValue('game_time', 0); 29 | 30 | $time['hours'] = $time['minutes'] / 60; 31 | $time['minutes'] %= 60; 32 | 33 | $time['days'] = $time['hours'] / 24; 34 | $time['hours'] %= 24; 35 | 36 | $time['months'] = $time['days'] / 30; 37 | $time['days'] %= 30; 38 | 39 | $time['years'] = intval($time['months'] / 12); 40 | $time['months'] %= 12; 41 | 42 | $this->time = Carbon::create( 43 | $time['years'], 44 | $time['months'], 45 | $time['days'], 46 | $time['hours'], 47 | $time['minutes'] 48 | ); 49 | } 50 | 51 | /** 52 | * Get the game time as a Carbon instance. 53 | * 54 | * @return Carbon 55 | */ 56 | public function getTime(): Carbon 57 | { 58 | return $this->time; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Models/Model.php: -------------------------------------------------------------------------------- 1 | client = $client; 36 | $this->data = $data; 37 | } 38 | 39 | /** 40 | * Return a value by key. 41 | * 42 | * This supports the dot notation. 43 | * 44 | * @param string $key 45 | * @param mixed|null $default 46 | * @return mixed|null 47 | */ 48 | protected function getValue(string $key, $default = null) 49 | { 50 | if (strpos($key, '.') === false) { 51 | return $this->data[$key] ?? $default; 52 | } 53 | 54 | $data = $this->data; 55 | 56 | foreach (explode('.', $key) as $part) { 57 | if (!is_array($data) || !array_key_exists($part, $data)) { 58 | return $default; 59 | } 60 | 61 | $data = &$data[$part]; 62 | } 63 | 64 | return $data; 65 | } 66 | 67 | /** 68 | * Convert the model into a pure array. 69 | * 70 | * @return array 71 | */ 72 | public function toArray(): array 73 | { 74 | return $this->data; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Models/Patreon.php: -------------------------------------------------------------------------------- 1 | isPatron = $this->getValue('isPatron', false); 77 | $this->active = $this->getValue('active', false); 78 | $this->color = $this->getValue('color'); 79 | $this->tierId = $this->getValue('tierId'); 80 | $this->currentPledge = $this->getValue('currentPledge'); 81 | $this->lifetimePledge = $this->getValue('lifetimePledge'); 82 | $this->nextPledge = $this->getValue('nextPledge'); 83 | $this->hidden = $this->getValue('hidden'); 84 | } 85 | 86 | /** 87 | * Get if the current player is a patron. 88 | * 89 | * @return bool 90 | */ 91 | public function isPatron(): bool 92 | { 93 | return $this->isPatron; 94 | } 95 | 96 | /** 97 | * Get if the player's patron subscription is active. 98 | * 99 | * @return mixed 100 | */ 101 | public function isActive(): bool 102 | { 103 | return $this->active; 104 | } 105 | 106 | /** 107 | * Get the HEX code for subscribed tier. 108 | * 109 | * @return string|null 110 | */ 111 | public function getColor(): ?string 112 | { 113 | return $this->color; 114 | } 115 | 116 | /** 117 | * Get the player's tier ID. 118 | * 119 | * @return int|null 120 | */ 121 | public function getTierId(): ?int 122 | { 123 | return $this->tierId; 124 | } 125 | 126 | /** 127 | * Get the player's current pledge. 128 | * 129 | * @return int|null 130 | */ 131 | public function getCurrentPledge(): ?int 132 | { 133 | return $this->currentPledge; 134 | } 135 | 136 | /** 137 | * Get the player's lifetime pledge. 138 | * 139 | * @return int|null 140 | */ 141 | public function getLifetimePledge(): ?int 142 | { 143 | return $this->lifetimePledge; 144 | } 145 | 146 | /** 147 | * Get the player's next pledge. 148 | * 149 | * @return int|null 150 | */ 151 | public function getNextPledge(): ?int 152 | { 153 | return $this->nextPledge; 154 | } 155 | 156 | /** 157 | * Get if the user has their patreon information hidden. 158 | * 159 | * @return bool|null 160 | */ 161 | public function isHidden(): ?bool 162 | { 163 | return $this->hidden; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/Models/Player.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 212 | $this->name = $this->getValue('name'); 213 | $this->avatar = $this->getValue('avatar'); 214 | $this->smallAvatar = $this->getValue('smallAvatar'); 215 | $this->joinDate = new Carbon($this->getValue('joinDate'), 'UTC'); 216 | $this->steamID64 = $this->getValue('steamID'); 217 | $this->groupId = $this->getValue('groupID'); 218 | $this->groupName = $this->getValue('groupName'); 219 | $this->groupColor = $this->getValue('groupColor'); 220 | 221 | $bannedUntil = $this->getValue('bannedUntil'); 222 | $this->bannedUntil = $bannedUntil ? new Carbon($bannedUntil, 'UTC') : null; 223 | 224 | $this->isBanned = $this->getValue('banned'); 225 | $this->activeBanCount = $this->getValue('bansCount'); 226 | $this->displayBans = $this->getValue('displayBans', false); 227 | 228 | $this->patreon = new Patreon($client, $this->getValue('patreon', [])); 229 | 230 | $history = new Collection($this->getValue('vtcHistory', [])); 231 | $this->companyHistory = $history->map(fn (array $entry) => new PlayerCompanyHistory($client, $entry)); 232 | 233 | $achievements = new Collection($this->getValue('achievements', [])); 234 | $this->achievements = $achievements->map(fn (array $entry) => new PlayerAchievement($client, $entry)); 235 | 236 | $awards = new Collection($this->getValue('awards', [])); 237 | $this->awards = $awards->map(fn (array $entry) => new PlayerAward($client, $entry)); 238 | 239 | $this->isStaff = $this->getValue('permissions.isStaff', false); 240 | $this->isUpperStaff = $this->getValue('permissions.isUpperStaff', false); 241 | $this->inGameAdmin = $this->getValue('permissions.isGameAdmin', false); 242 | $this->companyId = $this->getValue('vtc.id'); 243 | $this->companyName = $this->getValue('vtc.name'); 244 | $this->companyTag = $this->getValue('vtc.tag'); 245 | $this->isInCompany = $this->getValue('vtc.inVTC', false); 246 | $this->companyMemberId = $this->getValue('vtc.memberID'); 247 | $this->discordSnowflake = $this->getValue('discordSnowflake'); 248 | } 249 | 250 | /** 251 | * Get the player's ID. 252 | * 253 | * @return int 254 | */ 255 | public function getId(): int 256 | { 257 | return $this->id; 258 | } 259 | 260 | /** 261 | * Get the name of the player. 262 | * 263 | * @return string 264 | */ 265 | public function getName(): string 266 | { 267 | return $this->name; 268 | } 269 | 270 | /** 271 | * Get the URL of the player's avatar. 272 | * 273 | * @return string 274 | */ 275 | public function getAvatar(): string 276 | { 277 | return $this->avatar; 278 | } 279 | 280 | /** 281 | * Get the URL of the player's small avatar. 282 | * 283 | * @return string 284 | */ 285 | public function getSmallAvatar(): string 286 | { 287 | return $this->smallAvatar; 288 | } 289 | 290 | /** 291 | * Get the date which the player joined. 292 | * 293 | * @return Carbon 294 | */ 295 | public function getJoinDate(): Carbon 296 | { 297 | return $this->joinDate; 298 | } 299 | 300 | /** 301 | * Get the player's Steam ID. 302 | * 303 | * @return string 304 | */ 305 | public function getSteamID64(): string 306 | { 307 | return $this->steamID64; 308 | } 309 | 310 | /** 311 | * Get the player's group ID. 312 | * 313 | * @return int 314 | */ 315 | public function getGroupId(): int 316 | { 317 | return $this->groupId; 318 | } 319 | 320 | /** 321 | * Get the name of the player's group. 322 | * 323 | * @return string 324 | */ 325 | public function getGroupName(): string 326 | { 327 | return $this->groupName; 328 | } 329 | 330 | /** 331 | * Get the player's group color. 332 | * 333 | * @return string 334 | */ 335 | public function getGroupColor(): string 336 | { 337 | return $this->groupColor; 338 | } 339 | 340 | /** 341 | * Check if the player is banned. 342 | * 343 | * @return bool 344 | */ 345 | public function isBanned(): bool 346 | { 347 | return $this->isBanned; 348 | } 349 | 350 | /** 351 | * If the player is banned, get the date they are banned until. 352 | * 353 | * @return Carbon|null 354 | */ 355 | public function getBannedUntilDate(): ?Carbon 356 | { 357 | return $this->bannedUntil; 358 | } 359 | 360 | /** 361 | * Get the player's number of active bans, or null if staff. 362 | * 363 | * @return int|null 364 | */ 365 | public function getActiveBanCount(): ?int 366 | { 367 | return $this->activeBanCount; 368 | } 369 | 370 | /** 371 | * Check if the player has their bans hidden. 372 | * 373 | * @return bool 374 | */ 375 | public function hasBansHidden(): bool 376 | { 377 | return !$this->displayBans; 378 | } 379 | 380 | /** 381 | * Get the player's patreon information. 382 | * 383 | * @return Patreon 384 | * 385 | * @deprecated Renamed to a proper get method. 386 | * @see Player::getPatreon() 387 | */ 388 | public function patreon(): Patreon 389 | { 390 | return $this->patreon; 391 | } 392 | 393 | /** 394 | * Get the player's Patreon information. 395 | * 396 | * @return Patreon 397 | */ 398 | public function getPatreon(): Patreon 399 | { 400 | return $this->patreon; 401 | } 402 | 403 | /** 404 | * Check if the player is a staff member. 405 | * 406 | * @return bool 407 | */ 408 | public function isStaff(): bool 409 | { 410 | return $this->isStaff; 411 | } 412 | 413 | /** 414 | * Check if the player is an upper staff member. 415 | * 416 | * @return bool 417 | */ 418 | public function isUpperStaff(): bool 419 | { 420 | return $this->isUpperStaff; 421 | } 422 | 423 | /** 424 | * Check if the player is an in-game admin. 425 | * 426 | * @return bool 427 | */ 428 | public function isAdmin(): bool 429 | { 430 | return $this->inGameAdmin; 431 | } 432 | 433 | /** 434 | * Get the player's company ID. 435 | * 436 | * @return int 437 | */ 438 | public function getCompanyId(): int 439 | { 440 | return $this->companyId; 441 | } 442 | 443 | /** 444 | * Get the name of the player's company. 445 | * 446 | * @return string 447 | */ 448 | public function getCompanyName(): string 449 | { 450 | return $this->companyName; 451 | } 452 | 453 | /** 454 | * Get the tag of the player's company. 455 | * 456 | * @return string 457 | */ 458 | public function getCompanyTag(): string 459 | { 460 | return $this->companyTag; 461 | } 462 | 463 | /** 464 | * Check if the player is in a company. 465 | * 466 | * @return bool 467 | */ 468 | public function isInCompany(): bool 469 | { 470 | return $this->isInCompany; 471 | } 472 | 473 | /** 474 | * Get the player's company member ID. 475 | * 476 | * @return int 477 | */ 478 | public function getCompanyMemberId(): int 479 | { 480 | return $this->companyMemberId; 481 | } 482 | 483 | /** 484 | * Get the player's history of company memberships. 485 | * 486 | * @return Collection 487 | */ 488 | public function getCompanyHistory(): Collection 489 | { 490 | return $this->companyHistory; 491 | } 492 | 493 | /** 494 | * Get the player's Discord Snowflake. 495 | * 496 | * @return string|null 497 | */ 498 | public function getDiscordSnowflake(): ?string 499 | { 500 | return $this->discordSnowflake; 501 | } 502 | 503 | /** 504 | * Get the player's achievements sorted from the oldest. 505 | * 506 | * Returns an empty collection if they are private. 507 | * 508 | * @return Collection 509 | */ 510 | public function getAchievements(): Collection 511 | { 512 | return $this->achievements; 513 | } 514 | 515 | /** 516 | * Get the player's awards sorted from the oldest. 517 | * 518 | * Returns an empty collection if they are private. 519 | * 520 | * @return Collection 521 | */ 522 | public function getAwards(): Collection 523 | { 524 | return $this->awards; 525 | } 526 | 527 | /** 528 | * Get the player's bans. 529 | * 530 | * @return Collection 531 | * 532 | * @throws ApiErrorException 533 | * @throws ClientExceptionInterface 534 | */ 535 | public function getBans(): Collection 536 | { 537 | return (new BanRequest($this->client, $this->id))->get(); 538 | } 539 | 540 | /** 541 | * Get events created by the player. 542 | * 543 | * @return Collection 544 | * 545 | * @throws ApiErrorException 546 | * @throws ClientExceptionInterface 547 | */ 548 | public function getEvents(): Collection 549 | { 550 | $request = new EventUserRequest( 551 | $this->client, 552 | $this->id, 553 | ); 554 | 555 | return $request->get(); 556 | } 557 | 558 | /** 559 | * Get the player's company. 560 | * 561 | * @return Company|null 562 | * 563 | * @throws ApiErrorException 564 | * @throws ClientExceptionInterface 565 | */ 566 | public function getCompany(): ?Company 567 | { 568 | $company = null; 569 | 570 | if ($this->isInCompany()) { 571 | $request = new CompanyRequest( 572 | $this->client, 573 | $this->companyId, 574 | ); 575 | 576 | $company = $request->get(); 577 | } 578 | 579 | return $company; 580 | } 581 | 582 | /** 583 | * Get the CompanyMember instance for the player. 584 | * 585 | * @return CompanyMember|null 586 | * 587 | * @throws ApiErrorException 588 | * @throws ClientExceptionInterface 589 | */ 590 | public function getCompanyMember(): ?CompanyMember 591 | { 592 | $member = null; 593 | 594 | if ($this->isInCompany()) { 595 | $request = new MemberRequest( 596 | $this->client, 597 | $this->companyId, 598 | $this->companyMemberId, 599 | ); 600 | 601 | $member = $request->get(); 602 | } 603 | 604 | return $member; 605 | } 606 | 607 | /** 608 | * Get the CompanyRole instance for the player's company role. 609 | * 610 | * @return CompanyRole|null 611 | * 612 | * @throws ApiErrorException 613 | * @throws ClientExceptionInterface 614 | * 615 | * @deprecated Not recommended to use due to another internal request. 616 | */ 617 | public function getCompanyRole(): ?CompanyRole 618 | { 619 | $role = null; 620 | 621 | if ($this->isInCompany()) { 622 | $member = $this->getCompanyMember(); 623 | 624 | $request = new RoleRequest( 625 | $this->client, 626 | $this->companyId, 627 | $member->getRoleId(), 628 | ); 629 | 630 | $role = $request->get(); 631 | } 632 | 633 | return $role; 634 | } 635 | } 636 | -------------------------------------------------------------------------------- /src/Models/PlayerAchievement.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 57 | $this->title = $this->getValue('title'); 58 | $this->description = $this->getValue('description'); 59 | $this->imageUrl = $this->getValue('image_url'); 60 | $this->achievedAt = new Carbon($this->getValue('achieved_at'), 'UTC'); 61 | } 62 | 63 | /** 64 | * Get the ID of the achievement. 65 | * 66 | * @return int 67 | */ 68 | public function getId(): int 69 | { 70 | return $this->id; 71 | } 72 | 73 | /** 74 | * Get the title of the achievement. 75 | * 76 | * @return string 77 | */ 78 | public function getTitle(): string 79 | { 80 | return $this->title; 81 | } 82 | 83 | /** 84 | * Get the description of the achievement. 85 | * 86 | * @return string 87 | */ 88 | public function getDescription(): string 89 | { 90 | return $this->description; 91 | } 92 | 93 | /** 94 | * Get the link to the achievement image. 95 | * 96 | * @return string 97 | */ 98 | public function getImageUrl(): string 99 | { 100 | return $this->imageUrl; 101 | } 102 | 103 | /** 104 | * Get the date and time the user was given the achievement (UTC). 105 | * 106 | * @return Carbon 107 | */ 108 | public function getAchievedAt(): Carbon 109 | { 110 | return $this->achievedAt; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/Models/PlayerAward.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 50 | $this->name = $this->getValue('name'); 51 | $this->imageUrl = $this->getValue('image_url'); 52 | $this->awardedAt = new Carbon($this->getValue('awarded_at'), 'UTC'); 53 | } 54 | 55 | /** 56 | * Get the ID of the award. 57 | * 58 | * @return int 59 | */ 60 | public function getId(): int 61 | { 62 | return $this->id; 63 | } 64 | 65 | /** 66 | * Get the name of the award. 67 | * 68 | * @return string 69 | */ 70 | public function getName(): string 71 | { 72 | return $this->name; 73 | } 74 | 75 | /** 76 | * Get the link to the award image. 77 | * 78 | * @return string 79 | */ 80 | public function getImageUrl(): string 81 | { 82 | return $this->imageUrl; 83 | } 84 | 85 | /** 86 | * Get the date and time the user was given the award (UTC). 87 | * 88 | * @return Carbon 89 | */ 90 | public function getAwardedAt(): Carbon 91 | { 92 | return $this->awardedAt; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Models/PlayerCompanyHistory.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 57 | $this->name = $this->getValue('name'); 58 | $this->verified = $this->getValue('verified', false); 59 | $this->joinDate = new Carbon($this->getValue('joinDate'), 'UTC'); 60 | $this->leftDate = new Carbon($this->getValue('leftDate'), 'UTC'); 61 | } 62 | 63 | /** 64 | * Get the company's ID. 65 | * 66 | * @return int 67 | */ 68 | public function getId(): int 69 | { 70 | return $this->id; 71 | } 72 | 73 | /** 74 | * Get the company's name. 75 | * 76 | * @return string 77 | */ 78 | public function getName(): string 79 | { 80 | return $this->name; 81 | } 82 | 83 | /** 84 | * Check if the company is verified. 85 | * 86 | * @return bool 87 | */ 88 | public function isVerified(): bool 89 | { 90 | return $this->verified; 91 | } 92 | 93 | /** 94 | * Get the date that the member joined the company. 95 | * 96 | * @return Carbon 97 | */ 98 | public function getJoinDate(): Carbon 99 | { 100 | return $this->joinDate; 101 | } 102 | 103 | /** 104 | * Get the date that the member left the company. 105 | * 106 | * @return Carbon 107 | */ 108 | public function getLeftDate(): Carbon 109 | { 110 | return $this->leftDate; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/Models/Rule.php: -------------------------------------------------------------------------------- 1 | rules = $this->getValue('rules'); 35 | $this->revision = $this->getValue('revision'); 36 | } 37 | 38 | /** 39 | * Get the current rules. 40 | * 41 | * @return string 42 | */ 43 | public function getRules(): string 44 | { 45 | return $this->rules; 46 | } 47 | 48 | /** 49 | * Get the current revision number of the rules. 50 | * 51 | * @return int 52 | */ 53 | public function getRevision(): int 54 | { 55 | return $this->revision; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Models/Server.php: -------------------------------------------------------------------------------- 1 | id = $this->getValue('id'); 175 | $this->game = $this->getValue('game'); 176 | $this->ip = $this->getValue('ip'); 177 | $this->port = $this->getValue('port'); 178 | $this->name = $this->getValue('name'); 179 | $this->shortName = $this->getValue('shortname'); 180 | $this->idPrefix = $this->getValue('idprefix'); 181 | $this->online = $this->getValue('online'); 182 | $this->players = $this->getValue('players'); 183 | $this->queue = $this->getValue('queue'); 184 | $this->maxPlayers = $this->getValue('maxplayers'); 185 | $this->mapId = $this->getValue('mapid'); 186 | $this->displayOrder = $this->getValue('displayorder'); 187 | $this->syncDelay = $this->getValue('syncdelay'); 188 | 189 | $this->speedLimiter = $this->getValue('speedlimiter', false); 190 | $this->collisions = $this->getValue('collisions', false); 191 | $this->carsForPlayers = $this->getValue('carsforplayers', false); 192 | $this->policeCarsForPlayers = $this->getValue('policecarsforplayers', false); 193 | $this->afkEnabled = $this->getValue('afkenabled', false); 194 | $this->event = $this->getValue('event', false); 195 | $this->specialEvent = $this->getValue('specialEvent', false); 196 | $this->promods = $this->getValue('promods', false); 197 | } 198 | 199 | /** 200 | * Get the ID of the server. 201 | * 202 | * @return int 203 | */ 204 | public function getId(): int 205 | { 206 | return $this->id; 207 | } 208 | 209 | /** 210 | * Get the game which the server is for. 211 | * 212 | * @return string 213 | */ 214 | public function getGame(): string 215 | { 216 | return $this->game; 217 | } 218 | 219 | /** 220 | * Get the server IP address. 221 | * 222 | * @return string 223 | */ 224 | public function getIp(): string 225 | { 226 | return $this->ip; 227 | } 228 | 229 | /** 230 | * Get the port which the server is running on. 231 | * 232 | * @return int 233 | */ 234 | public function getPort(): int 235 | { 236 | return $this->port; 237 | } 238 | 239 | /** 240 | * Get the name of the server. 241 | * 242 | * @return string 243 | */ 244 | public function getName(): string 245 | { 246 | return $this->name; 247 | } 248 | 249 | /** 250 | * Get the short name of the server. 251 | * 252 | * @return string 253 | */ 254 | public function getShortName(): string 255 | { 256 | return $this->shortName; 257 | } 258 | 259 | /** 260 | * Get the server prefix. 261 | * 262 | * @return string|null 263 | */ 264 | public function getIdPrefix(): ?string 265 | { 266 | return $this->idPrefix; 267 | } 268 | 269 | /** 270 | * Check if the server is online. 271 | * 272 | * @return bool 273 | */ 274 | public function isOnline(): bool 275 | { 276 | return $this->online; 277 | } 278 | 279 | /** 280 | * Get the number of players connected to the server. 281 | * 282 | * @return int 283 | */ 284 | public function getPlayers(): int 285 | { 286 | return $this->players; 287 | } 288 | 289 | /** 290 | * Get the number of players in the server queue. 291 | * 292 | * @return int 293 | */ 294 | public function getQueue(): int 295 | { 296 | return $this->queue; 297 | } 298 | 299 | /** 300 | * Get the maximum players allowed on the server. 301 | * 302 | * @return int 303 | */ 304 | public function getMaxPlayers(): int 305 | { 306 | return $this->maxPlayers; 307 | } 308 | 309 | /** 310 | * Get the map ID given to the server used by ETS2Map. 311 | * 312 | * @return int 313 | */ 314 | public function getMapId(): int 315 | { 316 | return $this->mapId; 317 | } 318 | 319 | /** 320 | * Get the order ID of the server. This determines which order to display the servers in. 321 | * The lowest number will show first. 322 | * 323 | * @return int 324 | */ 325 | public function getDisplayOrder(): int 326 | { 327 | return $this->displayOrder; 328 | } 329 | 330 | /** 331 | * Check if the server has a speed limit. 332 | * 333 | * @return bool 334 | */ 335 | public function hasSpeedLimit(): bool 336 | { 337 | return $this->speedLimiter; 338 | } 339 | 340 | /** 341 | * Check if the server has collisions enabled. 342 | * 343 | * @return bool 344 | */ 345 | public function hasCollisions(): bool 346 | { 347 | return $this->collisions; 348 | } 349 | 350 | /** 351 | * Check if the player can driver cars. 352 | * 353 | * @return bool 354 | */ 355 | public function canPlayersHaveCars(): bool 356 | { 357 | return $this->carsForPlayers; 358 | } 359 | 360 | /** 361 | * Check if the player can driver police cars. 362 | * 363 | * @return bool 364 | */ 365 | public function canPlayersHavePoliceCars(): bool 366 | { 367 | return $this->policeCarsForPlayers; 368 | } 369 | 370 | /** 371 | * Check if AFK kick is enabled on the server. 372 | * 373 | * @return bool 374 | */ 375 | public function isAfkEnabled(): bool 376 | { 377 | return $this->afkEnabled; 378 | } 379 | 380 | /** 381 | * Check if the server is an event server. 382 | * 383 | * @return bool 384 | */ 385 | public function isEvent(): bool 386 | { 387 | return $this->event; 388 | } 389 | 390 | /** 391 | * Check if the server is a special event server. 392 | * 393 | * @return bool 394 | */ 395 | public function isSpecialEvent(): bool 396 | { 397 | return $this->specialEvent; 398 | } 399 | 400 | /** 401 | * Check if the server has ProMods enabled. 402 | * 403 | * @return bool 404 | */ 405 | public function hasProMods(): bool 406 | { 407 | return $this->promods; 408 | } 409 | 410 | /** 411 | * Get the sync delay/tick rate. 412 | * 413 | * @return int 414 | */ 415 | public function getSyncDelay(): int 416 | { 417 | return $this->syncDelay; 418 | } 419 | } 420 | -------------------------------------------------------------------------------- /src/Models/Social.php: -------------------------------------------------------------------------------- 1 | twitter = $twitter; 60 | $this->facebook = $facebook; 61 | $this->twitch = $twitch; 62 | $this->discord = $discord; 63 | $this->youtube = $youtube; 64 | } 65 | 66 | /** 67 | * Get the Twitter URL. 68 | * 69 | * @return string|null 70 | */ 71 | public function getTwitter(): ?string 72 | { 73 | return $this->twitter; 74 | } 75 | 76 | /** 77 | * Get the Facebook URL. 78 | * 79 | * @return string|null 80 | */ 81 | public function getFacebook(): ?string 82 | { 83 | return $this->facebook; 84 | } 85 | 86 | /** 87 | * Get the Twitch URL. 88 | * 89 | * @return string|null 90 | */ 91 | public function getTwitch(): ?string 92 | { 93 | return $this->twitch; 94 | } 95 | 96 | /** 97 | * Get the Discord URL. 98 | * 99 | * @return string|null 100 | */ 101 | public function getDiscord(): ?string 102 | { 103 | return $this->discord; 104 | } 105 | 106 | /** 107 | * Get the YouTube URL. 108 | * 109 | * @return string|null 110 | */ 111 | public function getYouTube(): ?string 112 | { 113 | return $this->youtube; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/Models/Version.php: -------------------------------------------------------------------------------- 1 | name = $this->getValue('name'); 78 | $this->numeric = $this->getValue('numeric'); 79 | $this->stage = $this->getValue('stage'); 80 | 81 | $this->ets2mpChecksum = new Checksum( 82 | $this->getValue('ets2mp_checksum.dll'), 83 | $this->getValue('ets2mp_checksum.adb'), 84 | ); 85 | 86 | $this->atsmpChecksum = new Checksum( 87 | $this->getValue('atsmp_checksum.dll'), 88 | $this->getValue('atsmp_checksum.adb'), 89 | ); 90 | 91 | $this->time = new Carbon($this->getValue('time'), 'UTC'); 92 | $this->supportedETS2GameVersion = $this->getValue('supported_game_version'); 93 | $this->supportedATSGameVersion = $this->getValue('supported_ats_game_version'); 94 | } 95 | 96 | /** 97 | * Get the version name. 98 | * 99 | * @return string 100 | */ 101 | public function getName(): string 102 | { 103 | return $this->name; 104 | } 105 | 106 | /** 107 | * Get the numeric name of the version. 108 | * 109 | * @return string 110 | */ 111 | public function getNumeric(): string 112 | { 113 | return $this->numeric; 114 | } 115 | 116 | /** 117 | * Get the stage of which the version is at within the development lifecycle. 118 | * 119 | * @return string 120 | */ 121 | public function getStage(): string 122 | { 123 | return $this->stage; 124 | } 125 | 126 | /** 127 | * Get the ETS2MP checksum for the current version. 128 | * 129 | * @return Checksum 130 | */ 131 | public function getETS2MPChecksum(): Checksum 132 | { 133 | return $this->ets2mpChecksum; 134 | } 135 | 136 | /** 137 | * Get the ATSMP checksum for the current version. 138 | * 139 | * 140 | * @return Checksum 141 | */ 142 | public function getATSMPChecksum(): Checksum 143 | { 144 | return $this->atsmpChecksum; 145 | } 146 | 147 | /** 148 | * Get the date which the version was released. 149 | * 150 | * @return Carbon 151 | */ 152 | public function getTime(): Carbon 153 | { 154 | return $this->time; 155 | } 156 | 157 | /** 158 | * Get the supported Euro Truck Simulator 2 version. 159 | * 160 | * @return string 161 | */ 162 | public function getSupportedETS2GameVersion(): string 163 | { 164 | return $this->supportedETS2GameVersion; 165 | } 166 | 167 | /** 168 | * Get the supported American Truck Simulator version. 169 | * 170 | * @return string 171 | */ 172 | public function getSupportedATSGameVersion(): string 173 | { 174 | return $this->supportedATSGameVersion; 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /src/Requests/BanRequest.php: -------------------------------------------------------------------------------- 1 | id = $id; 32 | } 33 | 34 | /** 35 | * Get the endpoint of the request. 36 | * 37 | * @return string 38 | */ 39 | public function getEndpoint(): string 40 | { 41 | return 'bans/' . $this->id; 42 | } 43 | 44 | /** 45 | * Get the data for the request. 46 | * 47 | * @return Collection 48 | * 49 | * @throws ApiErrorException 50 | * @throws ClientExceptionInterface 51 | */ 52 | public function get(): Collection 53 | { 54 | return (new Collection($this->send()['response'])) 55 | ->map(fn (array $ban) => new Ban($this->client, $ban)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Requests/Company/BanIndexRequest.php: -------------------------------------------------------------------------------- 1 | companyKey = $companyKey; 33 | } 34 | 35 | /** 36 | * Get the endpoint of the request. 37 | * 38 | * @return string 39 | */ 40 | public function getEndpoint(): string 41 | { 42 | return 'vtc/' . $this->companyKey . '/members/banned'; 43 | } 44 | 45 | /** 46 | * Get the data for the request. 47 | * 48 | * @return Collection|CompanyMember[] 49 | * 50 | * @throws ApiErrorException 51 | * @throws ClientExceptionInterface 52 | */ 53 | public function get(): Collection 54 | { 55 | return (new Collection($this->send()['response']['members'])) 56 | ->map(fn (array $member) => new CompanyMember($this->client, $member)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Requests/Company/EventAttendingRequest.php: -------------------------------------------------------------------------------- 1 | companyId = $id; 33 | } 34 | 35 | /** 36 | * Get the endpoint of the request. 37 | * 38 | * @return string 39 | */ 40 | public function getEndpoint(): string 41 | { 42 | return 'vtc/' . $this->companyId . '/events/attending'; 43 | } 44 | 45 | /** 46 | * Get the data for the request. 47 | * 48 | * @return Collection|Event[] 49 | * 50 | * @throws ApiErrorException 51 | * @throws ClientExceptionInterface 52 | */ 53 | public function get(): Collection 54 | { 55 | return (new Collection($this->send()['response'])) 56 | ->map(fn (array $event) => new Event($this->client, $event)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Requests/Company/EventIndexRequest.php: -------------------------------------------------------------------------------- 1 | companyId = $id; 32 | } 33 | 34 | /** 35 | * Get the endpoint of the request. 36 | * 37 | * @return string 38 | */ 39 | public function getEndpoint(): string 40 | { 41 | return 'vtc/' . $this->companyId . '/events'; 42 | } 43 | 44 | /** 45 | * Get the data for the request. 46 | * 47 | * @return CompanyEventIndex 48 | * 49 | * @throws ApiErrorException 50 | * @throws ClientExceptionInterface 51 | */ 52 | public function get(): CompanyEventIndex 53 | { 54 | return new CompanyEventIndex( 55 | $this->client, 56 | $this->send()['response'] 57 | ); 58 | } 59 | 60 | /** 61 | * Get all events that the company is attending. 62 | * 63 | * @return EventAttendingRequest 64 | */ 65 | public function attending(): EventAttendingRequest 66 | { 67 | return new EventAttendingRequest( 68 | $this->client, 69 | $this->companyId, 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Requests/Company/EventRequest.php: -------------------------------------------------------------------------------- 1 | companyId = $companyId; 40 | $this->eventId = $eventId; 41 | } 42 | 43 | /** 44 | * Get the endpoint of the request. 45 | * 46 | * @return string 47 | */ 48 | public function getEndpoint(): string 49 | { 50 | return 'vtc/' . $this->companyId . '/events/' . $this->eventId; 51 | } 52 | 53 | /** 54 | * Get the data for the request. 55 | * 56 | * @return Event 57 | * 58 | * @throws ApiErrorException 59 | * @throws ClientExceptionInterface 60 | */ 61 | public function get(): Event 62 | { 63 | return new Event( 64 | $this->client, 65 | $this->send()['response'] 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Requests/Company/MemberIndexRequest.php: -------------------------------------------------------------------------------- 1 | companyKey = $companyKey; 32 | } 33 | 34 | /** 35 | * Get the endpoint of the request. 36 | * 37 | * @return string 38 | */ 39 | public function getEndpoint(): string 40 | { 41 | return 'vtc/' . $this->companyKey . '/members'; 42 | } 43 | 44 | /** 45 | * Get the data for the request. 46 | * 47 | * @return CompanyMemberIndex 48 | * 49 | * @throws ApiErrorException 50 | * @throws ClientExceptionInterface 51 | */ 52 | public function get(): CompanyMemberIndex 53 | { 54 | return new CompanyMemberIndex( 55 | $this->client, 56 | $this->send()['response'] 57 | ); 58 | } 59 | 60 | /** 61 | * Get the members within the company that are currently banned. 62 | * 63 | * @return BanIndexRequest 64 | */ 65 | public function bans(): BanIndexRequest 66 | { 67 | return new BanIndexRequest( 68 | $this->client, 69 | $this->companyKey 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Requests/Company/MemberRequest.php: -------------------------------------------------------------------------------- 1 | companyKey = $companyKey; 40 | $this->memberId = $memberId; 41 | } 42 | 43 | /** 44 | * Get the endpoint of the request. 45 | * 46 | * @return string 47 | */ 48 | public function getEndpoint(): string 49 | { 50 | return 'vtc/' . $this->companyKey . '/member/' . $this->memberId; 51 | } 52 | 53 | /** 54 | * Get the data for the request. 55 | * 56 | * @return mixed 57 | * 58 | * @throws ApiErrorException 59 | * @throws ClientExceptionInterface 60 | */ 61 | public function get(): CompanyMember 62 | { 63 | return new CompanyMember( 64 | $this->client, 65 | $this->send()['response'] 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Requests/Company/PostIndexRequest.php: -------------------------------------------------------------------------------- 1 | companyKey = $companyKey; 33 | } 34 | 35 | /** 36 | * Get the endpoint of the request. 37 | * 38 | * @return string 39 | */ 40 | public function getEndpoint(): string 41 | { 42 | return 'vtc/' . $this->companyKey . '/news'; 43 | } 44 | 45 | /** 46 | * Get the data for the request. 47 | * 48 | * @return Collection|CompanyPost[] 49 | * 50 | * @throws ApiErrorException 51 | * @throws ClientExceptionInterface 52 | */ 53 | public function get(): Collection 54 | { 55 | return (new Collection($this->send()['response']['news'])) 56 | ->map(fn (array $post) => new CompanyPost($this->client, $post)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Requests/Company/PostRequest.php: -------------------------------------------------------------------------------- 1 | companyKey = $companyKey; 40 | $this->postId = $postId; 41 | } 42 | 43 | /** 44 | * Get the endpoint of the request. 45 | * 46 | * @return string 47 | */ 48 | public function getEndpoint(): string 49 | { 50 | return 'vtc/' . $this->companyKey . '/news/' . $this->postId; 51 | } 52 | 53 | /** 54 | * Get the data for the request. 55 | * 56 | * @return CompanyPost 57 | * 58 | * @throws ApiErrorException 59 | * @throws ClientExceptionInterface 60 | */ 61 | public function get(): CompanyPost 62 | { 63 | return new CompanyPost( 64 | $this->client, 65 | $this->send()['response'] 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Requests/Company/RoleIndexRequest.php: -------------------------------------------------------------------------------- 1 | companyKey = $companyKey; 34 | } 35 | 36 | /** 37 | * Get the endpoint of the request. 38 | * 39 | * @return string 40 | */ 41 | public function getEndpoint(): string 42 | { 43 | return 'vtc/' . $this->companyKey . '/roles'; 44 | } 45 | 46 | /** 47 | * Get the data for the request. 48 | * 49 | * @return Collection 50 | * 51 | * @throws Exception 52 | * @throws ApiErrorException 53 | * @throws ClientExceptionInterface 54 | */ 55 | public function get(): Collection 56 | { 57 | return (new Collection($this->send()['response']['roles'])) 58 | ->map(fn (array $role) => new CompanyRole($this->client, $role)); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Requests/Company/RoleRequest.php: -------------------------------------------------------------------------------- 1 | companyKey = $companyKey; 40 | $this->roleId = $roleId; 41 | } 42 | 43 | /** 44 | * Get the endpoint of the request. 45 | * 46 | * @return string 47 | */ 48 | public function getEndpoint(): string 49 | { 50 | return 'vtc/' . $this->companyKey . '/role/' . $this->roleId; 51 | } 52 | 53 | /** 54 | * Get the data for the request. 55 | * 56 | * @return CompanyRole 57 | * 58 | * @throws ApiErrorException 59 | * @throws ClientExceptionInterface 60 | */ 61 | public function get(): CompanyRole 62 | { 63 | return new CompanyRole( 64 | $this->client, 65 | $this->send()['response'] 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Requests/CompanyIndexRequest.php: -------------------------------------------------------------------------------- 1 | client, 33 | $this->send()['response'] 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Requests/CompanyRequest.php: -------------------------------------------------------------------------------- 1 | key = $key; 39 | } 40 | 41 | /** 42 | * Get the endpoint of the request. 43 | * 44 | * @return string 45 | */ 46 | public function getEndpoint(): string 47 | { 48 | return 'vtc/' . $this->key; 49 | } 50 | 51 | /** 52 | * Get the data for the request. 53 | * 54 | * @return Company 55 | * 56 | * @throws ApiErrorException 57 | * @throws ClientExceptionInterface 58 | */ 59 | public function get(): Company 60 | { 61 | return new Company( 62 | $this->client, 63 | $this->send()['response'] 64 | ); 65 | } 66 | 67 | /** 68 | * Get the news posts for the company. 69 | * 70 | * @return PostIndexRequest 71 | */ 72 | public function posts(): PostIndexRequest 73 | { 74 | return new PostIndexRequest( 75 | $this->client, 76 | $this->key 77 | ); 78 | } 79 | 80 | /** 81 | * Get the post for the company with the specified ID. 82 | * 83 | * @param int $id 84 | * @return PostRequest 85 | */ 86 | public function post(int $id): PostRequest 87 | { 88 | return new PostRequest( 89 | $this->client, 90 | $this->key, 91 | $id 92 | ); 93 | } 94 | 95 | /** 96 | * Get the roles for the company. 97 | * 98 | * @return RoleIndexRequest 99 | */ 100 | public function roles(): RoleIndexRequest 101 | { 102 | return new RoleIndexRequest( 103 | $this->client, 104 | $this->key 105 | ); 106 | } 107 | 108 | /** 109 | * Get the requested company role. 110 | * 111 | * @param int $id 112 | * @return RoleRequest 113 | */ 114 | public function role(int $id): RoleRequest 115 | { 116 | return new RoleRequest( 117 | $this->client, 118 | $this->key, 119 | $id 120 | ); 121 | } 122 | 123 | /** 124 | * Get the members for the company. 125 | * 126 | * @return MemberIndexRequest 127 | */ 128 | public function members(): MemberIndexRequest 129 | { 130 | return new MemberIndexRequest( 131 | $this->client, 132 | $this->key 133 | ); 134 | } 135 | 136 | /** 137 | * Get the requested company member. 138 | * 139 | * @param int $id 140 | * @return MemberRequest 141 | */ 142 | public function member(int $id): MemberRequest 143 | { 144 | return new MemberRequest( 145 | $this->client, 146 | $this->key, 147 | $id 148 | ); 149 | } 150 | 151 | /** 152 | * Get the events created by the company. 153 | * 154 | * @return EventIndexRequest 155 | */ 156 | public function events(): EventIndexRequest 157 | { 158 | return new EventIndexRequest( 159 | $this->client, 160 | $this->key 161 | ); 162 | } 163 | 164 | /** 165 | * Get the event created by the company with the specified ID. 166 | * 167 | * @param int $id 168 | * @return EventRequest 169 | */ 170 | public function event(int $id): EventRequest 171 | { 172 | return new EventRequest( 173 | $this->client, 174 | $this->key, 175 | $id 176 | ); 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /src/Requests/EventIndexRequest.php: -------------------------------------------------------------------------------- 1 | client, 33 | $this->send()['response'] 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Requests/EventRequest.php: -------------------------------------------------------------------------------- 1 | id = $id; 31 | } 32 | 33 | /** 34 | * Get the endpoint of the request. 35 | * 36 | * @return string 37 | */ 38 | public function getEndpoint(): string 39 | { 40 | return 'events/' . $this->id; 41 | } 42 | 43 | /** 44 | * Get the data for the request. 45 | * 46 | * @return Event 47 | * 48 | * @throws ApiErrorException 49 | * @throws ClientExceptionInterface 50 | */ 51 | public function get(): Event 52 | { 53 | return new Event( 54 | $this->client, 55 | $this->send()['response'] 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Requests/EventUserRequest.php: -------------------------------------------------------------------------------- 1 | userId = $userId; 32 | } 33 | 34 | /** 35 | * Get the endpoint of the request. 36 | * 37 | * @return string 38 | */ 39 | public function getEndpoint(): string 40 | { 41 | return 'events/user/' . $this->userId; 42 | } 43 | 44 | /** 45 | * Get the data for the request. 46 | * 47 | * @return Collection 48 | * 49 | * @throws ClientExceptionInterface 50 | * @throws ApiErrorException 51 | */ 52 | public function get(): Collection 53 | { 54 | return (new Collection($this->send()['response'])) 55 | ->map(fn (array $event) => new Event($this->client, $event)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Requests/GameTimeRequest.php: -------------------------------------------------------------------------------- 1 | client, 33 | $this->send() 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Requests/PlayerRequest.php: -------------------------------------------------------------------------------- 1 | id = $id; 31 | } 32 | 33 | /** 34 | * Get the endpoint of the request. 35 | * 36 | * @return string 37 | */ 38 | public function getEndpoint(): string 39 | { 40 | return 'player/' . $this->id; 41 | } 42 | 43 | /** 44 | * Get the data for the request. 45 | * 46 | * @return Player 47 | * 48 | * @throws ApiErrorException 49 | * @throws ClientExceptionInterface 50 | */ 51 | public function get(): Player 52 | { 53 | return new Player( 54 | $this->client, 55 | $this->send()['response'] 56 | ); 57 | } 58 | 59 | /** 60 | * Get the players bans. 61 | * 62 | * @return BanRequest 63 | */ 64 | public function bans(): BanRequest 65 | { 66 | return new BanRequest( 67 | $this->client, 68 | $this->id 69 | ); 70 | } 71 | 72 | /** 73 | * Get all events created by the player. 74 | * 75 | * @return EventUserRequest 76 | */ 77 | public function events(): EventUserRequest 78 | { 79 | return new EventUserRequest( 80 | $this->client, 81 | $this->id, 82 | ); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Requests/Request.php: -------------------------------------------------------------------------------- 1 | client = $client; 27 | } 28 | 29 | /** 30 | * Get the endpoint of the request. 31 | * 32 | * @return string 33 | */ 34 | abstract public function getEndpoint(): string; 35 | 36 | /** 37 | * Get the data for the request. 38 | * 39 | * @return mixed 40 | */ 41 | abstract public function get(); 42 | 43 | /** 44 | * Send the request to the API endpoint and get the result. 45 | * 46 | * @return array 47 | * 48 | * @throws ClientExceptionInterface 49 | * @throws ApiErrorException 50 | */ 51 | public function send(): array 52 | { 53 | $request = new GuzzleRequest('GET', $this->getEndpoint()); 54 | $requestResponse = $this->client->getHttpClient()->send($request); 55 | 56 | $response = json_decode($requestResponse->getBody(), true, 512, JSON_BIGINT_AS_STRING); 57 | 58 | if ($this->hasError($response)) { 59 | $message = $response['descriptor'] ?? $response['response']; 60 | 61 | throw new ApiErrorException($message, $requestResponse->getStatusCode()); 62 | } 63 | 64 | return $response; 65 | } 66 | 67 | /** 68 | * Check if the response contains an error. 69 | * 70 | * @param mixed $response 71 | * @return bool 72 | */ 73 | protected function hasError($response): bool 74 | { 75 | if (!isset($response['error'])) { 76 | return false; 77 | } 78 | 79 | if (is_string($response['error'])) { 80 | return $response['error'] === 'true'; 81 | } 82 | 83 | return $response['error']; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Requests/RuleRequest.php: -------------------------------------------------------------------------------- 1 | client, 33 | $this->send() 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Requests/ServerRequest.php: -------------------------------------------------------------------------------- 1 | send()['response'])) 33 | ->map(fn (array $server) => new Server($this->client, $server)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Requests/VersionRequest.php: -------------------------------------------------------------------------------- 1 | client, 33 | $this->send() 34 | ); 35 | } 36 | } 37 | --------------------------------------------------------------------------------