Пример #1
0
 /**
  * Creates a new Requestobject
  *
  * @param ConfigurationInterface $configuration The configurationobject
  *
  * @return \newznab\libraries\ApaiIO\Request\RequestInterface
  */
 public static function createRequest(ConfigurationInterface $configuration)
 {
     $class = $configuration->getRequest();
     $factoryCallback = $configuration->getRequestFactory();
     if (true === is_object($class) && $class instanceof RequestInterface) {
         $class->setConfiguration($configuration);
         return self::applyCallback($factoryCallback, $class);
     }
     if (true === is_string($class) && true === array_key_exists($class, self::$requestObjects)) {
         $request = self::$requestObjects[$class];
         $request->setConfiguration($configuration);
         return self::applyCallback($factoryCallback, $request);
     }
     try {
         $reflectionClass = new \ReflectionClass($class);
     } catch (\ReflectionException $e) {
         throw new \InvalidArgumentException(sprintf("Requestclass not found: %s", $class));
     }
     if ($reflectionClass->implementsInterface('\\newznab\\libraries\\ApaiIO\\Request\\RequestInterface')) {
         $request = new $class();
         $request->setConfiguration($configuration);
         return self::$requestObjects[$class] = self::applyCallback($factoryCallback, $request);
     }
     throw new \LogicException(sprintf("Requestclass does not implements the RequestInterface: %s", $class));
 }
Пример #2
0
 /**
  * Applies a responsetransformer
  *
  * @param mixed                  $response      The response of the request
  * @param ConfigurationInterface $configuration The configurationobject
  *
  * @return mixed
  */
 protected function applyResponseTransformer($response, ConfigurationInterface $configuration)
 {
     if (true === is_null($configuration->getResponseTransformer())) {
         return $response;
     }
     $responseTransformer = ResponseTransformerFactory::createResponseTransformer($configuration);
     return $responseTransformer->transform($response);
 }
Пример #3
0
 /**
  * Calculates the signature for the request
  *
  * @param array $params
  *
  * @return string
  */
 protected function buildSignature(array $params)
 {
     $template = "GET\nwebservices.amazon.%s\n/onca/xml\n%s";
     return Util::buildSignature(sprintf($template, $this->configuration->getCountry(), implode('&', $params)), $this->configuration->getSecretKey());
 }
Пример #4
0
 /**
  * Calculates the signature for the request
  *
  * @param string $request
  *
  * @return string
  */
 protected function buildSignature($request)
 {
     return Util::buildSignature($request, $this->configuration->getSecretKey());
 }