140 lines
3.5 KiB
PHP
140 lines
3.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' => '3000',
|
|
],
|
|
])->getBody()->getContents();
|
|
|
|
$data = json_decode($response);
|
|
|
|
return response()->json($data);
|
|
}
|
|
|
|
public function getPersonMotions(
|
|
string $mp_id,
|
|
string $date = '',
|
|
): JsonResponse {
|
|
$response = $this->http->get('dokumentlista/', [
|
|
'query' => [
|
|
'iid' => $mp_id,
|
|
'rm' => $date,
|
|
'doktyp' => 'mot',
|
|
'utformat' => 'json',
|
|
],
|
|
])->getBody()->getContents();
|
|
|
|
$data = json_decode($response);
|
|
|
|
return response()->json($data);
|
|
}
|
|
|
|
public function getPartyMotions(
|
|
string $party,
|
|
string $date = '',
|
|
|
|
): JsonResponse {
|
|
$response = $this->http->get('dokumentlista/', [
|
|
'query' => [
|
|
'parti' => $party,
|
|
'rm' => $date,
|
|
'doktyp' => 'mot',
|
|
'utformat' => 'json',
|
|
],
|
|
])->getBody()->getContents();
|
|
|
|
$data = json_decode($response);
|
|
|
|
return response()->json($data);
|
|
}
|
|
|
|
public function searchMotions(
|
|
string $query = '',
|
|
string $party = '',
|
|
string $dateInterval = '',
|
|
int $page = 1
|
|
): JsonResponse {
|
|
$response = $this->http->get('dokumentlista/', [
|
|
'query' => array_filter([
|
|
'sok' => $query,
|
|
'parti' => $party,
|
|
'rm' => $dateInterval,
|
|
'doktyp' => 'mot',
|
|
'utformat' => 'json',
|
|
'p' => $page,
|
|
]),
|
|
])->getBody()->getContents();
|
|
|
|
$data = json_decode($response);
|
|
|
|
return response()->json($data);
|
|
}
|
|
|
|
public function getMotion(
|
|
string $bet,
|
|
string $tempbet,
|
|
string $nr,
|
|
): JsonResponse {
|
|
$response = $this->http->get('dokumentlista/', [
|
|
'query' => [
|
|
'bet' => $bet,
|
|
'tempbet' => $tempbet,
|
|
'nr' => $nr,
|
|
'utformat' => 'json',
|
|
],
|
|
])->getBody()->getContents();
|
|
|
|
$data = json_decode($response);
|
|
|
|
return response()->json($data);
|
|
}
|
|
}
|