-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add langueges support - add get city by id - add get region by id
- Loading branch information
1 parent
24e57b6
commit 5a67350
Showing
11 changed files
with
213 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Parhomenko\Olx\Api; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
class Districts | ||
{ | ||
const API_VERSION = '2.0'; | ||
const OLX_DISTRICTS_URL = '/api/partner/districts'; | ||
|
||
private $user; | ||
private $guzzleClient; | ||
|
||
public function __construct( User $user, Client $guzzleClient ) | ||
{ | ||
$this->user = $user; | ||
$this->guzzleClient = $guzzleClient; | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws \Exception | ||
*/ | ||
public function getAll() : array | ||
{ | ||
try { | ||
$response = $this->guzzleClient->request('GET', self::OLX_DISTRICTS_URL, [ | ||
'headers' => [ | ||
'Authorization' => $this->user->getTokenType() .' ' .$this->user->getAccessToken(), | ||
'Version' => self::API_VERSION | ||
] | ||
]); | ||
|
||
$data = json_decode( $response->getBody()->getContents(), true ); | ||
|
||
if( !isset( $data['data'] ) ) throw new \Exception( 'Got empty response | Get all OLX districts' ); | ||
|
||
return $data['data']; | ||
|
||
} catch ( \Exception $e ){ | ||
throw $e; | ||
} | ||
} | ||
|
||
/** | ||
* @param int $district_id | ||
* @return array | ||
* @throws \Exception | ||
*/ | ||
public function get(int $district_id) : array | ||
{ | ||
try { | ||
$response = $this->guzzleClient->request('GET', self::OLX_DISTRICTS_URL .'/' .$district_id, [ | ||
'headers' => [ | ||
'Authorization' => $this->user->getTokenType() .' ' .$this->user->getAccessToken(), | ||
'Version' => self::API_VERSION | ||
] | ||
]); | ||
|
||
$data = json_decode( $response->getBody()->getContents(), true ); | ||
|
||
if( !isset( $data['data'] ) ) throw new \Exception( 'Got empty response | Get all OLX district' ); | ||
|
||
return $data['data']; | ||
|
||
} catch ( \Exception $e ){ | ||
throw $e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters