public function __invoke(ResponseInterface $response)
 {
     \SellerCenter\SDK\Common\AnnotationRegistry::registerAutoloadNamespace();
     if (count($response->xml()->xpath('/ErrorResponse'))) {
         $serializer = SerializerBuilder::create()->build();
         return $serializer->deserialize($response->xml()->asXML(), 'SellerCenter\\SDK\\Common\\Api\\Response\\Error\\ErrorResponse', 'xml');
     }
     return;
 }
Esempio n. 2
0
 public function parse(Session $rets, ResponseInterface $response, $parameters)
 {
     $xml = $response->xml();
     $rs = new Results();
     $rs->setSession($rets)->setResource($parameters['SearchType'])->setClass($parameters['Class']);
     if ($this->getRestrictedIndicator($rets, $xml, $parameters)) {
         $rs->setRestrictedIndicator($this->getRestrictedIndicator($rets, $xml, $parameters));
     }
     $rs->setHeaders($this->getColumnNames($rets, $xml, $parameters));
     $rets->debug(count($rs->getHeaders()) . ' column headers/fields given');
     $this->parseRecords($rets, $xml, $parameters, $rs);
     if ($this->getTotalCount($rets, $xml, $parameters) !== null) {
         $rs->setTotalResultsCount($this->getTotalCount($rets, $xml, $parameters));
         $rets->debug($rs->getTotalResultsCount() . ' total results found');
     }
     $rets->debug($rs->getReturnedResultsCount() . ' results given');
     if ($this->foundMaxRows($rets, $xml, $parameters)) {
         // MAXROWS tag found.  the RETS server withheld records.
         // if the server supports Offset, more requests can be sent to page through results
         // until this tag isn't found anymore.
         $rs->setMaxRowsReached();
         $rets->debug('Maximum rows returned in response');
     }
     unset($xml);
     return $rs;
 }
Esempio n. 3
0
 public function parse(Session $rets, ResponseInterface $response)
 {
     $xml = $response->xml();
     $base = $xml->METADATA->{'METADATA-SYSTEM'};
     $metadata = new \PHRETS\Models\Metadata\System();
     $metadata->setSession($rets);
     $configuration = $rets->getConfiguration();
     if ($configuration->getRetsVersion()->is1_5()) {
         if (isset($base->System->SystemID)) {
             $metadata->setSystemId((string) $base->System->SystemID);
         }
         if (isset($base->System->SystemDescription)) {
             $metadata->setSystemDescription((string) $base->System->SystemDescription);
         }
     } else {
         if (isset($base->SYSTEM->attributes()->SystemID)) {
             $metadata->setSystemId((string) $base->SYSTEM->attributes()->SystemID);
         }
         if (isset($base->SYSTEM->attributes()->SystemDescription)) {
             $metadata->setSystemDescription((string) $base->SYSTEM->attributes()->SystemDescription);
         }
         if (isset($base->SYSTEM->attributes()->TimeZoneOffset)) {
             $metadata->setTimezoneOffset((string) $base->SYSTEM->attributes()->TimeZoneOffset);
         }
     }
     if (isset($base->SYSTEM->Comments)) {
         $metadata->setComments((string) $base->SYSTEM->Comments);
     }
     if (isset($base->attributes()->Version)) {
         $metadata->setVersion((string) $xml->METADATA->{'METADATA-SYSTEM'}->attributes()->Version);
     }
     return $metadata;
 }
Esempio n. 4
0
 /**
  * Sets attributes from response xml.
  *
  * @param ResponseInterface $response
  * @param array $attributes
  */
 public function __construct(ResponseInterface $response, array $attributes = null)
 {
     $this->response = $response;
     if (is_null($attributes)) {
         $attributes = Xml::elementsToArray($response->xml()->xpath('/RESPONSE/FIELDS/*'));
     }
     parent::__construct($attributes);
 }
Esempio n. 5
0
 public function __invoke(CommandInterface $command, ResponseInterface $response)
 {
     $output = $this->api->getOperation($command->getName())->getOutput();
     $xml = $response->xml();
     if ($this->honorResultWrapper && $output['resultWrapper']) {
         $xml = $xml->{$output['resultWrapper']};
     }
     return new Result($this->xmlParser->parse($output, $xml));
 }
