Ejemplo n.º 1
0
 /**
  * @param int $id
  * @return ShipmentInfoType
  */
 public function getManifest($id)
 {
     $response = $this->processRequest(['request_url' => '/manifest/' . $id, 'headers' => ['Accept: application/vnd.cpc.manifest-v' . self::API_VERSION . '+xml']]);
     $responseXML = new SimpleXMLElement($response);
     switch ($responseXML->getName()) {
         case 'manifest':
             $ManifestType = new ManifestType();
             $ManifestType->setPoNumber((string) $responseXML->{'po-number'});
             if ($responseXML->{'links'}->link) {
                 foreach ($responseXML->{'links'}->link as $link) {
                     $LinkType = new LinkType();
                     $LinkType->setHref((string) $link['href']);
                     $LinkType->setRel((string) $link['rel']);
                     $LinkType->setMediaType((string) $link['media-type']);
                     if (isset($link['index'])) {
                         $LinkType->setIndex((string) $link['index']);
                     }
                     $ManifestType->addLink($LinkType);
                 }
             }
             return $ManifestType;
             break;
         case 'messages':
             return WebService::getMessagesType($responseXML);
             break;
         default:
             return false;
             break;
     }
 }
Ejemplo n.º 2
0
 /**
  * @param $apiKey
  * @param $ssl
  * @return mixed
  */
 public function processLink($apiKey, $ssl = true)
 {
     $RequestProcessor = new RequestProcessor(['request_url' => $this->getHref(), 'headers' => ['Accept: ' . $this->getMediaType()], 'request' => null, 'api_key' => $apiKey, 'ssl' => $ssl]);
     $response = $RequestProcessor->process();
     switch ($this->getRel()) {
         case 'label':
             return self::processApplicationPdfResponse($response);
             break;
         case 'manifest':
             $responseXML = new \SimpleXMLElement($response);
             switch ($responseXML->getName()) {
                 case 'manifest':
                     $ManifestType = new ManifestType();
                     $ManifestType->setPoNumber((string) $responseXML->{'po-number'});
                     if ($responseXML->{'links'}->link) {
                         foreach ($responseXML->{'links'}->link as $link) {
                             $LinkType = new LinkType();
                             $LinkType->setHref((string) $link['href']);
                             $LinkType->setRel((string) $link['rel']);
                             $LinkType->setMediaType((string) $link['media-type']);
                             if (isset($link['index'])) {
                                 $LinkType->setIndex((string) $link['index']);
                             }
                             $ManifestType->addLink($LinkType);
                         }
                     }
                     return $ManifestType;
                     break;
                 case 'messages':
                     return WebService::getMessagesType($responseXML);
                     break;
                 default:
                     return false;
                     break;
             }
             break;
         case 'artifact':
             return self::processApplicationPdfResponse($response);
             break;
         default:
             return false;
             break;
     }
 }