Exemplo n.º 1
0
 /**
  * Get the shipment status history.
  *
  * @param DOMXPath $xpath
  *
  * @return Track
  * @throws \Exception
  */
 protected function getTrack(DOMXPath $xpath)
 {
     $rows = $xpath->query("//table[@class='dataTable']//tr");
     if (!$rows) {
         throw new \Exception("Unable to parse UPS tracking data for [{$this->parcelNumber}].");
     }
     $track = new Track();
     $lastLocation = '';
     foreach ($rows as $index => $row) {
         if ($index == 0) {
             continue;
             // skip the heading row
         }
         $eventData = $this->parseRow($row, $xpath);
         if (!empty($eventData['location'])) {
             $lastLocation = $eventData['location'];
         } else {
             $eventData['location'] = $lastLocation;
         }
         $event = Event::fromArray($eventData);
         $track->addEvent($event);
         if (array_key_exists('recipient', $eventData)) {
             $track->setRecipient($eventData['recipient']);
         }
     }
     return $track->sortEvents();
 }
Exemplo n.º 2
0
 /**
  * Get the shipment status history.
  *
  * @param DOMXPath $xpath
  *
  * @return Track
  * @throws \Exception
  */
 protected function getTrack(DOMXPath $xpath)
 {
     $rows = $xpath->query("//table[@id='tc-hits']//tbody//tr[contains(@class,'detail-wrapper')]");
     if (!$rows) {
         throw new \Exception("Unable to parse USPS tracking data for [{$this->parcelNumber}].");
     }
     $track = new Track();
     $lastLocation = '';
     $lastDate = '';
     foreach ($rows as $row) {
         $eventData = $this->parseRow($row);
         if (!empty($eventData['location'])) {
             $lastLocation = $eventData['location'];
         } else {
             $eventData['location'] = $lastLocation;
         }
         if (!empty($eventData['date'])) {
             $lastDate = $eventData['date'];
         } else {
             $eventData['date'] = $lastDate;
         }
         $track->addEvent(Event::fromArray($eventData));
     }
     return $track->sortEvents();
 }
Exemplo n.º 3
0
 /** @test */
 public function it_can_build_an_event_from_array()
 {
     $data = ['location' => 'some location', 'date' => Carbon::parse('2016-01-31'), 'description' => 'some description', 'status' => 'delivered'];
     $event = Event::fromArray($data);
     $this->assertInstanceOf(Event::class, $event);
     $this->assertSame('some location', $event->getLocation());
     $this->assertSame('2016-01-31', $event->getDate()->toDateString());
     $this->assertSame('some description', $event->getDescription());
     $this->assertSame('delivered', $event->getStatus());
 }
Exemplo n.º 4
0
 /**
  * @param int $count
  *
  * @return Event|Event[]
  */
 protected function getEvents($count = 1)
 {
     $eventData = ['location' => 'some location', 'date' => '2016-01-31', 'description' => 'some description', 'status' => 'delivered'];
     if ($count == 1) {
         return Event::fromArray($eventData);
     }
     $events = [];
     for ($x = 1; $x <= $count; $x++) {
         $events[] = Event::fromArray($eventData);
     }
     return $events;
 }
Exemplo n.º 5
0
 /**
  * Get the shipment status history.
  *
  * @param DOMXPath $xpath
  *
  * @return Track
  * @throws \Exception
  */
 protected function getTrack(DOMXPath $xpath)
 {
     $rows = $xpath->query("//div[@id='pieceEvents0']/div/div/div/table/tbody/tr");
     if (!$rows) {
         throw new \Exception("Unable to parse DHL tracking data for [{$this->parcelNumber}].");
     }
     $track = new Track();
     foreach ($rows as $row) {
         $eventData = $this->parseEvent($row, $xpath);
         $track->addEvent(Event::fromArray($eventData));
         if (array_key_exists('recipient', $eventData)) {
             $track->setRecipient($eventData['recipient']);
         }
     }
     return $track->sortEvents();
 }
Exemplo n.º 6
0
 /**
  * Get the shipment status history.
  *
  * @param DOMXPath $xpath
  *
  * @return Track
  * @throws \Exception
  */
 protected function getTrack(DOMXPath $xpath)
 {
     $rows = $xpath->query("//table[@class='events_view fullview_tabledata']//tbody//tr");
     if (!$rows) {
         throw new \Exception("Unable to parse Swiss Post tracking data for [{$this->parcelNumber}].");
     }
     $track = new Track();
     $lastLocation = '';
     foreach ($rows as $row) {
         $eventData = $this->parseRow($row);
         if (!empty($eventData['location'])) {
             $lastLocation = $eventData['location'];
         } else {
             $eventData['location'] = $lastLocation;
         }
         $event = Event::fromArray($eventData);
         $track->addEvent($event);
     }
     return $track->sortEvents();
 }