-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGigyaRequestor.php
66 lines (57 loc) · 1.75 KB
/
GigyaRequestor.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Exercise\GigyaBundle;
use Symfony\Bridge\Monolog\Logger;
class GigyaRequestor
{
/**
* @var string
*/
protected $apiKey;
/**
* @var string
*/
protected $secretKey;
/**
* @var \Symfony\Bridge\Monolog\Logger
*/
protected $logger;
/**
* @param string $apiKey
* @param string $secretKey
*/
public function __construct($apiKey, $secretKey, Logger $logger)
{
$this->apiKey = $apiKey;
$this->secretKey = $secretKey;
$this->logger = $logger;
}
/**
* @param string $method
* @param array $parameters
* @param boolean $https
* @return GSResponse
* @throws \GSException If request failed
*/
public function sendRequest($method, array $parameters = array(), $https = false)
{
$gsOject = new \GSObject();
foreach ($parameters as $key => $value) {
$gsOject->put($key, $value);
}
$request = new \GSRequest($this->apiKey, $this->secretKey, $method, $gsOject, $https);
$request->setCurlOptionsArray(array(
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0
));
$params = json_encode($request->getParams()->serialize());
$requestLogEntry = sprintf("method: %s; params: %s", $method, $params);
$response = $request->send();
$responseLogEntry = sprintf("response: %s", $response->getResponseText());
$this->logger->debug($requestLogEntry);
$this->logger->debug($responseLogEntry);
if ($response->getErrorCode() == 0) {
return $response->getData();
}
throw new \GSException(sprintf("%s: %s", $response->getErrorCode(), $response->getErrorMessage()));
}
}