62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?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);
|
|
}
|
|
}
|