/** * This actually signs the request. * It can be called multiple times (for different requests) on the same instance * of the client. * This method puts it in the oauth params in the Authorization header by default. * * @param Request $request Request to sign * @throws Exception */ public function sign(Request $request) { $this->request = $request; $oauth_params = $this->getOAuthParams(); $oauth_params['oauth_signature'] = $this->getSignature(); //put it where it needs to go in the request switch ($this->config['signature_location']) { case self::SIGN_LOCATION_HEADER: //Needs escaping in the header, not in the QS $oauth_params['oauth_signature'] = Helpers::escape($oauth_params['oauth_signature']); $header = 'OAuth ' . Helpers::flattenAssocArray($oauth_params, '%s="%s"', ', '); $request->setHeader(Request::HEADER_AUTHORIZATION, $header); break; case self::SIGN_LOCATION_QUERY: foreach ($oauth_params as $param_name => $param_value) { $request->setParameter($param_name, $param_value); } break; default: throw new Exception('Invalid signing location specified.'); } //Reset so this instance of the Client can sign subsequent requests. //Mainly for the nonce. $this->resetOAuthParams(); }
public function getPDF() { /** @var Object $this */ if ($this->hasGUID() === false) { throw new Exception('PDF files are only available to objects that exist remotely.'); } $uri = sprintf('%s/%s', $this::getResourceURI(), $this->getGUID()); $url = new URL($this->_application, $uri); $request = new Request($this->_application, $url, Request::METHOD_GET); $request->setHeader(Request::HEADER_ACCEPT, Request::CONTENT_TYPE_PDF); $request->send(); return $request->getResponse()->getResponseBody(); }
/** * @return array */ public function execute() { /** @var ObjectInterface $from_class */ $from_class = $this->from; $url = new URL($this->app, $from_class::getResourceURI()); $request = new Request($this->app, $url, Request::METHOD_GET); $where = $this->getWhere(); if (!empty($where)) { $request->setParameter('where', $where); } if ($this->order !== null) { $request->setParameter('order', $this->order); } if ($this->modifiedAfter !== null) { $request->setHeader('If-Modified-Since', $this->modifiedAfter); } if ($this->page !== null) { $request->setParameter('page', $this->page); } if ($this->offset !== null) { $request->setParameter('offset', $this->offset); } $request->send(); $elements = array(); foreach ($request->getResponse()->getElements() as $element) { /** @var Object $built_element */ $built_element = new $from_class($this->app); $built_element->fromStringArray($element); $elements[] = $built_element; } return $elements; }
private static function downloadContent(Application $app, $url) { $url = new URL($app, $url); $request = new Request($app, $url, Request::METHOD_GET); $request->setHeader(Request::HEADER_ACCEPT, '*/*'); $request->send(); return $request->getResponse()->getResponseBody(); }