Example #1
0
 /**
  * Push the notification.
  *
  * @return GCMResponse $return Response object
  */
 public function push()
 {
     $this->curl->set_option('CURLOPT_HEADER', TRUE);
     $this->curl->set_http_headers(['Content-Type:application/json', 'Authorization: key=' . $this->auth_token]);
     $tmp_payload = json_decode($this->payload, TRUE);
     $tmp_payload['registration_ids'] = [$this->endpoint];
     $tmp_payload['priority'] = $this->priority;
     $this->payload = json_encode($tmp_payload);
     $response = $this->curl->post_request(self::GOOGLE_SEND_URL, $this->payload);
     $res = new GCMResponse($response, $this->logger, $this->endpoint);
     $this->endpoint = '';
     $this->payload = '';
     return $res;
 }
Example #2
0
 /**
  * Fetch and parse results as though they were a query string.
  *
  * @param String $url    API URL
  * @param Array  $params Array of parameters for the API request
  * @param String $method Request method to use, either 'get' or 'post'
  *
  * @return Array $result Array of return values
  */
 protected function get_json_results($url, $params = [], $method = 'get')
 {
     if (strtolower($method) === 'get') {
         $response = $this->curl->get_request($url . '?' . http_build_query($params));
     } else {
         $response = $this->curl->post_request($url, $params);
     }
     $result = json_decode($response->get_result(), TRUE);
     if ($response->http_code !== 200) {
         $error = $result['errors'][0];
         $context = ['message' => $error['message'], 'code' => $error['code'], 'request' => $url];
         $this->logger->error('Twitter API Request ({request}) failed, ({code}): {message}', $context);
         $result = '';
     }
     unset($response);
     return $result;
 }
Example #3
0
 /**
  * Fetch and parse results as though they were a query string.
  *
  * @param String $url    API URL
  * @param Array  $params Array of parameters for the API request
  * @param String $method Request method to use, either 'get' or 'post'
  *
  * @return Array $parts Array of return values
  */
 protected function get_json_results($url, $params = [], $method = 'get')
 {
     $this->curl->set_option('CURLOPT_FAILONERROR', FALSE);
     if (strtolower($method) === 'get') {
         $response = $this->curl->get_request($url . '?' . http_build_query($params));
     } else {
         $response = $this->curl->post_request($url, $params);
     }
     $result = json_decode($response->get_result(), TRUE);
     if ($response->http_code !== 200) {
         $error = $result['error'];
         $result = [];
         $context = ['message' => $error['message'], 'code' => $error['code'], 'type' => $error['type'], 'request' => $url];
         $this->logger->error('Facebook API Request ({request}) failed, {type} ({code}): {message}', $context);
     }
     unset($response);
     return $result;
 }
Example #4
0
 /**
  * Push the notification.
  *
  * @return PAPResponse $return Response object
  */
 public function push()
 {
     // construct PAP URL
     $pap_url = "https://cp{$this->cid}.pushapi.na.blackberry.com/mss/PD_pushRequest";
     $pap_data = $this->construct_pap_data();
     $this->curl->set_option('CURLOPT_URL', $pap_url);
     $this->curl->set_option('CURLOPT_HEADER', FALSE);
     $this->curl->set_option('CURLOPT_HTTP_VERSION', CURL_HTTP_VERSION_1_1);
     $this->curl->set_option('CURLOPT_HTTPAUTH', CURLAUTH_BASIC);
     $this->curl->set_option('CURLOPT_USERPWD', $this->auth_token . ':' . $this->password);
     $this->curl->set_option('CURLOPT_RETURNTRANSFER', TRUE);
     $this->curl->set_http_header('Content-Type: multipart/related; boundary=' . self::PAP_BOUNDARY . '; type=application/xml');
     $this->curl->set_http_header('Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2');
     $this->curl->set_http_header('Connection: keep-alive');
     $response = $this->curl->post_request($pap_url, $pap_data);
     $res = new PAPResponse($response, $this->logger, $this->endpoint);
     $this->endpoint = '';
     $this->push_id = '';
     $this->payload = '';
     $this->deliverbefore = '';
     return $res;
 }