Esempio n. 1
0
 /**
  * Make a custom api request.
  *
  * @param string                      $method  HTTP Method
  * @param string                      $uri     URI template
  * @param array                       $headers
  * @param string|StreamInterface|null $body
  *
  * @throws OneSignalException
  *
  * @return array
  */
 public function request($method, $uri, array $headers = [], $body = null)
 {
     try {
         $response = $this->client->send($method, self::API_URL . $uri, array_merge(['Content-Type' => 'application/json'], $headers), $body);
         return json_decode($response->getBody(), true);
     } catch (\Throwable $t) {
         throw new OneSignalException($t->getMessage());
     } catch (\Exception $e) {
         throw new OneSignalException($e->getMessage());
     }
 }
Esempio n. 2
0
 /**
  * Ping an endpoint.
  *
  * @param  string  $method
  * @param  \Psr\Http\Message\UriInterface|string  $uri
  * @param  mixed  $body
  * @param  array  $headers
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function send($method, $uri, $data = [], array $headers = [])
 {
     list($headers, $body) = $this->prepareRequestPayloads($headers, $body);
     return $this->http->send(strtoupper($method), $uri, $headers, $body);
 }