/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * Get the shipment status history. * * @param array $response * * @return Track */ protected function getTrack(array $response) { $track = new Track(); foreach ($response['tuStatus'][0]['history'] as $index => $historyItem) { $event = new Event(); $status = $this->resolveStatus($response, $index); $event->setStatus($status); $event->setLocation($this->getLocation($historyItem)); $event->setDescription($historyItem['evtDscr']); $event->setDate($this->getDate($historyItem)); $event->addAdditionalDetails('eventNumber', $response['tuStatus'][0]['progressBar']['evtNos'][$index]); $track->addEvent($event); if ($status == Track::STATUS_DELIVERED) { $track->setRecipient($this->getRecipient($response)); } if ($status == Track::STATUS_PICKUP) { $track->addAdditionalDetails('parcelShop', $this->getParcelShopDetails($response)); } } return $track->sortEvents(); }
/** @test */ public function it_sorts_the_events_by_date_in_descending_order() { $event1 = Event::fromArray(['date' => '2016-01-31 14:00:00']); $event2 = Event::fromArray(['date' => '2016-01-31 15:00:00']); $event3 = Event::fromArray(['date' => '2016-01-31 16:00:00']); $this->track->addEvent($event3); $this->track->addEvent($event1); $this->track->addEvent($event2); $this->assertSame($event3, $this->track->events()[0]); $this->assertSame($event1, $this->track->events()[1]); $this->assertSame($event2, $this->track->events()[2]); $this->track->sortEvents(); $this->assertSame($event3, $this->track->events()[0]); $this->assertSame($event2, $this->track->events()[1]); $this->assertSame($event1, $this->track->events()[2]); }