Esempio n. 1
0
 /**
  * @author Ronan Chilvers <*****@*****.**>
  */
 public function getBody()
 {
     try {
         return (array) $this->guzzleResponse->getBody();
     } catch (ParseException $ex) {
         return false;
     }
 }
Esempio n. 2
0
 /**
  * Parse Provider's Response
  * @param GuzzleHttp\Message\Response $response
  * @return array $result
  */
 public function parse($response)
 {
     $body = (string) $response->getBody();
     $json = json_decode(substr($body, 19, strlen($body) - 19 - 2));
     $buy = number_format(preg_replace('/,/', '.', $json->InformalVentaValue), 2);
     $sell = number_format(preg_replace('/,/', '.', $json->InformalCompraValue), 2);
     return array('buy' => $buy, 'sell' => $sell, 'timestamp' => time());
 }
Esempio n. 3
0
 public function testRequest()
 {
     $response = new GuzzleHttp\Message\Response(200, ['X-Foo' => 'Bar']);
     $response->setBody(GuzzleHttp\Stream\Stream::factory('foo'));
     $mock = new GuzzleHttp\Subscriber\Mock([$response]);
     $client = new LeagueWrap\Client();
     $client->baseUrl('http://google.com');
     $client->setTimeout(10);
     $client->addMock($mock);
     $response = $client->request('', []);
     $this->assertEquals('foo', $response);
 }
Esempio n. 4
0
 /**
  * Parse Provider's Response
  * @param GuzzleHttp\Message\Response $response
  * @return array $result
  */
 public function parse($response)
 {
     $body = (string) $response->getBody();
     $json = json_decode($body);
     $sources = array_filter($json, function ($source) {
         return $source->source != 'oficial';
     });
     $sourcesBuy = array_map(function ($source) {
         return $source->value_buy;
     }, $sources);
     $buy = number_format(array_sum($sourcesBuy) / count($sourcesBuy), 2);
     $sourcesSell = array_map(function ($source) {
         return $source->value_sell;
     }, $sources);
     $sell = number_format(array_sum($sourcesSell) / count($sourcesSell), 2);
     return array('buy' => $buy, 'sell' => $sell, 'timestamp' => time());
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function isSuccessful()
 {
     return $this->response->getStatusCode() == 204;
 }
Esempio n. 6
0
 /**
  * Handle the response from the server. Raw responses are returned without
  * checking anything. JSON responses are decoded and then checked for
  * any errors.
  *
  * @param GuzzleHttp\Message\Response $response The Guzzle response object.
  * @param bool $isRawResponse Do we want to return the raw response, or
  *                            process as JSON?
  * @param GuzzleHttp\Message\Request The Guzzle request object.
  *
  * @return array|string An array decoded from JSON, or the raw response from
  *                      the server.
  * @throws Box\View\BoxViewException
  */
 private static function handleResponse($response, $isRawResponse, $request)
 {
     $responseBody = (string) $response->getBody();
     // if we want a raw response, then it's not JSON, and we're done
     if (!empty($isRawResponse)) {
         return $responseBody;
     }
     // decode json and handle any potential errors
     $jsonDecoded = json_decode($responseBody, true);
     if ($jsonDecoded === false || $jsonDecoded === null) {
         return static::error(static::JSON_RESPONSE_ERROR, null, $request, $response);
     }
     if (is_array($jsonDecoded) && isset($jsonDecoded['status']) && $jsonDecoded['status'] == 'error') {
         $message = !empty($jsonDecoded['error_message']) ? $jsonDecoded['error_message'] : 'Server error';
         return static::error(static::SERVER_ERROR, $message, $request, $response);
     }
     return $jsonDecoded;
 }
Esempio n. 7
0
 /**
  * Set the headers received with the last response.
  *
  * @param GuzzleHttp\Message\Response $response
  */
 public function setLastResponseHeaders($response)
 {
     $this->lastResponseHeaders = $response->getHeaders();
     return $this;
 }
Esempio n. 8
0
 /**
  * Gets the HTTP Status Code
  *
  * @return number
  */
 public function getStatusCode()
 {
     return $this->response->getStatusCode();
 }