Giter Club home page Giter Club logo

laravel-postcodeapi's People

Contributors

arjanwestdorp avatar avido avatar barryvdh avatar bvweijen avatar dependabot-preview[bot] avatar koozza avatar lamalamamark avatar laravel-shift avatar nickurt avatar speedykhr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

laravel-postcodeapi's Issues

Laravel 5.2 support (Guzzle 6)

Your package currently does not work with Laravel 5.2 because it Laravel 5.2 uses Guzzle 6.* and your package requires 5.*

Unable to use provider

Hello,

I've gotten this problem when calling functions. When calling functions like this:

$address = \PostcodeApi::create('ApiPostcode')->findByPostcodeAndHouseNumber($request->code, $request->house);

I get the following error:
{message: "Unable to use the provider "ApiPostcode"",…}
exception: "nickurt\PostcodeApi\Exception\InvalidArgumentException"
file: "C:\wamp64\quartzline\vendor\nickurt\laravel-postcodeapi\src\ProviderFactory.php"
line: 18
message: "Unable to use the provider "ApiPostcode""
trace: [{file: "C:\wamp64\quartzline\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php",…},…].

Do you have any ideas to help me out?

Thanks in advance!

Caching responses

Hello,

Do you think it could be possible to have the responses cached for a specific period of time ? Maybe in a separate table or something, and have the API first check if the postcode is already cached and return the CACHED responses ?

This could save a few roundtrips to any API provider and also could limit the number of the API requests -- therefore reducing costs.

Allow aliasing providers

It'd be awesome to allow aliasing providers. This would make it super easy to use a sandbox that shares a class, but runs using a different endpoint and API key

For example, let's look at postcodeapi.nu, which has a live environment (v3) on https://api.postcodeapi.nu/v3/lookup and a sandbox under https://sandbox.postcodeapi.nu/v3/lookup

By allowing aliases, you could have this config:

<?php

return [
    'postcodeapi-nu' => [
        'alias' => \nickurt\PostcodeApi\Providers\nl_NL\PostcodeApiNu::class,
        'url' => 'https://api.postcodeapi.nu/v3/lookup/%s/%s',
        'key' => 'key',
    ],
    'postcodeapi-nu-sandbox' => [
        'alias' => \nickurt\PostcodeApi\Providers\nl_NL\PostcodeApiNu::class,
        'url' => 'https://sandbox.postcodeapi.nu/v3/lookup/%s/%s',
        'key' => 'sandbox',
    ],
];

You'd probably only have to make a small change, and include some tests.

         /** @var Provider $class */
-        if (class_exists($providerClass = 'nickurt\\PostcodeApi\\Providers\\' . $config['code'] . '\\' . $provider)) {
+        $providerClass = $config['alias'] ?? "nickurt\\PostcodeApi\\Providers\\{$config['code']}\\{$provider}")
+        if (class_exists($providerClass)) {
             $class = (new $providerClass);
             $class->setApiKey($config['key']);

Optimized autoloaders don't load some providers

Problem

When running in dev, I noticed no problems with the autoloading, but when switching composer to use --classmap-authoritative, some classes aren't available.

Possible causes

I think this has to do with incorrect namespace capitalisation, as seen here:

namespace nickurt\postcodeapi\Providers\en_AU;

Solutions

Fix the namespaces

Maybe run phpunit again after composer dump-autoload --classmap-authoritative, to check if all classes remain available.


I'll get to work on a PR, shouldn't be too long.

"Undefined offset: 0"

Laravel 5.5

When I make a call with the following address:

$address = PostcodeApi::create('PostcodeNL')->findByPostcodeAndHouseNumber($request->zipcode, $request->housenumber);

I get this error. Any ideas?


{message: "Undefined offset: 0", exception: "ErrorException",…}
exception: "ErrorException"
file: "C:\Projects\nspctr\vendor\guzzlehttp\guzzle\src\Client.php"
line: 348
message: "Undefined offset: 0"
[{file: "C:\Projects\nspctr\vendor\guzzlehttp\guzzle\src\Client.php", line: 348,…},…]

Be able to set the http client to be used (unit testing purposes)

Hi,

It doesn't seem to be possible to set the http client. I expected to do something like:

$guzzle = new GuzzleHttp\Client();
$postcodeapi = app('PostcodeApi');
$postcodeapi->setHttpClient($guzzle);

This way I can mock the responses for the PostcodeApi. Same as you did with the openprovider package for laravel.

Regards, Matthijs

Class not found....

Hello,

I'm using Laravel 5.8 and I have the following issue:

?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AddressController extends Controller
{

    public function byPostcodeAndHouseNumber(Request $request)
    {
        $postCode21 = PostcodeApi::create('PostcodeApiNu')->findByPostcodeAndHouseNumber('1118CP', '202');
        return response()->json([
            'data' => $postCode21
        ]);
    }
}

Results in the following error:

Symfony\Component\Debug\Exception\FatalThrowableError: Class &#039;App\Http\Controllers\PostcodeApi&#039; not found in file /app/Http/Controllers/AddressController.php on line 12
Stack trace:
  1. Symfony\Component\Debug\Exception\FatalThrowableError-&gt;() /app/Http/Controllers/AddressController.php:12

I like to know what I need to change

Thanks, Roy

Tag latest master

Hi,

Laravel autodiscover is not working with 1.1.
Could you tag master with a new version, so we can use Autodiscovery?

Thanks :)

Add house number addition to address from provider PostcodeApiNu

Issue

The nickurt\PostcodeApi\Entity\Address class that nickurt\postcodeapi\Providers\nl_NL\PostcodeApiNu returns does not contain the house number addition.

Reproduce

Execute the following function:

$provider = \PostcodeApi::create('PostcodeApiNu');
$provider->findByPostcodeAndHouseNumber('4817MK', '148EC6');

This will result in:

nickurt\PostcodeApi\Entity\Address {#1136
  #street: null
  #houseNo: null
  #town: null
  #municipality: null
  #province: null
  #latitude: null
  #longitude: null
}

The PostcodeApiNu API does include the house number addition as the addition field shown in the response from the PostcodeApiNu API:

...
{
 "_embedded": {
    "addresses": [{
			"purpose": "woonfunctie",
			"postcode": "4817MK",
			"addition": "C6",
			"number": 148,
			"year": 1980,
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.