Skip to content

Commit b866520

Browse files
committed
Added support for getting datastructures and marked get codes as unsupported
1 parent 07486cf commit b866520

11 files changed

+5486
-25
lines changed

src/Sdmx/api/client/rest/DotStatClient.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Sdmx\api\entities\DataflowStructure;
1111
use Sdmx\api\entities\DsdIdentifier;
1212
use Sdmx\api\entities\PortableTimeSeries;
13+
use Sdmx\api\exceptions\UnsupportedOperationException;
1314
use Sdmx\api\parser\DataStructureParser;
1415

1516
class DotStatClient implements SdmxClient
@@ -86,19 +87,23 @@ public function getDataflow($dataflow, $agency, $version)
8687
*/
8788
public function getDataflowStructure(DsdIdentifier $dsd, $full = false)
8889
{
89-
// TODO: Implement getDataflowStructure() method.
90+
$url = $this->queryBuilder->getDsdQuery($dsd->getId(), $dsd->getAgency(), $dsd->getVersion(), $full);
91+
$response = $this->httpClient->get($url);
92+
$dataflowStructures = $this->dataStructureParser->parse($response);
93+
94+
return count($dataflowStructures) > 0 ? $dataflowStructures[0] : null;
9095
}
9196

9297
/**
9398
* Gets all the codes from this provider for a given codelist.
9499
* @param string $codelist
95100
* @param string $agency
96101
* @param string $version
97-
* @return string[]
102+
* @return \string[]
98103
*/
99104
public function getCodes($codelist, $agency, $version)
100105
{
101-
// TODO: Implement getCodes() method.
106+
throw new UnsupportedOperationException('This method is not supported by dot stat api\'s');
102107
}
103108

104109
/**

src/Sdmx/api/entities/DataflowStructure.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
*/
1111
class DataflowStructure
1212
{
13+
14+
const DEFAULT_MEASURE = 'OBS_VALUE';
15+
1316
/**
1417
* @var string $id
1518
*/
@@ -36,6 +39,11 @@ class DataflowStructure
3639
*/
3740
private $dimensions;
3841

42+
/**
43+
* @var string $measure
44+
*/
45+
private $measure = self::DEFAULT_MEASURE;
46+
3947
/**
4048
* DataflowStructure constructor.
4149
*/
@@ -204,10 +212,19 @@ function __toString()
204212
return $str;
205213
}
206214

207-
215+
/**
216+
* @return string
217+
*/
208218
public function getMeasure()
209219
{
210-
return 'OBS_VALUE';
220+
return $this->measure;
221+
}
222+
223+
/**
224+
* @param string $measure
225+
*/
226+
public function setMeasure($measure){
227+
$this->measure = $measure;
211228
}
212229

213230

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Sdmx\api\exceptions;
4+
5+
6+
class UnsupportedOperationException extends \RuntimeException
7+
{
8+
9+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Sdmx\api\parser\v20;
4+
5+
6+
use Sdmx\api\parser\CodelistParser;
7+
use SimpleXMLElement;
8+
9+
class V20CodelistParser implements CodelistParser
10+
{
11+
12+
/**
13+
* Parses codelist into a hash indexed by codelist name and containing an array of codes
14+
* @param SimpleXMLElement $data
15+
* @return string[]
16+
*/
17+
public function parseCodesFromNode(SimpleXMLElement $data)
18+
{
19+
$result = [];
20+
21+
$codes = $data->xpath('./*[name()="Code"]');
22+
23+
foreach ($codes as $code){
24+
$name = $code->xpath('./*[name()="Description"][@xml:lang="en"]');
25+
if(count($name) > 0){
26+
$result[(string) $code['value']] = (string)$name[0];
27+
}
28+
}
29+
30+
return $result;
31+
}
32+
33+
/**
34+
* Parses codelist into a hash indexed by codelist name and containing an array of codes
35+
* @param string $data
36+
* @return string[]
37+
*/
38+
public function parseCodes($data)
39+
{
40+
$xml = new SimpleXMLElement($data);
41+
return $this->parseCodesFromNode($xml->xpath('//message:CodeLists/*[name()="CodeList"]')[0]);
42+
}
43+
}

0 commit comments

Comments
 (0)