Skip to content

Commit bcd4255

Browse files
Merge pull request #3 from JustSteveKing/2.0
2.0
2 parents c647cbe + 02e44d9 commit bcd4255

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1587
-1142
lines changed

.env.ci

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
COMPANIES_HOUSE_KEY=123456
2+
COMPANIES_HOUSE_URL="https://api.company-information.service.gov.uk"
3+
COMPANIES_HOUSE_TIMEOUT=10
4+
COMPANIES_HOUSE_RETRY_TIMES=
5+
COMPANIES_HOUSE_RETRY_MILLISECONDS=

.github/workflows/php-cs-fixer.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/run-tests.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-latest]
12-
php: [7.4]
13-
laravel: [7.*, 8.*]
12+
php: [8.0]
13+
laravel: [8.*]
1414
dependency-version: [prefer-stable]
1515
include:
1616
- laravel: 8.*
1717
testbench: 6.*
18-
- laravel: 7.*
19-
testbench: 5.*
2018

2119
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
2220

.php_cs.dist

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 156 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1+
# Laravel Companies House
2+
13
<p align="center">
24

35
![](./companies-house-laravel.png)
46

57
</p>
68

7-
# A Laravel wrapper to get companies house information and validate company numbers
8-
99
[![Latest Version on Packagist](https://img.shields.io/packagist/v/juststeveking/companies-house-laravel.svg?style=flat-square)](https://packagist.org/packages/juststeveking/companies-house-laravel)
1010
![Tests](https://github.com/juststeveking/companies-house-laravel/workflows/Tests/badge.svg?branch=master)
1111
[![Total Downloads](https://img.shields.io/packagist/dt/juststeveking/companies-house-laravel.svg?style=flat-square)](https://packagist.org/packages/juststeveking/companies-house-laravel)
1212

1313

14-
A Laravel wrapper to get companies house information and validate company numbers. This is a work in progress and more methods will be added to the API as they are required.
15-
16-
This has been tested thoroughly in Laravel 8, Laravel 7 is supported but if you find issues please do drop a detailed issue.
14+
A Laravel wrapper to get companies house information and validate company numbers.
1715

1816
## Installation
1917

@@ -25,7 +23,7 @@ composer require juststeveking/companies-house-laravel
2523

2624
You can publish the config file with:
2725
```bash
28-
php artisan vendor:publish --provider="JustSteveKing\CompaniesHouseLaravel\CompaniesHouseLaravelServiceProvider" --tag="config"
26+
php artisan vendor:publish --provider="JustSteveKing\CompaniesHouse\CompaniesHouseServiceProvider" --tag="config"
2927
```
3028

3129
This is the contents of the published config file:
@@ -34,86 +32,194 @@ This is the contents of the published config file:
3432
return [
3533
'api' => [
3634
'key' => env('COMPANIES_HOUSE_KEY', ''),
37-
'url' => env('COMPANIES_HOUSE_URL', 'https://api.companieshouse.gov.uk')
35+
'url' => env('COMPANIES_HOUSE_URL', 'https://api.company-information.service.gov.uk'),
36+
'timeout' => env('COMPANIES_HOUSE_TIMEOUT', 10),
37+
'retry' => [
38+
'times' => env('COMPANIES_HOUSE_RETRY_TIMES', null),
39+
'milliseconds' => env('COMPANIES_HOUSE_RETRY_MILLISECONDS', null),
40+
],
3841
]
3942
];
4043
```
4144

4245
## Usage
4346

44-
Using it inline:
47+
This library is aimed to be easy to use, and slots into Laravel with no issues.
4548

46-
```php
47-
use JustSteveKing\CompaniesHouseLaravel\Client;
49+
The package will install a Service Provider for you, meaning that all you need to do is resolve the `Client` from the container, and start using it.
4850

49-
// Make a new client
50-
$api = Client::make();
5151

52-
// Get Company information from a company number
53-
$company = $api->company('company-number');
54-
```
52+
### Get A Company Profile
5553

56-
Using the validation inline:
54+
To get a company profile, you can quite simply:
5755

5856
```php
59-
$this->validate($request, [
60-
'company_number' => [
61-
'required',
62-
'string',
63-
Rule::companyNumber()
64-
]
65-
]);
57+
use JustSteveKing\CompaniesHouse\Client;
58+
59+
class CompanyController extends Controler
60+
{
61+
public function __construct(
62+
protected Client $service,
63+
) {}
64+
65+
public function __invoke(Request $request)
66+
{
67+
$company = $this->service->company(
68+
companyNumber: $request->get('company_number')
69+
);
70+
}
71+
}
6672
```
6773

68-
Searching for a company by name, please note this will return an empty collection if there are no results:
74+
75+
## Get A Companies Officers
76+
77+
You can get a `Collection` of Company Officers using the companies number:
6978

7079
```php
71-
use JustSteveKing\CompaniesHouseLaravel\Client;
80+
use JustSteveKing\CompaniesHouse\Client;
81+
82+
class CompanyOfficersController extends Controler
83+
{
84+
public function __construct(
85+
protected Client $service,
86+
) {}
87+
88+
public function __invoke(Request $request)
89+
{
90+
$company = $this->service->officers(
91+
companyNumber: $request->get('company_number')
92+
);
93+
}
94+
}
95+
```
96+
7297

73-
$api = Client::make();
98+
### Get a specific Officer from a Company
7499

75-
// Get a collection of Company\SearchResult inside of a CompanyCollection
76-
$results = $api->searchCompany('Name you want to search');
100+
You can get an `Officer` from a company using the company number and their appointment ID:
77101

78-
// You now have access to all standard Laravel collection methods
79-
$results->each(function ($result) {
80-
// Do something with the result here.
81-
});
102+
```php
103+
use JustSteveKing\CompaniesHouse\Client;
104+
105+
class CompanyOfficerController extends Controler
106+
{
107+
public function __construct(
108+
protected Client $service,
109+
) {}
110+
111+
public function __invoke(Request $request)
112+
{
113+
$company = $this->service->officer(
114+
companyNumber: $request->get('company_number'),
115+
appointmentId: $request->get('appointment_id'),
116+
);
117+
}
118+
}
82119
```
83120

84-
Fetching a Collection of Company Officers will return an OfficerCollection:
85121

86-
```php
87-
use JustSteveKing\CompaniesHouseLaravel\Client;
122+
### Searching
123+
124+
There are a few options when it comes to searching, you can search for:
125+
126+
- companies
127+
- officers
128+
- disqualified officers
129+
- search all
130+
88131

89-
$api = Client::make();
132+
#### Searching for Companies
90133

91-
// Get a collection of Company\SearchResult inside of a CompanyCollection
92-
$results = $api->getOfficers('company-number');
134+
This will return a `SearchCollection`
93135

94-
// You now have access to all standard Laravel collection methods
95-
$results->each(function ($result) {
96-
// Do something with the result here.
97-
});
136+
```php
137+
use JustSteveKing\CompaniesHouse\Client;
138+
139+
class CompanySearchController extends Controler
140+
{
141+
public function __construct(
142+
protected Client $service,
143+
) {}
144+
145+
public function __invoke(Request $request)
146+
{
147+
$results = $this->service->searchCompany(
148+
query: $request->get('query'),
149+
perPage: 25, //optional
150+
startIndex: 0, //optional
151+
);
152+
}
153+
}
98154
```
99155

100156

101-
## Testing
157+
#### Searching for Officers
158+
159+
This will return a `SearchCollection`
160+
161+
```php
162+
use JustSteveKing\CompaniesHouse\Client;
163+
164+
class OfficersSearchController extends Controler
165+
{
166+
public function __construct(
167+
protected Client $service,
168+
) {}
169+
170+
public function __invoke(Request $request)
171+
{
172+
$results = $this->service->searchOfficers(
173+
query: $request->get('query'),
174+
perPage: 25, //optional
175+
startIndex: 0, //optional
176+
);
177+
}
178+
}
179+
```
102180

103-
### Using this library in your own tests
104181

105-
There is a relatively simple testing utility on this library, that allows you to fake the underlying Http client:
182+
#### Searching everything
183+
184+
This will return a `SearchCollection`
106185

107186
```php
108-
use Illuminate\Support\Facades\Http
109-
use JustSteveKing\CompaniesHouseLaravel\Client;
187+
use JustSteveKing\CompaniesHouse\Client;
188+
189+
class SearchController extends Controler
190+
{
191+
public function __construct(
192+
protected Client $service,
193+
) {}
194+
195+
public function __invoke(Request $request)
196+
{
197+
$results = $this->service->search(
198+
query: $request->get('query'),
199+
perPage: 25, //optional
200+
startIndex: 0, //optional
201+
);
202+
}
203+
}
204+
```
205+
206+
## Validation
207+
208+
Using the validation inline:
110209

111-
$fakedApi = Client::fake([
112-
'https://api.companieshouse.gov.uk/*',
113-
Http::response([], 200, [])
210+
```php
211+
$this->validate($request, [
212+
'company_number' => [
213+
'required',
214+
'string',
215+
Rule::companyNumber()
216+
]
114217
]);
115218
```
116219

220+
221+
## Testing
222+
117223
To understand how to use this part please follow the Laravel documentation for [Testing the Http Client](https://laravel.com/docs/8.x/http-client#testing)
118224

119225

0 commit comments

Comments
 (0)