roelofr/postcodeapi

This package is abandoned and no longer maintained. No replacement package was suggested.

A simple service for Laravel that provides postal code validation via postcodeapi.nu

v0.2.2 2020-01-23 10:54 UTC

This package is auto-updated.

Last update: 2022-07-17 00:47:51 UTC


README

Build status Code Climate maintainability rating Code Climate coverage rating

PHP code style: PSR-12 License: Mozilla Public License v2

Easy access the postcodeapi.nu using a simple-to-use, well tested Laravel plugin.

License

Licensed under MIT.

Requirements

  • PHP 7.4+
  • Laravel 5.1 (Supports Statamic)

Installation

  1. Firstly, pull the addon off Packagist
    composer require roelofr/postcodeapi
    
  2. (Laravel <5.5) Add Service Provider to config/app.php
    'providers' => [
        // …
        Roelofr\PostcodeApi\ServiceProvider::class
    ]
  3. Publish the configuration
    php artian vendor:publish --provider=Roelofr\PostcodeApi\ServiceProvider
    
  4. You're good to go!

Usage

This plugin provides a contract (PostcodeApiContract) and a facade (PostcodeApi), use whichever you want.

The main route is the retrieve method, which expects a postcode and a number.

public function retrieve(string $postcode, string $number): AddressInformation;

The method will automatically try to clean the postcode and number to allow for API submission. After retireval an AddressInformation model is returned, or a NotFoundException is thrown.

Exceptions

  • A MalformedDataException, if we cannot find a Dutch post code and house number in the paramters.
  • A AuthenticationFailureException if your API key does not work.
  • A NotFoundException if the given postcode + number cannot be found.

Without Laravel

To get this plugin to work without Laravel is fairly tricky, as it requires a configuration and a cache according to Laravel's schematics.

If you want to rewrite parts of the code to work without Laravel, feel free to open a PR. It's somewhat out of scope though.