-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPipl.php
46 lines (36 loc) · 1000 Bytes
/
Pipl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Abdelrahman_badr\Pipl;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
/**
* Class Pipl
* @package Abdelrahman_badr\Pipl
*/
class Pipl
{
protected $client;
public function __construct(ClientInterface $client = null)
{
$this->client = $client ?? (new Client());
}
public function search(array $fields)
{
if (empty($fields)) {
throw new Exception("Search function parameter can't be empty");
}
$url = $this->buildUrl($fields);
$response = $this->client->get($url);
return json_decode($response->getBody(), true);
}
protected function buildUrl(array $fields)
{
$key = env('PIPL_API_KEY');
$baseUrl = rtrim(env('PIPL_API_BASE_URL', 'http://api.pipl.com/search/'), '/');
$url = $baseUrl . "/?key={$key}";
foreach ($fields as $key => $value) {
$url .= "&$key=$value";
}
return $url;
}
}