├── .gitignore ├── CHANGELOG.md ├── test.php ├── src ├── Exceptions │ ├── IsEmpty.php │ └── IsNull.php └── Mvrd.php ├── .travis.yml ├── composer.json ├── LICENSE.md ├── phpunit.xml.dist ├── CONTRIBUTING.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | build 3 | .DS_Store 4 | composer.lock 5 | index.php 6 | .env 7 | .env.example -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All Notable changes to `mvrd` will be documented in this file 4 | 5 | ## 2016-12-15 6 | - Initial release -------------------------------------------------------------------------------- /test.php: -------------------------------------------------------------------------------- 1 | getData()); -------------------------------------------------------------------------------- /src/Exceptions/IsEmpty.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Unicodeveloper\Mvrd\Exceptions; 13 | 14 | use Exception; 15 | 16 | class IsEmpty extends Exception 17 | { 18 | public static function create($message) 19 | { 20 | return new static("{$message}"); 21 | } 22 | } -------------------------------------------------------------------------------- /src/Exceptions/IsNull.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Unicodeveloper\Mvrd\Exceptions; 13 | 14 | use Exception; 15 | 16 | class IsNull extends Exception 17 | { 18 | public static function create($message) 19 | { 20 | return new static("{$message}"); 21 | } 22 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.6 5 | - 7.0 6 | - hhvm 7 | 8 | matrix: 9 | allow_failures: 10 | - php: hhvm 11 | 12 | install: travis_retry composer install --no-interaction --prefer-source 13 | 14 | script: 15 | - mkdir -p build/logs 16 | - php vendor/bin/phpunit -c phpunit.xml.dist 17 | - phpunit --coverage-text --coverage-clover=coverage.clover 18 | - phpunit --coverage-clover build/logs/clover.xml 19 | 20 | after_script: 21 | - wget https://scrutinizer-ci.com/ocular.phar 22 | - php ocular.phar code-coverage:upload --format=php-clover coverage.clover 23 | - travis_retry php vendor/bin/coveralls -v 24 | 25 | notifications: 26 | slack: red-creek:5lI8ybvl6YTcCNPosh4TE13h -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unicodeveloper/mvrd", 3 | "description": "Unofficial Motor Vehicle Registration Information Search Portal Library", 4 | "keywords": ["php","api","motor","nigeria", "vehicle information", "registration"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "unicodeveloper", 9 | "email": "prosperotemuyiwa@gmail.com" 10 | } 11 | ], 12 | "minimum-stability": "stable", 13 | "require": { 14 | "php" : "^5.4|^7.0", 15 | "guzzlehttp/guzzle": "5.*|6.*", 16 | "symfony/dom-crawler": "^3.2", 17 | "symfony/css-selector": "^2.8", 18 | "vlucas/phpdotenv": "^2.2" 19 | }, 20 | "require-dev": { 21 | "phpunit/phpunit" : "4.*", 22 | "scrutinizer/ocular": "~1.1", 23 | "satooshi/php-coveralls": "^0.7.0", 24 | "mockery/mockery": "^0.9.4" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "Unicodeveloper\\Mvrd\\": "src/" 29 | } 30 | }, 31 | "autoload-dev": { 32 | "psr-4": { 33 | "Unicodeveloper\\Mvrd\\Test\\": "tests" 34 | } 35 | }, 36 | "scripts": { 37 | "test": "vendor/bin/phpunit" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Prosper Otemuyiwa 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | tests 15 | 16 | 17 | 18 | 19 | src/ 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/unicodeveloper/jusibe-php-lib). 6 | 7 | 8 | ## Pull Requests 9 | 10 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 11 | 12 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 13 | 14 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 15 | 16 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 17 | 18 | - **Create feature branches** - Don't ask us to pull from your master branch. 19 | 20 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 21 | 22 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 23 | 24 | 25 | ## Running Tests 26 | 27 | ``` bash 28 | $ composer test 29 | ``` 30 | 31 | 32 | **Happy coding**! 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mvrd library - Grab all the Nigerian Vehicles Data!!! 2 | 3 | [![Latest Stable Version](https://poser.pugx.org/unicodeveloper/mvrd/v/stable.svg)](https://packagist.org/packages/unicodeveloper/jusibe-php-lib) 4 | [![License](https://poser.pugx.org/unicodeveloper/mvrd/license.svg)](LICENSE.md) 5 | ![](https://img.shields.io/badge/unicodeveloper-approved-brightgreen.svg) 6 | [![Build Status](https://img.shields.io/travis/unicodeveloper/jusibe-php-lib.svg)](https://travis-ci.org/unicodeveloper/jusibe-php-lib) 7 | [![Coveralls](https://img.shields.io/coveralls/unicodeveloper/jusibe-php-lib/master.svg)](https://coveralls.io/github/unicodeveloper/jusibe-php-lib?branch=master) 8 | [![Quality Score](https://img.shields.io/scrutinizer/g/unicodeveloper/jusibe-php-lib.svg?style=flat-square)](https://scrutinizer-ci.com/g/unicodeveloper/jusibe-php-lib) 9 | [![Total Downloads](https://img.shields.io/packagist/dt/unicodeveloper/mvrd.svg?style=flat-square)](https://packagist.org/packages/unicodeveloper/jusibe-php-lib) 10 | 11 | > Mvrd Library for PHP 12 | 13 | Head over to [lsmvaapvs.org](http://www.lsmvaapvs.org) and input a valid Nigerian Plate Number. Your result would be like so: 14 | 15 | ![Plate Number Result](https://cloud.githubusercontent.com/assets/2946769/21285119/1e414f42-c430-11e6-98a5-7c6af945f440.png) 16 | 17 | ## Installation 18 | 19 | [PHP](https://php.net) 5.4+ or [HHVM](http://hhvm.com) 3.3+, and [Composer](https://getcomposer.org) are required. 20 | 21 | To get the latest version of mvrd, simply add the following line to the require block of your `composer.json` file. 22 | 23 | ``` 24 | "unicodeveloper/mvrd": "1.0.*" 25 | ``` 26 | 27 | You'll then need to run `composer install` or `composer update` to download it and have the autoloader updated. 28 | 29 | 30 | ## Usage 31 | 32 | Available methods for use right now are: 33 | ```php 34 | 35 | /** 36 | * Get Vehicle Details 37 | * @param none 38 | * @return array 39 | */ 40 | $mvrd->getData(); 41 | ``` 42 | 43 | ### Grab the Vehicle Details 44 | 45 | ```php 46 | 47 | getData(); 58 | 59 | ``` 60 | 61 | **Response Info for Developer** 62 | 63 | ![Response](https://cloud.githubusercontent.com/assets/2946769/21230172/5e2a9d54-c2e4-11e6-9456-12b75ca39028.png) 64 | 65 | 66 | ### Grab specific Vehicle Detail 67 | 68 | ```php 69 | 70 | getData()['Color']; 81 | 82 | ``` 83 | Vehicle Information that can be acquired are; 84 | 85 | - PlateNumber 86 | - OwnerName 87 | - Color 88 | - Model 89 | - ChasisNumber 90 | - VehicleStatus 91 | - IssueDate 92 | - ExpiryDate 93 | 94 | *Please note that the array keys are case sensitive and can only be used as shown above.* 95 | 96 | **Response Info for Developer** 97 | 98 | ![mvrd](https://cloud.githubusercontent.com/assets/15154504/21583481/20df1ee6-d083-11e6-9734-a5edd7bd8bcd.PNG) 99 | 100 | 101 | ### Grab the Vehicle Details with Wrong or Invalid Plate Number 102 | 103 | ```php 104 | 105 | getData(); 116 | 117 | ``` 118 | 119 | **Response Info for Developer** 120 | 121 | ![Check SMS Credits Response](https://cloud.githubusercontent.com/assets/2946769/21229979/bc704824-c2e3-11e6-8562-ec15fa7e2cdb.png) 122 | 123 | ## Contributing 124 | 125 | Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities. 126 | 127 | ## How can I thank you? 128 | 129 | Why not star the github repo? I'd love the attention! Why not share the link for this repository on Twitter or HackerNews? Spread the word! 130 | 131 | Don't forget to [follow me on twitter](https://twitter.com/unicodeveloper)! 132 | 133 | Thanks! 134 | Prosper Otemuyiwa. 135 | 136 | ## License 137 | 138 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 139 | -------------------------------------------------------------------------------- /src/Mvrd.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Unicodeveloper\Mvrd; 13 | 14 | use GuzzleHttp\Client; 15 | use Symfony\Component\DomCrawler\Crawler; 16 | use Unicodeveloper\Mvrd\Exceptions\IsNull; 17 | use Unicodeveloper\Mvrd\Exceptions\IsEmpty; 18 | 19 | class Mvrd { 20 | 21 | /** 22 | * lsmvaapvs.org API Base Url 23 | */ 24 | const baseURL = 'http://www.lsmvaapvs.org'; 25 | 26 | /** 27 | * Response from requests made to lsmvaapvs.org 28 | * @var mixed 29 | */ 30 | protected $response; 31 | 32 | /** 33 | * Instance of Guzzle Client 34 | * @var object 35 | */ 36 | protected $client; 37 | 38 | /** 39 | * Constructor 40 | * @param $plateNumber string 41 | */ 42 | public function __construct($plateNumber = null) 43 | { 44 | if (is_null($plateNumber)) { 45 | throw IsNull::create("Please input a valid plate number, Oga!!!"); 46 | } 47 | 48 | $this->plateNumber = $plateNumber; 49 | $this->prepareRequest(); 50 | } 51 | 52 | /** 53 | * Instantiate Guzzle Client and prepare request for http operations 54 | * @return none 55 | */ 56 | private function prepareRequest() 57 | { 58 | $this->client = new Client(['base_uri' => self::baseURL]); 59 | } 60 | 61 | /** 62 | * Perform a GET request 63 | * @param string $relativeUrl 64 | * @return none 65 | */ 66 | private function performGetRequest($relativeUrl) 67 | { 68 | $this->response = $this->client->request('GET', $relativeUrl, []); 69 | } 70 | 71 | /** 72 | * Get Raw Data 73 | * @param none 74 | * @return array 75 | */ 76 | public function getData() 77 | { 78 | $this->performGetRequest('/search.php?vpn=' . $this->plateNumber); 79 | 80 | $html = (string) $this->response->getBody(); 81 | 82 | $crawler = new Crawler($html); 83 | $rawVehicleData = []; 84 | 85 | $nodeValues = $crawler->filter('table > tbody > tr')->each( function( $node, $i) { 86 | // Remove double spaces, and newline(s) 87 | $formData = trim(preg_replace('/\s+/', ' ', $node->text())); 88 | 89 | return $this->processData($formData); 90 | 91 | }); 92 | 93 | // Strip multi-dimensional data array into simple associative array. 94 | $vehicleData = []; 95 | foreach ($nodeValues as $index => $value) { 96 | foreach ($value as $key => $carData) { 97 | $vehicleData[$key] = $carData; 98 | } 99 | } 100 | 101 | return $vehicleData; 102 | } 103 | 104 | 105 | /** 106 | * Process vehicle data to make it possible to store them as key-value pairs in an array. 107 | * @param $data (string to be processed) 108 | * @return array 109 | */ 110 | public function processData($data) 111 | { 112 | // Prepare data to be stored as key=>value pairs 113 | $string = explode(' ', $data, 3); 114 | 115 | // Use the number of spaces in the string as a requisite to determine how to handle them. 116 | // e.g Color field(1 space) contains less spaces than Plate Number(2 spaces) e.t.c 117 | if (substr_count($data, ' ') > 1) { 118 | 119 | // Check if the string holds Vehicle Model data as this needs to be stored differently. 120 | $isModelPresent = ($string[0] == 'Model') ? true : false; 121 | 122 | if ($isModelPresent) { 123 | $rawVehicleData[$string[0]] = $string[1] .' '. $string[2]; 124 | }else{ 125 | /* An error on the host website (lsmvaapvs.org) sees 'Issue' misspelt as 'Isssue' 126 | we try to fix this by detecting that string and correcting it before handling the data. 127 | */ 128 | $string[0] = $string[0] == 'Isssue' ? 'Issue' : $string[0]; 129 | $rawVehicleData[$string[0].$string[1]] = $string[2]; 130 | } 131 | 132 | }else{ 133 | $rawVehicleData[$string[0]] = $string[1]; 134 | } 135 | 136 | return $rawVehicleData; 137 | } 138 | } 139 | 140 | --------------------------------------------------------------------------------