示例#1
0
 public function testGettersSetters()
 {
     $notification = new Notification(array(new Device('234'), new Device('23452')), 'testing');
     $parameter = new Parameters('test', $notification);
     $this->assertEquals('test', $parameter->getKey());
     $this->assertEquals($notification, $parameter->getNotification());
     $parameter->setKey('test2');
     $parameter->setNotification(new Notification(array(new Device('test'))));
     $this->assertEquals('test2', $parameter->getKey());
     $this->assertNotEquals($notification, $parameter->getNotification());
 }
示例#2
0
 /**
  * submits the request to the server and returns a Response
  *
  * @param Parameters $parameters
  * @return string
  * @throws ApiException
  */
 public function submit(Parameters $parameters)
 {
     $request = $this->client->createRequest('POST', $this->endpoint);
     $request->setBody(Stream::factory($parameters->getNotification()->toJson()));
     $request->addHeaders(array('Content-Type' => 'application/json', 'Authorization' => 'key=' . $parameters->getKey()));
     try {
         $response = $this->client->send($request);
     } catch (RequestException $exception) {
         $response = $exception->getResponse();
     }
     // determine if the response succeeded
     if ($response->getStatusCode() == 200) {
         return $response->getBody()->getContents();
     } elseif ($response->getStatusCode() == 401) {
         throw new ApiException('Key provided was not authorized to make requests to the server');
     } elseif ($response->getStatusCode() >= 500) {
         throw new ApiException('Server error from API');
     } else {
         throw new ApiException('Unknown response code from server' . $response->getStatusCode());
     }
 }