protected function setupCallbackUrl() { //Create and setup callback URL $this->callback_url = new Url(); $this->callback_url->setScheme('http'); $this->callback_url->setHost('ws.audioscrobbler.com'); $this->callback_url->setPath('/2.0/'); //2.0 - API version $this->callback_url->appendQuery("api_key={$this->key}"); if ($this->data_format == self::DATA_JSON) { $this->callback_url->appendQuery('format=json'); } //JSON result }
public function render($rowData) { if ($this->_renderer) { return call_user_func($this->_renderer, $this); } // Direct URL if ($this->_url !== NULL) { // URL callback if (is_callable($this->_url)) { $url = call_user_func($this->_url, $rowData); } else { $url = new Nette\Http\Url($this->_url); foreach ($this->_table->getIdColumns() as $key) { $url->appendQuery(array('record' . ucfirst($key) => isset($rowData->{$key}) ? $rowData->{$key} : NULL)); } } $this->element->href((string) $url); // Standard action's URL } else { $this->element->href($this->_table->createActionLink($this->getName(), $rowData)); } // Class if (($class = $this->getClass($rowData)) !== NULL) { $this->element->class .= " {$class}"; } return (string) $this->element; }
/** * Calls remote API. * * @param string * @return mixed json-decoded result * @throws \NetteAddons\IOException */ protected function exec($path) { try { $url = new Url($this->baseUrl . '/' . ltrim($path, '/')); if ($this->clientId && $this->clientSecret) { $url->appendQuery(array('client_id' => $this->clientId, 'client_secret' => $this->clientSecret)); } $request = $this->requestFactory->create($url); $request->addHeader('Accept', "application/vnd.github.{$this->apiVersion}+json"); return \Nette\Utils\Json::decode($request->execute()); } catch (\NetteAddons\Utils\StreamException $e) { throw new \NetteAddons\IOException('Request execution failed.', NULL, $e); } catch (\Nette\Utils\JsonException $e) { throw new \NetteAddons\IOException('GitHub API returned invalid JSON.', NULL, $e); } }
/** * Send OAuth response * @param array|\Traversable $data * @param string|null $redirectUrl * @param int $code */ public function oauthResponse($data, $redirectUrl = NULL, $code = 200) { if ($data instanceof \Traversable) { $data = iterator_to_array($data); } $data = (array) $data; // Redirect, if there is URL if ($redirectUrl !== NULL) { $url = new Url($redirectUrl); if ($this->getParameter('response_type') == 'token') { $url->setFragment(http_build_query($data)); } else { $url->appendQuery($data); } $this->redirectUrl($url); } // else send JSON response foreach ($data as $key => $value) { $this->payload->{$key} = $value; } $this->getHttpResponse()->setCode($code); $this->sendResponse(new JsonResponse($this->payload)); }
public function appendQuery($value) { parent::appendQuery($value); $this->queryArray = array(); \parse_str($this->getQuery(), $this->queryArray); }