예제 #1
0
 /**
  * @param string $method
  * @param string $action
  * @param mixed $data
  *
  * @return mixed
  * @throws QuarkArchException
  */
 private function _api($method, $action, $data = [])
 {
     $request = new QuarkDTO(new QuarkJSONIOProcessor());
     $request->Method($method);
     $request->Merge($data);
     $response = new QuarkDTO(new QuarkJSONIOProcessor());
     if (!$this->_uri) {
         throw new QuarkArchException('QuarkRest API is not reachable. URI is not provided');
     }
     $this->_uri->path = $action;
     $data = QuarkHTTPTransportClient::To($this->_uri->URI(true), $request, $response);
     if ($data == null || !isset($data->status) || $data->status != 200) {
         throw new QuarkArchException('QuarkRest API is not reachable. Response: ' . print_r($data, true));
     }
     return $data;
 }
예제 #2
0
    /**
     * @param $payload
     * @param $options
     *
     * @return mixed
     */
    public function Send($payload, $options = [])
    {
        $type = isset($options[self::OPTION_TYPE]) ? $options[self::OPTION_TYPE] : self::TYPE_TOAST;
        $badge = isset($options[self::OPTION_VALUE]) ? $options[self::OPTION_VALUE] : null;
        $visual = '';
        $templates = isset($options[self::OPTION_VISUAL]) && is_array($options[self::OPTION_VISUAL]) ? $options[self::OPTION_VISUAL] : array();
        foreach ($templates as $elem) {
            if ($elem instanceof MicrosoftNotificationTemplate) {
                $visual .= $elem->Binding();
            }
        }
        $request = new QuarkDTO(new QuarkPlainIOProcessor());
        $request->Method('POST');
        $request->Header(QuarkDTO::HEADER_AUTHORIZATION, 'Bearer ' . $this->_token());
        $request->Header('X-WNS-Type', $type);
        $request->Header(QuarkDTO::HEADER_CONTENT_TYPE, 'text/xml');
        $type = str_replace('wns/', '', $type);
        $data = '<?xml version="1.0" encoding="utf-8"?>
			<' . $type . ($badge === null ? '' : ' value="' . $badge . '"') . '>' . ($type == self::TYPE_BADGE ? '' : '<visual>' . $visual . '</visual>') . '<data>' . json_encode($payload) . '</data>
			</' . $type . '>';
        $request->Data($data);
        $response = new QuarkDTO(new QuarkPlainIOProcessor());
        foreach ($this->_devices as $device) {
            QuarkHTTPTransportClient::To($device->id, $request, $response);
        }
    }
예제 #3
0
 /**
  * @param string $method
  * @param string $url
  * @param array  $data
  * @param string $base = 'https://graph.facebook.com/'
  *
  * @return QuarkDTO|\StdClass
  */
 public function API($method = '', $url = '', $data = [], $base = 'https://graph.facebook.com/')
 {
     $request = new QuarkDTO(new QuarkJSONIOProcessor());
     $request->Method($method);
     $get = $method == 'GET';
     if (!$get) {
         $request->Data($data);
     }
     $response = new QuarkDTO(new QuarkJSONIOProcessor());
     $out = QuarkHTTPTransportClient::To($base . $url . '?' . http_build_query(array_merge_recursive($get ? $data : array()) + array('access_token' => $this->_session)), $request, $response);
     if (!$out->Data()) {
         $data = array();
         parse_str($out->RawData(), $data);
         $out->Data((object) $data);
     }
     if (isset($out->error)) {
         Quark::Log('Facebook.Exception: ' . (isset($out->error->type) ? $out->error->type : '') . ': ' . (isset($out->error->message) ? $out->error->message : '') . '. Code: ' . (isset($out->error->code) ? $out->error->code : ''), Quark::LOG_WARN);
         Quark::Trace($out);
         return null;
     }
     return $out;
 }
예제 #4
0
 /**
  * @param string $method
  * @param string $url
  * @param array  $data
  * @param string $base = 'https://api.vk.com/method/'
  *
  * @return QuarkDTO|\StdClass
  */
 public function API($method = '', $url = '', $data = [], $base = 'https://api.vk.com/method/')
 {
     $request = new QuarkDTO(new QuarkFormIOProcessor());
     $request->Method($method);
     $get = $method == 'GET';
     if (!$get) {
         $request->Data($data);
     }
     $response = new QuarkDTO(new QuarkJSONIOProcessor());
     $out = QuarkHTTPTransportClient::To($base . $url . '?' . http_build_query(array_merge_recursive($get ? $data : array()) + array('access_token' => $this->_session)), $request, $response);
     if (isset($out->error)) {
         Quark::Log('VKontakte.Exception: ' . (isset($out->error->error_code) ? $out->error->error_code : '') . ': ' . (isset($out->error->error_msg) ? $out->error->error_msg : ''), Quark::LOG_WARN);
         Quark::Trace($out);
         return null;
     }
     return $out;
 }