Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow searching with company slug #37

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ public function companies(): CompanyIndexRequest
}

/**
* Get the information for the company with the specified ID.
* Get the information for the company with the specified ID or slug.
*
* https://stats.truckersmp.com/api#vtc_info
*
* @param int $id
* @param string|int $key
* @return CompanyRequest
*/
public function company(int $id): CompanyRequest
public function company(string $key): CompanyRequest
{
return new CompanyRequest($id);
return new CompanyRequest($key);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Requests/Company/MemberIndexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
class MemberIndexRequest extends Request
{
/**
* The ID of the requested company.
* The ID or slug of the requested company.
*
* @var int
* @var string|int
*/
protected $companyId;
protected $companyKey;

/**
* Create a new MemberIndexRequest instance.
*
* @param int $id
* @param string|int $companyKey
* @return void
*/
public function __construct(int $id)
public function __construct(string $companyKey)
{
parent::__construct();

$this->companyId = $id;
$this->companyKey = $companyKey;
}

/**
Expand All @@ -36,7 +36,7 @@ public function __construct(int $id)
*/
public function getEndpoint(): string
{
return 'vtc/' . $this->companyId . '/members';
return 'vtc/' . $this->companyKey . '/members';
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Requests/Company/MemberRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
class MemberRequest extends Request
{
/**
* The ID of the requested company.
* The ID or slug of the requested company.
*
* @var int
* @var string|int
*/
protected $companyId;
protected $companyKey;

/**
* The ID of the requested member.
Expand All @@ -26,15 +26,15 @@ class MemberRequest extends Request
/**
* Create a new MemberRequest instance.
*
* @param int $companyId
* @param string|int $companyKey
* @param int $memberId
* @return void
*/
public function __construct(int $companyId, int $memberId)
public function __construct(string $companyKey, int $memberId)
{
parent::__construct();

$this->companyId = $companyId;
$this->companyKey = $companyKey;
$this->memberId = $memberId;
}

Expand All @@ -45,7 +45,7 @@ public function __construct(int $companyId, int $memberId)
*/
public function getEndpoint(): string
{
return 'vtc/' . $this->companyId . '/member/' . $this->memberId;
return 'vtc/' . $this->companyKey . '/member/' . $this->memberId;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Requests/Company/PostIndexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
class PostIndexRequest extends Request
{
/**
* The ID of the requested company.
* The ID or slug of the requested company.
*
* @var int
* @var string|int
*/
protected $companyId;
protected $companyKey;

/**
* Create a new PostIndexRequest instance.
*
* @param int $companyId
* @param string|int $companyKey
* @return void
*/
public function __construct(int $companyId)
public function __construct(string $companyKey)
{
parent::__construct();

$this->companyId = $companyId;
$this->companyKey = $companyKey;
}

/**
Expand All @@ -37,7 +37,7 @@ public function __construct(int $companyId)
*/
public function getEndpoint(): string
{
return 'vtc/' . $this->companyId . '/news';
return 'vtc/' . $this->companyKey . '/news';
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Requests/Company/PostRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
class PostRequest extends Request
{
/**
* The ID of the requested company.
* The ID or slug of the requested company.
*
* @var int
* @var string|int
*/
protected $companyId;
protected $companyKey;

/**
* The ID of the requested post.
Expand All @@ -26,15 +26,15 @@ class PostRequest extends Request
/**
* Create a new PostRequest instance.
*
* @param int $companyId
* @param string|int $companyKey
* @param int $postId
* @return void
*/
public function __construct(int $companyId, int $postId)
public function __construct(string $companyKey, int $postId)
{
parent::__construct();

$this->companyId = $companyId;
$this->companyKey = $companyKey;
$this->postId = $postId;
}

Expand All @@ -45,7 +45,7 @@ public function __construct(int $companyId, int $postId)
*/
public function getEndpoint(): string
{
return 'vtc/' . $this->companyId . '/news/' . $this->postId;
return 'vtc/' . $this->companyKey . '/news/' . $this->postId;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Requests/Company/RoleIndexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
class RoleIndexRequest extends Request
{
/**
* The ID of the requested company.
* The ID or slug of the requested company.
*
* @var int
* @var string|int
*/
protected $companyId;
protected $companyKey;

/**
* Create a new RoleIndexRequest instance.
*
* @param int $companyId
* @param string|int $companyKey
* @return void
*/
public function __construct(int $companyId)
public function __construct(string $companyKey)
{
parent::__construct();

$this->companyId = $companyId;
$this->companyKey = $companyKey;
}

/**
Expand All @@ -37,7 +37,7 @@ public function __construct(int $companyId)
*/
public function getEndpoint(): string
{
return 'vtc/' . $this->companyId . '/roles';
return 'vtc/' . $this->companyKey . '/roles';
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Requests/Company/RoleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
class RoleRequest extends Request
{
/**
* The ID of the requested company.
* The ID or slug of the requested company.
*
* @var int
* @var string|int
*/
protected $companyId;
protected $companyKey;

/**
* The ID of the requested role.
Expand All @@ -27,15 +27,15 @@ class RoleRequest extends Request
/**
* Create a new RoleRequest instance.
*
* @param int $companyId
* @param int $companyKey
* @param int $roleId
* @return void
*/
public function __construct(int $companyId, int $roleId)
public function __construct(int $companyKey, int $roleId)
{
parent::__construct();

$this->companyId = $companyId;
$this->companyKey = $companyKey;
$this->roleId = $roleId;
}

Expand All @@ -46,7 +46,7 @@ public function __construct(int $companyId, int $roleId)
*/
public function getEndpoint(): string
{
return 'vtc/' . $this->companyId . '/role/' . $this->roleId;
return 'vtc/' . $this->companyKey . '/role/' . $this->roleId;
}

/**
Expand Down
26 changes: 13 additions & 13 deletions src/Requests/CompanyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
class CompanyRequest extends Request
{
/**
* The ID of the requested company.
* The ID or slug of the requested company.
*
* @var int
* @var string|int
*/
protected $id;
protected $key;

/**
* Create a new CompanyRequest instance.
*
* @param int $id
* @param string|int $key
* @return void
*/
public function __construct(int $id)
public function __construct(string $key)
{
parent::__construct();

$this->id = $id;
$this->key = $key;
}

/**
Expand All @@ -41,7 +41,7 @@ public function __construct(int $id)
*/
public function getEndpoint(): string
{
return 'vtc/' . $this->id;
return 'vtc/' . $this->key;
}

/**
Expand All @@ -67,7 +67,7 @@ public function get(): Company
public function posts(): PostIndexRequest
{
return new PostIndexRequest(
$this->id
$this->key
);
}

Expand All @@ -80,7 +80,7 @@ public function posts(): PostIndexRequest
public function post(int $id): PostRequest
{
return new PostRequest(
$this->id,
$this->key,
$id
);
}
Expand All @@ -93,7 +93,7 @@ public function post(int $id): PostRequest
public function roles(): RoleIndexRequest
{
return new RoleIndexRequest(
$this->id
$this->key
);
}

Expand All @@ -106,7 +106,7 @@ public function roles(): RoleIndexRequest
public function role(int $id): RoleRequest
{
return new RoleRequest(
$this->id,
$this->key,
$id
);
}
Expand All @@ -119,7 +119,7 @@ public function role(int $id): RoleRequest
public function members(): MemberIndexRequest
{
return new MemberIndexRequest(
$this->id
$this->key
);
}

Expand All @@ -132,7 +132,7 @@ public function members(): MemberIndexRequest
public function member(int $id): MemberRequest
{
return new MemberRequest(
$this->id,
$this->key,
$id
);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ public function companies(): CompanyIndex
}

/**
* Get or cache the company with the specified id.
* Get or cache the company with the specified id or slug.
*
* @param int $id
* @param string|int $key
*
* @return Company
*
Expand All @@ -233,12 +233,12 @@ public function companies(): CompanyIndex
* @throws ClientExceptionInterface
* @throws InvalidArgumentException
*/
public function company(int $id): Company
public function company(string $key): Company
{
$cachedCompany = self::$cache->getItem('company_' . $id);
$cachedCompany = self::$cache->getItem('company_' . $key);

if (!$cachedCompany->isHit()) {
$cachedCompany->set($this->client->company($id)->get())->expiresAfter(self::CACHE_SECONDS);
$cachedCompany->set($this->client->company($key)->get())->expiresAfter(self::CACHE_SECONDS);
self::$cache->save($cachedCompany);
}

Expand Down
Loading