/** * Method to build and return a full request URL for the request. This method will * add appropriate pagination details if necessary and also prepend the API url * to have a complete URL for the request. * * @param string $path URL to inflect * @param integer $page Page to request * @param integer $limit Number of results to return per page * * @return string The request URL. * * @since 1.0 */ protected function fetchUrl($path, $page = 0, $limit = 0) { // Get a new Uri object fousing the api url and given path. $uri = new Uri($this->options->get('api.url') . $path); if ($this->options->get('gh.token', false)) { // Use oAuth authentication - @todo set in request header ? $uri->setVar('access_token', $this->options->get('gh.token')); } else { // Use basic authentication if ($this->options->get('api.username', false)) { $uri->setUser($this->options->get('api.username')); } if ($this->options->get('api.password', false)) { $uri->setPass($this->options->get('api.password')); } } // If we have a defined page number add it to the JUri object. if ($page > 0) { $uri->setVar('page', (int) $page); } // If we have a defined items per page add it to the JUri object. if ($limit > 0) { $uri->setVar('per_page', (int) $limit); } return (string) $uri; }
/** * Method to build and return a full request URL for the request. This method will * add appropriate pagination details if necessary and also prepend the API url * to have a complete URL for the request. * * @param string $path URL to inflect. * @param integer $limit The number of objects per page. * @param integer $offset The object's number on the page. * @param string $until A unix timestamp or any date accepted by strtotime. * @param string $since A unix timestamp or any date accepted by strtotime. * * @return string The request URL. * * @since 1.0 */ protected function fetchUrl($path, $limit = 0, $offset = 0, $until = null, $since = null) { // Get a new Uri object fousing the api url and given path. $apiUrl = isset($this->options['api.url']) ? $this->options['api.url'] : null; $uri = new Uri($apiUrl . $path); if ($limit > 0) { $uri->setVar('limit', (int) $limit); } if ($offset > 0) { $uri->setVar('offset', (int) $offset); } if ($until != null) { $uri->setVar('until', $until); } if ($since != null) { $uri->setVar('since', $since); } return (string) $uri; }
/** * Method to build and return a full request URL for the request. This method will * add appropriate pagination details if necessary and also prepend the API url * to have a complete URL for the request. * * @param string $path URL to inflect * @param integer $page Page to request * @param integer $limit Number of results to return per page * * @return string The request URL. * * @since 11.3 */ protected function fetchUrl($path, $page = 0, $limit = 0) { // Get a new JUri object fousing the api url and given path. $uri = new Uri($this->options->get('api.url') . $path); if ($this->options->get('api.username', false)) { $uri->setUser($this->options->get('api.username')); } if ($this->options->get('api.password', false)) { $uri->setPass($this->options->get('api.password')); } // If we have a defined page number add it to the JUri object. if ($page > 0) { $uri->setVar('page', (int) $page); } // If we have a defined items per page add it to the JUri object. if ($limit > 0) { $uri->setVar('per_page', (int) $limit); } return (string) $uri; }
/** * Method to list issues. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param string $milestone The milestone number, 'none', or *. * @param string $state The optional state to filter requests by. [open, closed] * @param string $assignee The assignee name, 'none', or *. * @param string $mentioned The GitHub user name. * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. * @param string $sort The sort order: created, updated, comments, default: created. * @param string $direction The list direction: asc or desc, default: desc. * @param Date $since The date/time since when issues should be returned. * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return object * * @since 1.0 * @throws \DomainException */ public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, $sort = null, $direction = null, Date $since = null, $page = 0, $limit = 0) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues'; $uri = new Uri($this->fetchUrl($path, $page, $limit)); if ($milestone) { $uri->setVar('milestone', $milestone); } if ($state) { $uri->setVar('state', $state); } if ($assignee) { $uri->setVar('assignee', $assignee); } if ($mentioned) { $uri->setVar('mentioned', $mentioned); } if ($labels) { $uri->setVar('labels', $labels); } if ($sort) { $uri->setVar('sort', $sort); } if ($direction) { $uri->setVar('direction', $direction); } if ($since) { $uri->setVar('since', $since->toISO8601()); } // Send the request. $response = $this->client->get((string) $uri); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); throw new \DomainException($error->message, $response->code); } return json_decode($response->body); }
/** * Test the setVar method. * * @return void * * @since 1.0 * @covers Joomla\Uri\Uri::setVar */ public function testSetVar() { $this->object->setVar('somevariable', 'somevalue'); $this->assertThat($this->object->getVar('somevariable'), $this->equalTo('somevalue')); }
/** * Get the Uri object for a given page. * * @param integer $page The page number. * * @return Uri * * @since 1.0 */ private function uri($page) { $this->uri->setVar('page', $page); return $this->uri; }
/** * Method to list issues. * * @param string $user The name of the owner of the GitHub repository. * @param string $repo The name of the GitHub repository. * @param string $milestone The milestone number, 'none', or *. * @param string $state The optional state to filter requests by. [open, closed] * @param string $assignee The assignee name, 'none', or *. * @param string $mentioned The GitHub user name. * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. * @param string $sort The sort order: created, updated, comments, default: created. * @param string $direction The list direction: asc or desc, default: desc. * @param Date $since The date/time since when issues should be returned. * @param integer $page The page number from which to get items. * @param integer $limit The number of items on a page. * * @return object * * @since 1.0 * @throws \DomainException */ public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, $sort = null, $direction = null, Date $since = null, $page = 0, $limit = 0) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues'; $uri = new Uri($this->fetchUrl($path, $page, $limit)); if ($milestone) { $uri->setVar('milestone', $milestone); } if ($state) { $uri->setVar('state', $state); } if ($assignee) { $uri->setVar('assignee', $assignee); } if ($mentioned) { $uri->setVar('mentioned', $mentioned); } if ($labels) { $uri->setVar('labels', $labels); } if ($sort) { $uri->setVar('sort', $sort); } if ($direction) { $uri->setVar('direction', $direction); } if ($since) { $uri->setVar('since', $since->toISO8601()); } // Send the request. return $this->processResponse($this->client->get((string) $uri)); }
/** * Method to retrieve the correct URI for login via GitHub * * @return string The login URI * * @since 1.0 */ public function getLoginUri() { if (!$this->clientId) { // No clientId set - Throw some fatal error... return ''; } /* @type \JTracker\Application $application */ $application = $this->container->get('app'); $redirect = $application->get('uri.base.full') . 'login'; $uri = new Uri($redirect); $usrRedirect = base64_encode((string) new Uri($application->get('uri.request'))); $uri->setVar('usr_redirect', $usrRedirect); $redirect = (string) $uri; // Use "raw URI" here to partial encode the url. return 'https://github.com/login/oauth/authorize?scope=' . $application->get('github.auth_scope', 'public_repo') . '&client_id=' . $this->clientId . '&redirect_uri=' . urlencode($redirect); }
/** * 1. Request authorization on GitHub. * * @param string $client_id The client ID you received from GitHub when you registered. * @param string $redirect_uri URL in your app where users will be sent after authorization. * @param string $scope Comma separated list of scopes. * @param string $state An unguessable random string. It is used to protect against * cross-site request forgery attacks. * * @return string * * @since 1.0 */ public function getAuthorizationLink($client_id, $redirect_uri = '', $scope = '', $state = '') { $uri = new Uri('https://github.com/login/oauth/authorize'); $uri->setVar('client_id', $client_id); if ($redirect_uri) { $uri->setVar('redirect_uri', urlencode($redirect_uri)); } if ($scope) { $uri->setVar('scope', $scope); } if ($state) { $uri->setVar('state', $state); } return (string) $uri; }