Esempio n. 6
0
 public function isUserInSharedData($user)
 {
     $data = $this->response->xml()->data[0];
     foreach ($data as $element) {
         if ($element->share_with == $user) {
             return True;
         }
     }
     return False;
 }
 /**
  * Run request to Restoration Media
  */
 public function send()
 {
     $request = $this->client->createRequest('GET', $this->getBuiltUrl());
     $request->setHeader('User-Agent', 'github.com/caseyw/restorationmedia_php');
     $this->response = $this->client->send($request);
     /*
      * Restoration Media doesn't actually use HTTP Status Codes. I don't know why.
      */
     return 'success.' == $this->response->xml() ? true : false;
 }
 protected function getResponse(GuzzleResponse $response)
 {
     if (strpos($response->getHeader('Content-Type'), 'json')) {
         $returnResponse = new JsonResponse($response->getBody());
     } elseif (strpos($response->getHeader('Content-Type'), 'xml')) {
         $returnResponse = new XmlResponse($response->xml());
     } else {
         throw new \Exception('Unknow return type');
     }
     return $returnResponse;
 }
Esempio n. 9
0
 /**
  * Execute the command
  *
  * @param Command $command
  * @return bool
  */
 public function execute(Command $command)
 {
     $cookies = CookieJar::fromArray(['TokenKey' => $this->getToken()], $this->hostname);
     $client = $this->getClient();
     // Get the request method
     $method = $command->getMethod();
     // get the url
     $url = $command->getUrl($this->endpoint);
     // create the request object with the cookie
     $this->lastRequest = $client->createRequest($method, $url, $command->getPayload(['cookies' => $cookies]));
     $this->lastResponse = $client->send($this->lastRequest);
     $xml = $this->lastResponse->xml();
     return isset($xml->Success) && $xml->Success;
 }
Esempio n. 10
0
 public function getArrayOfShareesResponded(ResponseInterface $response, $shareeType)
 {
     $elements = $response->xml()->data;
     $elements = json_decode(json_encode($elements), 1);
     if (strpos($shareeType, 'exact ') === 0) {
         $elements = $elements['exact'];
         $shareeType = substr($shareeType, 6);
     }
     $sharees = [];
     foreach ($elements[$shareeType] as $element) {
         $sharees[] = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']];
     }
     return $sharees;
 }
Esempio n. 11
0
 public function parse(Session $rets, ResponseInterface $response)
 {
     $xml = $response->xml();
     $collection = new Collection();
     if ($xml->METADATA) {
         foreach ($xml->METADATA->{'METADATA-OBJECT'}->Object as $key => $value) {
             $metadata = new \PHRETS\Models\Metadata\Object();
             $metadata->setSession($rets);
             $obj = $this->loadFromXml($metadata, $value, $xml->METADATA->{'METADATA-OBJECT'});
             $collection->put($obj->getObjectType(), $obj);
         }
     }
     return $collection;
 }
Esempio n. 12
0
 public function parse(Session $rets, ResponseInterface $response, $keyed_by)
 {
     $xml = $response->xml();
     $collection = new Collection();
     if ($xml->METADATA) {
         foreach ($xml->METADATA->{'METADATA-TABLE'}->Field as $key => $value) {
             $metadata = new \PHRETS\Models\Metadata\Table();
             $metadata->setSession($rets);
             $this->loadFromXml($metadata, $value, $xml->METADATA->{'METADATA-TABLE'});
             $method = 'get' . $keyed_by;
             $collection->put((string) $metadata->{$method}(), $metadata);
         }
     }
     return $collection;
 }
Esempio n. 13
0
 public function parse(Session $rets, ResponseInterface $response)
 {
     $xml = $response->xml();
     $collection = new Collection();
     if ($xml->METADATA) {
         // some servers don't name this correctly for the version of RETS used, so play nice with either way
         if (!empty($xml->METADATA->{'METADATA-LOOKUP_TYPE'}->LookupType)) {
             $base = $xml->METADATA->{'METADATA-LOOKUP_TYPE'}->LookupType;
         } else {
             $base = $xml->METADATA->{'METADATA-LOOKUP_TYPE'}->Lookup;
         }
         foreach ($base as $key => $value) {
             $metadata = new \PHRETS\Models\Metadata\LookupType();
             $metadata->setSession($rets);
             $collection->push($this->loadFromXml($metadata, $value, $xml->METADATA->{'METADATA-LOOKUP_TYPE'}));
         }
     }
     return $collection;
 }
 /**
  * @param ResponseInterface $response
  * @param string            $deserialize
  *
  * @return mixed
  */
 protected function parse(ResponseInterface $response, $deserialize)
 {
     return $this->parser->parse($response->xml(), $deserialize);
 }
