-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e07266
commit 3a1d679
Showing
7 changed files
with
94 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
namespace GOAPI\IO; | ||
|
||
class Places | ||
{ | ||
private $client; | ||
private $apiBaseUrl = '/places'; | ||
|
||
public function __construct(\GuzzleHttp\Client $client) { | ||
$this->client = $client; | ||
} | ||
|
||
private function makeRequest($endpoint, $params = []) { | ||
try { | ||
$response = $this->client->request('GET', $this->apiBaseUrl . $endpoint, [ | ||
'query' => $params, | ||
]); | ||
|
||
// Assuming the API returns JSON response | ||
return json_decode($response->getBody(), true); | ||
} catch (\Exception $e) { | ||
// Handle exceptions and errors here | ||
// You might want to log the error or throw a custom exception | ||
return ["error" => $e->getMessage()]; | ||
} | ||
} | ||
|
||
public function search($keyword) { | ||
$response = $this->makeRequest('', ['search' => $keyword]); | ||
|
||
return (new Collection($response['data']['results']))->map(function($item) { | ||
return new \GOAPI\IO\Resources\Places\Place( | ||
id: $item['id'], | ||
displayName: $item['displayName'], | ||
lng: $item['lng'], | ||
lat: $item['lat'], | ||
coordinate: $item['coordinate'], | ||
); | ||
}); | ||
} | ||
|
||
} |
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,13 @@ | ||
<?php | ||
namespace GOAPI\IO\Resources\Places; | ||
|
||
class Place { | ||
|
||
function __construct( | ||
public $id, | ||
public $displayName, | ||
public $lng, | ||
public $lat, | ||
public $coordinate, | ||
) {} | ||
} |
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,8 @@ | ||
<?php | ||
require './vendor/autoload.php'; | ||
|
||
$collection = new \GOAPI\IO\Collection([ | ||
'dam','da','df', | ||
]); | ||
|
||
echo $collection[0]; |
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,21 @@ | ||
<?php | ||
|
||
$client = new \GOAPI\IO\Client([ | ||
'api_key' => getenv('GOAPI_IO_API_KEY'), // your api key | ||
]); | ||
|
||
test('get client instance', function () use($client) { | ||
$instance = $client->createPlaces(); | ||
|
||
expect($instance instanceof \GOAPI\IO\Places)->toBeTrue(); | ||
}); | ||
|
||
test('get search', function () use($client) { | ||
$instance = $client->createPlaces(); | ||
|
||
$response = $instance->search("Jakarta"); | ||
|
||
|
||
expect($response->values())->toBeArray(); | ||
expect($response[0] instanceof \GOAPI\IO\Resources\Places\Place)->toBeTrue(); | ||
}); |