diff --git a/README.md b/README.md index 49bbe4b..1db8596 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ BTW, Currently available (Successfully Scraped) 7. [CityLink Express](http://www.citylinkexpress.com/MY/Consignment.aspx) 8. [FedEx Express](https://www.fedex.com/my/) 9. [LEL Express](http://www.lex.com.my/) +10. [KTM Distribution Sdn Bhd](http://www.ktmd.com.my/tracking/) Tested in PHP 7.1 Only @@ -136,6 +137,11 @@ $data = parcel_track() Lazada E-Logistic Courier + + ktmd() + + KTM Distribution Sdn Bhd + setTrackingNumber($refNumber) String diff --git a/changelog.md b/changelog.md index 3db0c62..ca1edea 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## 1.10 +Add New Courier KTMD +- add KTM Distribution Sdn Bhd + ## 1.9 Add New Courier DHL E-Commerce - add dhl e-commerce @@ -28,7 +32,7 @@ Fix Carbon Time ## 1.7 Add LeLExpress courier -- Add lel lazada courier +- Add LEL Lazada courier - Fix ApiRequest - Fix Abx Request Body diff --git a/example/index.php b/example/index.php index 941e9d4..d1d309a 100644 --- a/example/index.php +++ b/example/index.php @@ -18,7 +18,8 @@ //$response = parcel_track()->lelExpress()->setTrackingNumber("MYMP000000573505")->fetch(); //$response = parcel_track()->postLaju()->setTrackingNumber("ER287051644MY")->fetch(); //$response = parcel_track()->lelExpress()->setTrackingNumber("MYMP000000573505")->fetch(); -$response = parcel_track()->dhlECommerce()->setTrackingNumber("5218031053514008AAAA")->fetch(); +//$response = parcel_track()->dhlECommerce()->setTrackingNumber("5218031053514008AAAA")->fetch(); +$response = parcel_track()->ktmd()->setTrackingNumber("103154269")->fetch(); //$response = parcel_track()->setTrackingNumber("EZP843055940197")->checkCourier(); diff --git a/src/Contract/BaseParcelTrack.php b/src/Contract/BaseParcelTrack.php index cd4bc2a..e79119b 100644 --- a/src/Contract/BaseParcelTrack.php +++ b/src/Contract/BaseParcelTrack.php @@ -15,6 +15,7 @@ use afiqiqmal\ParcelTrack\Tracker\DHLCommerce; use afiqiqmal\ParcelTrack\Tracker\FedEx; use afiqiqmal\ParcelTrack\Tracker\Gdex; +use afiqiqmal\ParcelTrack\Tracker\KTMD; use afiqiqmal\ParcelTrack\Tracker\LELExpress; use afiqiqmal\ParcelTrack\Tracker\PosLaju; use afiqiqmal\ParcelTrack\Tracker\SkyNet; @@ -80,6 +81,12 @@ public function lelExpress() return $this; } + public function ktmd() + { + $this->source = new KTMD(); + return $this; + } + protected function getWhichCourier() { $courier_matched = []; @@ -100,6 +107,7 @@ protected function getWhichCourier() $courier_matched[] = (new DHL())->getSourceName(); $courier_matched[] = (new FedEx())->getSourceName(); $courier_matched[] = (new SkyNet())->getSourceName(); + $courier_matched[] = (new KTMD())->getSourceName(); } if (strlen($this->trackingCode) >= 14) { diff --git a/src/Tracker/KTMD.php b/src/Tracker/KTMD.php new file mode 100644 index 0000000..b192ffc --- /dev/null +++ b/src/Tracker/KTMD.php @@ -0,0 +1,68 @@ + $refNum, + ]; + } + + public function getHeader() + { + return [ + 'Accept' => 'application/json' + ]; + } + + public function rawOutput() + { + return false; + } + + public function startCrawl($result) + { + $finalOutput = []; + if (isset($result['body'])) { + $output = $result['body']; + if ($output[0]['date'] == '-') { + return $this->buildResponse($result, []); + } + $output = array_reverse($output); + foreach ($output as $key => $item) { + $data = []; + $date = trim($item['date']); + $parcel = Carbon::createFromFormat("Y-m-d", $date); + + $data['date'] = $parcel->toDateTimeString(); + $data['timestamp'] = $parcel->timestamp; + $data['process'] = trim_spaces($item['description']); + $data['type'] = $this->distinguishProcess(trim_spaces($item['description']), $item == reset($output)); + $data['event'] = isset($item['location']) ? trim_spaces($item['location']) : null; + + $finalOutput[] = $data; + } + + return $this->buildResponse($result, $finalOutput, 200, false); + } + + return $this->buildResponse($result, []); + } +} \ No newline at end of file diff --git a/tests/KTMBTest.php b/tests/KTMBTest.php new file mode 100644 index 0000000..cfffc28 --- /dev/null +++ b/tests/KTMBTest.php @@ -0,0 +1,44 @@ +dhlExpress()->setTrackingNumber("103154269")->fetch(); + + $this->assertTrue(true); + $this->assertEquals(200, $result['code']); + } + + function testKTMBEmptySuccess() + { + $result = parcel_track()->dhlExpress()->setTrackingNumber("103154269AAAA")->fetch(); + + $this->assertTrue(count($result['tracker']['checkpoints']) == 0); + $this->assertEquals(200, $result['code']); + } + + function testKTMBFailed() + { + $result = parcel_track()->setTrackingNumber("103154269")->fetch(); + $this->assertTrue($result['error']); + $this->assertEquals(400, $result['code']); + } + + function testKTMBCheckCarrier() + { + $result = parcel_track()->setTrackingNumber("103154269")->checkCourier(); + $this->assertFalse($result['error']); + $this->assertTrue(in_array((new DHL())->getSourceName(), $result['possible_courier'])); + } +} \ No newline at end of file