Ejemplo n.º 1
0
 /**
  * Sends a request and returns a response
  *
  * @param CartRecover_Request $request
  * @return Cart_Recover_Response
  */
 public function sendRequest(CartRecover_Request $request)
 {
     $this->client->setUri($request->getUri());
     $this->client->setParameterGet($request->getParams());
     $this->client->setMethod($request->getMethod());
     $this->client->setHeaders(array('Accept' => 'application/json'));
     $this->response = $this->client->send();
     if ($this->response->getHeaders()->get('Content-Type')->getFieldValue() != 'application/json') {
         throw new CartRecover_Exception_UnexpectedValueException("Unknown response format.");
     }
     $body = json_decode($this->response->getContent(), true);
     $response = new CartRecover_Response();
     $response->setRawResponse($this->response->toString());
     $response->setBody($body);
     $response->setHeaders($this->response->getHeaders()->toArray());
     $response->setStatus($this->response->getReasonPhrase(), $this->response->getStatusCode());
     return $response;
 }
 public function sendPushNotification(PushNotification $notification)
 {
     $app = $this->getSetting('App');
     $devices = array_filter(explode(',', $this->getSetting('Devices')), 'strlen');
     if (!$app) {
         throw new PushException('No application was selected.');
     }
     if (!isset(self::$applications[$app])) {
         throw new PushException(sprintf('No settings were provided for application "%s"', $app));
     }
     if (!$devices) {
         throw new PushException('At least one device type must be selected to send to.');
     }
     $user = self::$applications[$app]['key'];
     $pass = self::$applications[$app]['secret'];
     $request = function ($url, $payload) use($user, $pass) {
         $client = new Zend\Http\Client($url);
         $client->setAuth($user, $pass);
         $client->setHeaders('Content-Type: application/json');
         $client->setRawData(json_encode($payload), 'application/json');
         try {
             $response = $client->request('POST');
         } catch (Zend\Http\Client_Exception $e) {
             throw new PushException($e->getMessage(), $e->getCode(), $e);
         }
         if ($response->isError()) {
             throw new PushException($response->getBody(), $response->getStatus());
         }
     };
     // Use the V1 API for sending to Android, Blackberry and iOS.
     if (array_intersect($devices, array(self::ANDROID, self::BLACKBERRY, self::IOS))) {
         $body = array();
         if (in_array(self::ANDROID, $devices)) {
             $body['android'] = array('alert' => $notification->Content);
         }
         if (in_array(self::BLACKBERRY, $devices)) {
             $body['blackberry'] = array('content-type' => 'text/plain', 'body' => $notification->Content);
         }
         if (in_array(self::IOS, $devices)) {
             $body['aps'] = array('badge' => $this->getSetting('Badge') == 'inc' ? '+1' : $this->getSetting('Badge'), 'alert' => $notification->Content, 'sound' => $this->getSetting('Sound'));
         }
         $request(self::V1_API_URL . '/broadcast/', $body);
     }
     // Use the V2 API for sending to Windows.
     if (array_intersect($devices, array(self::MPNS, self::WNS))) {
         $types = array();
         if (in_array(self::MPNS, $devices)) {
             $types[] = 'mpns';
         }
         if (in_array(self::WNS, $devices)) {
             $types[] = 'wns';
         }
         $request(self::V2_API_URL . '/broadcast/', array('notification' => array('alert' => $notification->Content), 'device_types' => $types));
     }
 }
Ejemplo n.º 3
0
 public function testPutRoleResources()
 {
     $client = new \Zend\Http\Client(self::HOST . '/roles/1/resources/ZfeggAdmin\\V1\\Rest\\AdminRole\\Controller::collection');
     $client->setMethod('PUT');
     $client->setHeaders(['Accept' => 'application/hal+json', 'Content-Type' => 'application/json']);
     $client->setRawBody(json_encode(['resource' => 'ZfeggAdmin\\V1\\Rest\\AdminRole\\Controller::collection', 'privileges' => ['GET', 'post', 'Put', 'delete']]));
     $response = $client->send();
     echo Json::prettyPrint($response->getBody());
 }
Ejemplo n.º 4
0
            $last = fgets($fh);
            fclose($fh);
        }
    }
    if ($last) {
        list($last, $last_version) = explode('|', $last);
        if ($last > time() - 60 * 60 * 24) {
            $doit = false;
        }
    }
}
if ($doit) {
    ini_set('include_path', CAT_PATH . '/modules/lib_zendlite');
    include CAT_PATH . '/modules/lib_zendlite/library.php';
    $client = new Zend\Http\Client($current['source'], array('timeout' => $current['timeout'], 'adapter' => 'Zend\\Http\\Client\\Adapter\\Proxy', 'proxy_host' => $current['proxy_host'], 'proxy_port' => $current['proxy_port']));
    $client->setHeaders(array('Pragma' => 'no-cache', 'Cache-Control' => 'no-cache'));
    try {
        $response = $client->send();
        if ($response->getStatusCode() != '200') {
            $error = "Unable to load source " . "(using Proxy: " . (isset($current['proxy_host']) && $current['proxy_host'] != '' ? 'yes' : 'no') . ")<br />" . "Status: " . $response->getStatus() . " - " . $response->getMessage() . ($debug ? "<br />" . var_dump($client->getLastRequest()) : NULL) . "<br />";
            $version = 'unknown';
        } else {
            $version = $response->getBody();
        }
    } catch (Exception $e) {
        $error = "Unable to load source " . "(using Proxy: " . (isset($current['proxy_host']) && $current['proxy_host'] != '' ? 'yes' : 'no') . ")<br />" . $e->getMessage() . "<br />";
        $version = 'unknown';
    }
    if ($version && $version != 'unknown') {
        if (CAT_Helper_Addons::getInstance()->versionCompare($version, CAT_VERSION, '>')) {
            $newer = true;
Ejemplo n.º 5
0
 /**
  * @throws Exception\ReceiversWasNotSpecified
  */
 public function send()
 {
     if (!count($this->getMessages())) {
         throw new Exception\ReceiversWasNotSpecified();
     }
     $client = new \Zend\Http\Client();
     $client->setUri(implode('/', [self::getConfig()['uri'], 'index/send']));
     $client->setHeaders(['x-auth' => self::getToken()]);
     $client->setMethod('POST');
     $messages = [];
     foreach ($this->getMessages() as $message) {
         $messages[] = $message->asArray();
     }
     $client->setParameterPost(['messages' => $messages]);
     return $client->send()->getBody();
 }