Initial commit
This commit is contained in:
61
app/Services/RiksdagenService.php
Normal file
61
app/Services/RiksdagenService.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
class RiksdagenService
|
||||
{
|
||||
private Client $http;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->http = new Client([
|
||||
'base_uri' => 'https://data.riksdagen.se/',
|
||||
]);
|
||||
}
|
||||
|
||||
public function searchPerson(
|
||||
string $mp_id = '',
|
||||
string $firstName = '',
|
||||
string $lastName = '',
|
||||
string $party = ''
|
||||
): JsonResponse {
|
||||
$response = $this->http->get('personlista/', [
|
||||
'query' => [
|
||||
'iid' => $mp_id,
|
||||
'parti' => $party,
|
||||
'fnamn' => $firstName,
|
||||
'enamn' => $lastName,
|
||||
'utformat' => 'json',
|
||||
'sort' => 'sorteringsnamn',
|
||||
'sortorder' => 'asc'
|
||||
]
|
||||
])->getBody()->getContents();
|
||||
|
||||
$data = json_decode($response);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function searchVotes(
|
||||
string $mp_id = '',
|
||||
string $party = '',
|
||||
string $date = '',
|
||||
): JsonResponse {
|
||||
$response = $this->http->get('voteringlista/', [
|
||||
'query' => [
|
||||
'iid' => $mp_id,
|
||||
'rm' => $date,
|
||||
'parti' => $party,
|
||||
'utformat' => 'json',
|
||||
'sz' => '500',
|
||||
]
|
||||
])->getBody()->getContents();
|
||||
|
||||
$data = json_decode($response);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user