/** * @param string $endpoint endpoint * @param array $parameters parameters */ protected function addOAuthParameters($endpoint, array &$parameters) { $accessToken = $this->metadata->getAccessToken(); $accessTokenSecret = $this->metadata->getAccessTokenSecret(); if (empty($accessToken) || empty($accessTokenSecret)) { throw new \LogicException('Cannot access this resource without oauth authentication.'); } $parameters['oauth_consumer_key'] = $this->metadata->getApiKey(); $parameters['oauth_timestamp'] = time(); $parameters['oauth_nonce'] = md5(uniqid(rand(), true)); $parameters['oauth_signature_method'] = "HMAC-SHA1"; $parameters['oauth_version'] = "1.0"; $parameters['oauth_token'] = $accessToken; $parameters['oauth_signature'] = $this->buildOAuthSignature($endpoint, $parameters); }
/** * @param string $service * @param array $parameters * @param string $endpoint * * @return array */ private function buildParams($service, array $parameters, &$endpoint) { if (null === $endpoint) { $endpoint = $this->metadata->getEndpoint(); } $default = array('api_key' => $this->metadata->getApiKey(), 'format' => 'rest'); if ($service) { $default['method'] = $service; } $parameters = array_merge($default, $parameters); $parameters = array_filter($parameters, function ($value) { return null !== $value; }); $parameters['api_sig'] = $this->buildSignature($parameters); $this->addOAuthParameters($endpoint, $parameters); return $parameters; }