Skip to content

B3none/API-Client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TruckersMP REST API Library

Build Status Latest Stable Version Latest Unstable Version License Monthly Downloads Total Downloads

This is a PHP library created to simplify development using the TruckersMP API. This library provides functions to connect and gather data from each API endpoint, and returns the data as a class with getting functions.

If you want to use the API without a library (or if you have advanced knowledge of PHP), check out our API documentation.

Warning!

Please use our service responsibly. People who make lots of requests to our API should contact TruckersMP Staff with a rationale and contact email.

Requirements

  • PHP 7.1.0 or newer
  • Composer

Installation

This library can be installed using Composer.

Two ways:

  1. Execute command composer require truckersmp/api-client
  2. Add truckersmp/api-client manually to the composer requirements list.

After doing either of the above, execute the command composer install.

Usage

Please note: this example doesn't use caching. You should cache your requests in order to use API responsibly. Some examples can be found in examples\cache folder.

<?php

use TruckersMP\Client;

$client = new Client();

// Get player data for player id 50
$player = $client->player(50);

// Get player data for player with SteamID 76561197965863564
$player = $client->player(76561197965863564);

// output the user's name
echo $player->getName();

// output the user's group
echo $player->getGroupName();

Methods

All timestamps in this project return a Carbon class.

  • player(int $id): PlayerModel - Get player info by either TruckersMP ID or Steam ID
  • bans(int $id): BansModel - Get bans for a player by player ID
  • servers(): ServersModel - Get a list of servers
  • gameTime(): GameTimeModel - Get the server time
  • version(): VersionModel- DEPRECATED Get the TruckersMP version info
  • rules(): RulesModel - Get the TruckersMP rules

Models

BanModel Methods

  • getExpires(): ?Carbon
  • getCreated(): Carbon
  • isActive(): bool
  • getReason(): string
  • getAdminName(): string
  • getAdminID(): int

BansModel

Contains an array of BanModels.

GameTimeModel Methods

  • getTime(): Carbon

PlayerModel Methods

  • getId(): int
  • getName(): string
  • getAvatar(): string
  • getJoinDate(): Carbon
  • getSteamID64(): string
  • getGroupID(): int
  • getGroupName(): string
  • isAdmin(): bool

RulesModel Methods

  • getRules(): string
  • getRevision(): int

ServerModel Methods

  • getId(): int
  • getGame(): string
  • getIp(): string
  • getPort(): int
  • getName(): string
  • getShortName(): string
  • isOnline(): bool
  • getPlayers(): int
  • getQueue(): int
  • getMaxPlayers(): int
  • hasSpeedLimit(): bool
  • hasCollisions(): bool
  • canPlayersHaveCars(): bool
  • canPlayersHavePoliceCars(): bool
  • isAfkEnabled(): bool
  • hasSyncDelay(): bool

ServersModel

Contains an array of ServerModels.

VersionModel

  • getVersion(): stdClass
  • getChecksum(): stdClass
  • getReleased(): Carbon
  • getSupport(): stdClass

Configuration

We use Guzzle to get data from an API endpoint. If you want to change the Guzzle configuration then you can pass config array during Client intialization.

You can also pass a second parameter to specify HTTP (false) or HTTPS (true) requests. This is true by default.

<?php 

$shouldUseHTTPS = true;

$client = new APIClient([
    // Guzzle config
], $shouldUseHTTPS);

All other settings you can find in APIClient.php constructor.

Need Help?

If you have any questions about library usage, you can create a new issue or make a topic on our forum.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%