/** * @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; }
/** * @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; }