Skip to content

Commit

Permalink
feature: add basic MapIt class with postcode method
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Mar 6, 2024
1 parent 5275192 commit 6ad9af2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use C6Digital\MapIt\MapIt;

$mapIt = new MapIt(
key: 'your-mapit-key-here', // Your MapIt API key / token.
url: 'https://mapit.mysociety.org/' // An optional MapIt URL.
url: 'https://mapit.mysociety.org' // An optional MapIt URL.
);
```

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
}
],
"require": {
"php": "^8.2"
"php": "^8.2",
"illuminate/http": "^10.0"
},
"require-dev": {
"pestphp/pest": "^2.15",
Expand Down
25 changes: 25 additions & 0 deletions src/MapIt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace C6Digital\MapIt;

use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;

class MapIt
{
public function __construct(
protected string $key,
protected string $url = 'https://mapit.mysociety.org',
) {}

public function postcode(string $postcode): ?array
{
return $this->client()->get("/postcode/{$postcode}")->json();
}

protected function client(): PendingRequest
{
return Http::baseUrl($this->url)
->withQueryParameters(['api_key' => $this->key]);
}
}
7 changes: 0 additions & 7 deletions src/MapItClass.php

This file was deleted.

0 comments on commit 6ad9af2

Please sign in to comment.