Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * @param QuarkClient $client
  *
  * @return mixed
  */
 public function Client(QuarkClient $client)
 {
     $conn = $client->Connect();
     if (!$conn) {
         Quark::Log('Mail. Unable to connect to mail server. Error: ' . $client->Error(true));
         return false;
     }
     $smtp = $this->_config->SMTP();
     $this->_dto->Header(QuarkDTO::HEADER_CONTENT_TRANSFER_ENCODING, QuarkDTO::TRANSFER_ENCODING_BASE64);
     try {
         $this->_cmd($client, 220);
         $this->_cmd($client, 250, 'HELO Quark');
         $this->_cmd($client, 334, 'AUTH LOGIN');
         $this->_cmd($client, 334, base64_encode($smtp->user));
         $this->_cmd($client, 235, base64_encode($smtp->pass));
         $this->_cmd($client, 250, 'MAIL FROM: <' . $smtp->user . '>');
         foreach ($this->_receivers as $receiver) {
             $this->_cmd($client, 250, 'RCPT TO: <' . $receiver . '>');
         }
         $this->_cmd($client, 354, 'DATA');
         $this->_cmd($client, 250, $this->_dto->SerializeResponseBody() . "\r\n.");
         $this->_cmd($client, 221, 'QUIT');
     } catch (QuarkArchException $e) {
         return false;
     }
     return $client->Close();
 }
Exemplo n.º 3
0
 /**
  * @param $payload
  * @param $options
  *
  * @return mixed
  */
 public function Send($payload, $options = [])
 {
     $request = QuarkDTO::ForPOST(new QuarkJSONIOProcessor());
     $request->Header(QuarkDTO::HEADER_AUTHORIZATION, 'key=' . $this->_key);
     $request->Data(array('registration_ids' => $this->_devices, 'data' => $payload));
     $response = new QuarkDTO(new QuarkJSONIOProcessor());
     return QuarkHTTPTransportClient::To('https://android.googleapis.com/gcm/send', $request, $response);
 }
Exemplo n.º 4
0
 /**
  * @param \Quark\Extensions\Payment\IQuarkPaymentScenario $data
  * @param string $url
  *
  * @return QuarkHTTPTransportClient
  */
 public function API($data, $url)
 {
     $request = QuarkDTO::ForPOST(new QuarkJSONIOProcessor());
     $request->Header(QuarkDTO::HEADER_AUTHORIZATION, $this->Authorization());
     $request->Data($data);
     $response = new QuarkDTO(new QuarkJSONIOProcessor());
     return QuarkHTTPTransportClient::To($url, $request, $response);
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
 /**
  * @param string $name
  * @param IQuarkAuthorizableModel $user
  * @param QuarkDTO $input
  * @param bool $http
  *
  * @return bool
  */
 public function Input($name, IQuarkAuthorizableModel $user, QuarkDTO $input, $http)
 {
     $this->_name = $name;
     $session = $http ? $input->GetCookieByName($this->_cookie) : ($input->AuthorizationProvider() != null ? $input->AuthorizationProvider()->ToCookie() : null);
     if (!$session) {
         return false;
     }
     $session->value = trim($session->value);
     if (!$session->value) {
         return false;
     }
     $storage = self::_storage($name, $session->value);
     try {
         $json = json_decode($storage->Load()->Content());
         if (!$json || QuarkObject::isIterative($json)) {
             return false;
         }
         $this->_sid = $session->value;
         $this->_user = $json->user;
         $this->_signature = $json->signature;
         $this->_ttl = $json->ttl;
         $this->_output = new QuarkDTO();
         $this->_output->AuthorizationProvider(new QuarkKeyValuePair($this->_name, $this->_sid));
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
Exemplo n.º 7
0
 /**
  * @param QuarkClient $client
  * @param string $data
  *
  * @return mixed
  * @throws \Exception
  */
 public function OnData(QuarkClient $client, $data)
 {
     if ($client->Connected()) {
         try {
             $this->_buffer .= $data;
             $out = $this->_processor->Decode($this->_buffer);
             if ($out !== false) {
                 $this->_buffer = '';
                 if ($this->_protocol) {
                     $this->_protocol->OnData($client, $out);
                 }
             }
         } catch (\Exception $e) {
             $this->_buffer = '';
         }
     } else {
         if ($data != "\r\n") {
             $this->_buffer .= $data;
             return;
         }
         $request = new QuarkDTO();
         $request->UnserializeRequest($this->_buffer . "\r\n");
         $this->_buffer = '';
         $response = new QuarkDTO(new QuarkHTMLIOProcessor());
         $response->Status(101, 'Switching Protocols');
         $response->Headers(array(QuarkDTO::HEADER_CONNECTION => QuarkDTO::CONNECTION_UPGRADE, QuarkDTO::HEADER_UPGRADE => QuarkDTO::UPGRADE_WEBSOCKET, QuarkDTO::HEADER_SEC_WEBSOCKET_ACCEPT => base64_encode(sha1($request->Header(QuarkDTO::HEADER_SEC_WEBSOCKET_KEY) . self::GuID, true))));
         if (strlen($this->_subprotocol) != 0) {
             $response->Header(QuarkDTO::HEADER_SEC_WEBSOCKET_PROTOCOL, $this->_subprotocol);
         }
         $client->Send($response->SerializeResponse());
         $client->Connected(true);
         $client->BeforeSend(function ($data) {
             return $this->_processor->Encode($data);
         });
         if ($this->_protocol) {
             $this->_protocol->OnConnect($client);
         }
     }
 }
Exemplo n.º 8
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);
        }
    }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
0
 /**
  * @param string $append
  *
  * @return QuarkDTO!bool
  * @throws QuarkArchException
  */
 private function _main($append = '')
 {
     if (strlen($this->_message) == 0) {
         throw new QuarkArchException('SMS: message length should be greater than 0');
     }
     return QuarkHTTPTransportClient::To('http://smsc.ru/sys/send.php' . '?login='******'&psw=' . $this->_config->password . '&phones=' . implode(',', $this->_phones) . '&mes=' . $this->_message . '&fmt=3' . '&charset=utf-8' . ($this->_config->sender != '' ? '&sender=' . $this->_config->sender : '') . $append, QuarkDTO::ForGET(new QuarkPlainIOProcessor()), new QuarkDTO(new QuarkJSONIOProcessor()));
 }