Пример #1
0
 /**
  * {@inheritDoc}
  **/
 public function __construct(array $params)
 {
     $this->client = new \PestJSON($params['host']);
     $this->client->setupAuth($params['user'], $params['pass']);
     $this->baseUrl = $params['baseUrl'];
     $this->host = $params['host'];
     $this->predefinedParams = $params['predefinedParams'];
     $this->statusIdsFlipped = array_flip($this->statusIds);
 }
Пример #2
0
 /**
  * Connect to ARI.
  *
  * @param string $address Example ws://localhost:8088/ari/events?api_key=username:password&app=stasis_app_name
  */
 public function connect($address)
 {
     $components = parse_url($address);
     $host = $components['host'];
     $port = $components['port'];
     $path = $components['path'];
     $query = $components['query'];
     $queryParts = [];
     parse_str($query, $queryParts);
     $this->stasisApplicationName = $queryParts['app'];
     $apiKey = $queryParts['api_key'];
     list($username, $password) = explode(':', $apiKey);
     $this->endpoint = new PestJSON('http://' . $host . ':' . $port . dirname($path));
     $this->endpoint->setupAuth($username, $password, 'basic');
     $this->wsClient = new WebSocket($address, $this->eventLoop, $this->logger);
     $this->wsClient->on("message", function (WebSocketMessage $rawMessage) {
         $message = new Message($rawMessage->getData());
         $eventType = '\\phparia\\Events\\' . $message->getType();
         if (class_exists($eventType)) {
             $event = new $eventType($this, $rawMessage->getData());
         } else {
             $this->logger->warn("Event: '{$eventType}' not implemented");
             // @todo Create a generic event for any that are not implemented
             return;
         }
         // Emit the specific event (just to get it back to where it came from)
         if ($event instanceof IdentifiableEventInterface) {
             $this->logger->notice("Emitting ID event: {$event->getEventId()}");
             $this->wsClient->emit($event->getEventId(), array('event' => $event));
         }
         // Emit the general event
         $this->logger->notice("Emitting event: {$message->getType()}");
         $this->wsClient->emit($message->getType(), array('event' => $event));
     });
 }
 public static function pageSlurp()
 {
     require_once CART66_PATH . "/models/Pest.php";
     require_once CART66_PATH . "/models/PestJSON.php";
     $page_id = Cart66Common::postVal('page_id');
     $page = get_page($page_id);
     $slurp_url = get_permalink($page->ID);
     $html = false;
     $job_id = $slurp_url;
     if (wp_update_post(array('ID' => $page->ID, 'post_status' => 'publish'))) {
         $access_key = Cart66Setting::getValue('mijireh_access_key');
         $rest = new PestJSON(MIJIREH_CHECKOUT);
         $rest->setupAuth($access_key, '');
         $data = array('url' => $slurp_url, 'page_id' => $page->ID, 'return_url' => add_query_arg('task', 'mijireh_page_slurp', $slurp_url));
         try {
             $response = $rest->post('/api/1/slurps', $data);
             $job_id = $response['job_id'];
         } catch (Pest_Unauthorized $e) {
             header('Bad Request', true, 400);
             die;
         }
     } else {
         $job_id = 'did not update post successfully';
     }
     echo $job_id;
     die;
 }
Пример #4
0
 public function pullOrder($order_number)
 {
     $access_key = Cart66Setting::getValue('mijireh_access_key');
     $rest = new PestJSON(MIJIREH_CHECKOUT);
     $rest->setupAuth($access_key, '');
     $order_data = $rest->get('/api/1/orders/' . $order_number);
     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] GETTING MIJIREH ORDER: " . print_r($order_data, true));
     return $order_data;
 }
 private function send($endpoint, $operation, $request)
 {
     $pest = new PestJSON($this->url);
     $pest->setupAuth($this->username, $this->password);
     $pest->curl_opts[CURLOPT_FOLLOWLOCATION] = false;
     // Not supported on hosts running safe_mode!
     $pest->curl_opts[CURLOPT_HTTPHEADER] = "Content-Type: application/json";
     $pest->curl_opts[CURLOPT_USERAGENT] = $this->USER_AGENT . " (v" . $this->CLIENT_VERSION . ")";
     $response = "";
     try {
         // Send request to rest service
         switch ($operation) {
             case $this->OP_PUT:
                 $response = $pest->put("/{$endpoint}", $request);
                 break;
             case $this->OP_GET:
                 $response = $pest->get("/{$endpoint}", $request);
                 break;
             case $this->OP_POST:
                 $response = $pest->post("/{$endpoint}", $request);
                 break;
             case $this->OP_DELETE:
                 $response = $pest->delete("/{$endpoint}", $request);
                 break;
         }
     } catch (Exception $e) {
         echo "Caught exception when sending request : " . $e->getMessage();
     }
     return $response;
 }
Пример #6
0
 /**
  * @return Pest rest client used to speak to the Sweet Tooth Platform
  *
  */
 protected function getRestClient()
 {
     if ($this->_restClient) {
         return $this->_restClient;
     }
     $baseUrl = $this->getApiBaseUrl();
     $pest = new PestJSON($baseUrl);
     $pest->setupAuth($this->apiKey, $this->apiSecret);
     $this->_restClient = $pest;
     return $this->_restClient;
 }