Skip to content

Commit

Permalink
Merge branch 'feature/III-2068'
Browse files Browse the repository at this point in the history
* feature/III-2068:
  III-2068: Add method to get service consumer by api key
  III-2068: Parse apiKeySapi3 and searchPrefixSapi3 from Consumer XML
  • Loading branch information
Luc Wollants committed Nov 13, 2017
2 parents b3b743f + 8f73c44 commit 59b39a1
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 10 deletions.
44 changes: 34 additions & 10 deletions CultureFeed/CultureFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -1890,17 +1890,20 @@ public function updateServiceConsumer(CultureFeed_Consumer $consumer) {
*/
public function getServiceConsumer($consumerKey) {
$result = $this->oauth_client->consumerGetAsXML('serviceconsumer/' . $consumerKey);
return $this->parseServiceConsumerFromXmlString($result);
}

try {
$xml = new CultureFeed_SimpleXMLElement($result);
}
catch (Exception $e) {
throw new CultureFeed_ParseException($result);
}

$element = $xml->xpath('/consumer');

return $this->parseServiceConsumer($element[0]);
/**
* Get An existing service consumer by api key.
*
* @param string $apiKey
* @return \CultureFeed_Consumer
* @throws \CultureFeed_ParseException
*/
public function getServiceConsumerByApiKey($apiKey)
{
$result = $this->oauth_client->consumerGetAsXML('serviceconsumer/apikey/' . $apiKey);
return $this->parseServiceConsumerFromXmlString($result);
}

/**
Expand Down Expand Up @@ -1966,6 +1969,25 @@ public function getClient() {
return $this->oauth_client;
}

/**
* @param string $xml
* @return CultureFeed_Consumer
* @throws CultureFeed_ParseException
*/
protected function parseServiceConsumerFromXmlString($xml)
{
try {
$xml = new CultureFeed_SimpleXMLElement($xml);
}
catch (Exception $e) {
throw new CultureFeed_ParseException($xml);
}

$element = $xml->xpath('/consumer');

return $this->parseServiceConsumer($element[0]);
}

/**
* Initializes a CultureFeed_Consumer object from its XML representation.
*
Expand All @@ -1987,6 +2009,8 @@ protected function parseServiceConsumer(CultureFeed_SimpleXMLElement $element) {
$consumer->name = $element->xpath_str('name');
$consumer->status = $element->xpath_str('status');
$consumer->group = $element->xpath_int('group', true);
$consumer->apiKeySapi3 = $element->xpath_str('apiKeySapi3');
$consumer->searchPrefixSapi3 = $element->xpath_str('searchPrefixSapi3');

return $consumer;
}
Expand Down
10 changes: 10 additions & 0 deletions CultureFeed/CultureFeed/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ class CultureFeed_Consumer {
*/
public $destinationAfterEmailVerification;

/**
* @var string|null
*/
public $apiKeySapi3;

/**
* @var string|null
*/
public $searchPrefixSapi3;

/**
* Extract an array useable as data in POST requests that expect consumer info.
*
Expand Down
4 changes: 4 additions & 0 deletions CultureFeed/CultureFeed/ICultureFeedDecoratorBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public function getServiceConsumer($consumerKey) {
return $this->realCultureFeed->getServiceConsumer($consumerKey);
}

public function getServiceConsumerByApiKey($apiKey) {
return $this->realCultureFeed->getServiceConsumerByApiKey($apiKey);
}

public function getServiceConsumers($start = 0, $max = null)
{
return $this->realCultureFeed->getServiceConsumers($start, $max);
Expand Down
2 changes: 2 additions & 0 deletions CultureFeed/ICultureFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public function updateServiceConsumer(CultureFeed_Consumer $consumer);

public function getServiceConsumer($consumerKey);

public function getServiceConsumerByApiKey($apiKey);

/**
* @return CultureFeed_Uitpas
*/
Expand Down
119 changes: 119 additions & 0 deletions CultureFeed/test/CultureFeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,125 @@ public function setUp() {
$this->cultureFeed = new CultureFeed($this->oauthClient);
}

/**
* @dataProvider getConsumerMethodDataProvider
*
* @param string $method
* @param string $identifier
* @param string $expectedPath
*/
public function testGetConsumerWithoutSapi3Properties(
$method,
$identifier,
$expectedPath
) {
$xml = file_get_contents(__DIR__ . '/data/consumer_without_sapi3_properties.xml');

$this->oauthClient->expects($this->once())
->method('consumerGetAsXml')
->with($expectedPath)
->willReturn($xml);

$consumer = $this->cultureFeed->{$method}($identifier);

$this->assertNull($consumer->apiKeySapi3);
$this->assertNull($consumer->searchPrefixSapi3);
}

/**
* @dataProvider getConsumerMethodDataProvider
*
* @param string $method
* @param string $identifier
* @param string $expectedPath
*/
public function testGetConsumerWithEmptySapi3Properties(
$method,
$identifier,
$expectedPath
) {
$xml = file_get_contents(__DIR__ . '/data/consumer_with_empty_sapi3_properties.xml');

$this->oauthClient->expects($this->once())
->method('consumerGetAsXml')
->with($expectedPath)
->willReturn($xml);

$consumer = $this->cultureFeed->{$method}($identifier);

$this->assertEquals('', $consumer->apiKeySapi3);
$this->assertEquals('', $consumer->searchPrefixSapi3);
}

/**
* @dataProvider getConsumerMethodDataProvider
*
* @param string $method
* @param string $identifier
* @param string $expectedPath
*/
public function testGetConsumerWithApiKeySapi3(
$method,
$identifier,
$expectedPath
) {
$xml = file_get_contents(__DIR__ . '/data/consumer_with_api_key_sapi3.xml');

$this->oauthClient->expects($this->once())
->method('consumerGetAsXml')
->with($expectedPath)
->willReturn($xml);

$consumer = $this->cultureFeed->{$method}($identifier);

$this->assertEquals('c2436351-f314-4b83-916d-2e0a37502358', $consumer->apiKeySapi3);
$this->assertEquals('', $consumer->searchPrefixSapi3);
}

/**
* @dataProvider getConsumerMethodDataProvider
*
* @param string $method
* @param string $identifier
* @param string $expectedPath
*/
public function testGetConsumerWithSearchPrefixSapi3(
$method,
$identifier,
$expectedPath
) {
$xml = file_get_contents(__DIR__ . '/data/consumer_with_search_prefix_sapi3.xml');

$this->oauthClient->expects($this->once())
->method('consumerGetAsXml')
->with($expectedPath)
->willReturn($xml);

$consumer = $this->cultureFeed->{$method}($identifier);

$this->assertEquals('c2436351-f314-4b83-916d-2e0a37502358', $consumer->apiKeySapi3);
$this->assertEquals('labels:foo AND regions:gem-leuven', $consumer->searchPrefixSapi3);
}

/**
* @return array
*/
public function getConsumerMethodDataProvider()
{
return [
[
'method' => 'getServiceConsumer',
'identifier' => '5720d908-03cf-46da-8f5a-c43db621df5c',
'expectedPath' => 'serviceconsumer/5720d908-03cf-46da-8f5a-c43db621df5c',
],
[
'method' => 'getServiceConsumerByApiKey',
'identifier' => 'c2436351-f314-4b83-916d-2e0a37502358',
'expectedPath' => 'serviceconsumer/apikey/c2436351-f314-4b83-916d-2e0a37502358',
],
];
}

/**
* Test the handling of a succesfull user light call.
*/
Expand Down
49 changes: 49 additions & 0 deletions CultureFeed/test/data/consumer_with_api_key_sapi3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<consumer xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:cdb="http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.1/FINAL">
<callback>http://www.uitdatabank.be/2/Home/Callback</callback>
<consumerKey>5720d908-03cf-46da-8f5a-c43db621df5c</consumerKey>
<consumerSecret>c1913bcb-7557-4267-aae2-25161403dcce</consumerSecret>
<description>UiTDatabank</description>
<creationDate>1970-01-01T00:00Z</creationDate>
<id>776</id>
<name>UiTDatabank</name>
<organization>www.uitdatabank.be</organization>
<status>ACTIVE</status>
<activityTypesUsedForMailingUpdates>TYPE_CONNECT_CHANNEL</activityTypesUsedForMailingUpdates>
<apiKeySapi3>c2436351-f314-4b83-916d-2e0a37502358</apiKeySapi3>
<channelSpecificCategoryId/>
<channelSpecificKeyword/>
<destinationAfterEmailVerification>http://www.uitdatabank.be/2/Home/About</destinationAfterEmailVerification>
<groups>
<group>
<id>744</id>
<name>UiTDatabank groep</name>
</group>
<group>
<id>22074</id>
<name>Auth API</name>
</group>
</groups>
<logo>//media.uitid.be/fis/download/ce126667652776f0e9e55160f12f5478/74d005ad-5bee-4dc9-af96-3830fed3b3b7/2014-03-13_112451.jpg</logo>
<domain>www.uitdatabank.be</domain>
<permissions>
<permission>gebruikers aanmaken</permission>
<permission>gebruikers aanpassen</permission>
<permission>gebruikers ophalen</permission>
<permission>gebruikers zoeken met privé email adres</permission>
<permission>bijkomende gegevens bij opzoeken van gebruikers</permission>
<permission>activiteiten aanmaken</permission>
<permission>authorisatie overslaan</permission>
<permission>confirmatie overslaan</permission>
<permission>de AUTH API gebruiken</permission>
<permission>events aanmaken</permission>
<permission>events aanpassen</permission>
<permission>verdeelsleutels ophalen</permission>
<permission>verdeelsleutels toekennen aan inrichter</permission>
<permission>balies aanmaken</permission>
<permission>balies aanpassen</permission>
</permissions>
<searchPrefix/>
<searchPrefixFilterQuery/>
<searchPrefixSapi3/>
<uitdatabankUrlTemplate/>
</consumer>
49 changes: 49 additions & 0 deletions CultureFeed/test/data/consumer_with_empty_sapi3_properties.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<consumer xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:cdb="http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.1/FINAL">
<callback>http://www.uitdatabank.be/2/Home/Callback</callback>
<consumerKey>5720d908-03cf-46da-8f5a-c43db621df5c</consumerKey>
<consumerSecret>c1913bcb-7557-4267-aae2-25161403dcce</consumerSecret>
<description>UiTDatabank</description>
<creationDate>1970-01-01T00:00Z</creationDate>
<id>776</id>
<name>UiTDatabank</name>
<organization>www.uitdatabank.be</organization>
<status>ACTIVE</status>
<activityTypesUsedForMailingUpdates>TYPE_CONNECT_CHANNEL</activityTypesUsedForMailingUpdates>
<apiKeySapi3/>
<channelSpecificCategoryId/>
<channelSpecificKeyword/>
<destinationAfterEmailVerification>http://www.uitdatabank.be/2/Home/About</destinationAfterEmailVerification>
<groups>
<group>
<id>744</id>
<name>UiTDatabank groep</name>
</group>
<group>
<id>22074</id>
<name>Auth API</name>
</group>
</groups>
<logo>//media.uitid.be/fis/download/ce126667652776f0e9e55160f12f5478/74d005ad-5bee-4dc9-af96-3830fed3b3b7/2014-03-13_112451.jpg</logo>
<domain>www.uitdatabank.be</domain>
<permissions>
<permission>gebruikers aanmaken</permission>
<permission>gebruikers aanpassen</permission>
<permission>gebruikers ophalen</permission>
<permission>gebruikers zoeken met privé email adres</permission>
<permission>bijkomende gegevens bij opzoeken van gebruikers</permission>
<permission>activiteiten aanmaken</permission>
<permission>authorisatie overslaan</permission>
<permission>confirmatie overslaan</permission>
<permission>de AUTH API gebruiken</permission>
<permission>events aanmaken</permission>
<permission>events aanpassen</permission>
<permission>verdeelsleutels ophalen</permission>
<permission>verdeelsleutels toekennen aan inrichter</permission>
<permission>balies aanmaken</permission>
<permission>balies aanpassen</permission>
</permissions>
<searchPrefix/>
<searchPrefixFilterQuery/>
<searchPrefixSapi3/>
<uitdatabankUrlTemplate/>
</consumer>
49 changes: 49 additions & 0 deletions CultureFeed/test/data/consumer_with_search_prefix_sapi3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<consumer xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:cdb="http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.1/FINAL">
<callback>http://www.uitdatabank.be/2/Home/Callback</callback>
<consumerKey>5720d908-03cf-46da-8f5a-c43db621df5c</consumerKey>
<consumerSecret>c1913bcb-7557-4267-aae2-25161403dcce</consumerSecret>
<description>UiTDatabank</description>
<creationDate>1970-01-01T00:00Z</creationDate>
<id>776</id>
<name>UiTDatabank</name>
<organization>www.uitdatabank.be</organization>
<status>ACTIVE</status>
<activityTypesUsedForMailingUpdates>TYPE_CONNECT_CHANNEL</activityTypesUsedForMailingUpdates>
<apiKeySapi3>c2436351-f314-4b83-916d-2e0a37502358</apiKeySapi3>
<channelSpecificCategoryId/>
<channelSpecificKeyword/>
<destinationAfterEmailVerification>http://www.uitdatabank.be/2/Home/About</destinationAfterEmailVerification>
<groups>
<group>
<id>744</id>
<name>UiTDatabank groep</name>
</group>
<group>
<id>22074</id>
<name>Auth API</name>
</group>
</groups>
<logo>//media.uitid.be/fis/download/ce126667652776f0e9e55160f12f5478/74d005ad-5bee-4dc9-af96-3830fed3b3b7/2014-03-13_112451.jpg</logo>
<domain>www.uitdatabank.be</domain>
<permissions>
<permission>gebruikers aanmaken</permission>
<permission>gebruikers aanpassen</permission>
<permission>gebruikers ophalen</permission>
<permission>gebruikers zoeken met privé email adres</permission>
<permission>bijkomende gegevens bij opzoeken van gebruikers</permission>
<permission>activiteiten aanmaken</permission>
<permission>authorisatie overslaan</permission>
<permission>confirmatie overslaan</permission>
<permission>de AUTH API gebruiken</permission>
<permission>events aanmaken</permission>
<permission>events aanpassen</permission>
<permission>verdeelsleutels ophalen</permission>
<permission>verdeelsleutels toekennen aan inrichter</permission>
<permission>balies aanmaken</permission>
<permission>balies aanpassen</permission>
</permissions>
<searchPrefix/>
<searchPrefixFilterQuery/>
<searchPrefixSapi3>labels:foo AND regions:gem-leuven</searchPrefixSapi3>
<uitdatabankUrlTemplate/>
</consumer>
Loading

0 comments on commit 59b39a1

Please sign in to comment.