Esempio n. 15
0
 /**
  * @param string $call
  * @param ResponseInterface $rawResponse
  *
  * @return Response
  */
 protected function parseResponse($call, ResponseInterface $rawResponse)
 {
     $response = new Response();
     $responseArray = json_decode(json_encode($rawResponse->xml()), true);
     $response->setMethod($call);
     if (!array_key_exists('message', $responseArray)) {
         $response->setCode(999);
         $response->setMessage('Invalid response received.');
     } else {
         $response->setCode(intval($responseArray['message']['code']));
         $response->setMessage($responseArray['message']['text']);
     }
     if ($response->isSuccessful() && array_key_exists('response', $responseArray)) {
         $response->setData($responseArray['response']);
     }
     return $response;
 }
Esempio n. 16
0
 /**
  * Parse the XML response body and return a \SimpleXMLElement.
  *
  * @param mixed|\GuzzleHttp\Message\ResponseInterface $body
  * @param array $config
  * @return mixed
  */
 public function xml($body, array $config = [])
 {
     $xml = $body->xml($config);
     return $this->parseXml($xml);
 }
Esempio n. 17
0
 /**
  * Returns the response in the configured format.
  *
  * @param ResponseInterface $response
  * @param string            $format
  *
  * @return mixed $response
  */
 private function responseFormat($response, $format)
 {
     if ($format == 'json') {
         return $response->json();
     } elseif ($format == 'xml') {
         return $response->xml();
     }
     return $response;
 }
Esempio n. 18
0
 /**
  * @return \SimpleXMLElement
  */
 public function xml()
 {
     return $this->response->xml();
 }
Esempio n. 19
0
 /**
  * @param ResponseInterface $response
  * @throws RequestException
  */
 private function catchErrors(ResponseInterface $response)
 {
     $code = $response->getStatusCode();
     if ($code != 200) {
         throw new RequestException($code);
     }
     try {
         $xml = $response->xml();
     } catch (ParseException $e) {
         // Simply ignore. This is not a known error structure, so maybe not an error
     }
     if (isset($xml->err) && $xml->err == 1) {
         throw new RequestException(500, $xml->errmsg);
     }
 }
Esempio n. 20
0
 protected function payload(ResponseInterface $response, StructureShape $member, array &$result)
 {
     $result += $this->parser->parse($member, $response->xml());
 }
Esempio n. 21
0
 private function responseToArray(ResponseInterface $response)
 {
     $responseType = $response->getHeader('Content-Type');
     if (false === strpos($responseType, 'application/json') && false === strpos($responseType, 'application/xml')) {
         throw new InvalidResponseFormatException((string) $response->getBody(), $response->getStatusCode());
     }
     return strpos($responseType, 'application/json') !== false ? $response->json() : $response->xml();
 }
Esempio n. 22
0
 /**
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return object
  */
 protected function parseResponse(RequestInterface $request, ResponseInterface $response)
 {
     $this->response = $response;
     if ($request->getQuery()->get('check_if_alive') == '1') {
         $xml = $response->xml();
         return (object) array($xml->getName() => (string) $xml);
     }
     return $response->json();
 }
 /**
  * @param \GuzzleHttp\Message\ResponseInterface $response
  * @return mixed
  */
 private function getResponseContent($response)
 {
     switch ($response->getHeader('content-type')) {
         case 'application/json':
             return $response->json();
         case 'text/xml':
         case 'application/xml':
             return $response->xml();
         default:
             return $response->getBody();
     }
 }
Esempio n. 24
0
 /**
  * @param Response $response
  * @return ErrorResponseException
  */
 protected function createErrorResponseException(Response $response)
 {
     $xml = $response->xml();
     if ($xml->errors->Err1) {
         $message = (string) $xml->errors->Err1;
     } elseif ($xml->ErrString) {
         $message = (string) $xml->ErrString;
     } else {
         $message = 'Failed to execute ' . $xml->Command;
     }
     $exception = new ErrorResponseException($message);
     $exception->setResponse($response);
     return $exception;
 }
Esempio n. 25
0
 /**
  * Parses the xml answer to get ocs response which doesn't match with
  * http one in v1 of the api.
  * @param ResponseInterface $response
  * @return string
  */
 public function getOCSResponse($response)
 {
     return $response->xml()->meta[0]->statuscode;
 }
Esempio n. 26
0
 /**
  * Parses the xml answer to get the array of subadmins returned.
  * @param ResponseInterface $resp
  * @return array
  */
 public function getArrayOfSubadminsResponded($resp)
 {
     $listCheckedElements = $resp->xml()->data[0]->element;
     $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
     return $extractedElementsArray;
 }
Esempio n. 27
0
 public function before(GuzzleCommandInterface $command, ResponseInterface $response, Parameter $model, &$result, array $context = array())
 {
     $this->xml = $response->xml();
 }