Skip to content
This repository was archived by the owner on Dec 6, 2019. It is now read-only.

Commit f876776

Browse files
committed
Support for XML APIs
1 parent a97d973 commit f876776

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

placid/PlacidPlugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function getName()
1010
}
1111
function getVersion()
1212
{
13-
return '1.5.2';
13+
return '1.6.2';
1414
}
1515
function getDeveloper()
1616
{

placid/services/Placid_RequestsService.php

+30-9
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ public function request($handle = null, array $config = array())
9191
$request = $client->createRequest($this->config['method'], $this->config['url']);
9292
}
9393

94-
95-
9694
// Get a cached request
9795
$cachedRequest = craft()->placid_cache->get(base64_encode(urlencode($request->getUrl())));
9896
$caches = craft()->placid_cache->get(base64_encode(urlencode($request->getUrl())));
@@ -433,17 +431,40 @@ private function _getResponse(Client $client, $request)
433431
}
434432
}
435433

436-
if($this->config['cache'])
434+
$contentType = preg_match('/.+?(?=;)/', $response->getContentType(), $matches);
435+
436+
$contentType = implode($matches, '');
437+
438+
// If there is no content type then just cast to json because of reasons.
439+
if($contentType == '')
437440
{
438-
craft()->placid_cache->set($request->getUrl(), $response->json(), $this->config['duration']);
441+
$contentType = 'application/json';
439442
}
440443

441-
try {
442-
$output = $response->json();
443-
} catch (\RuntimeException $e) {
444-
Craft::log('Placid - ' - $e->getMessage(), LogLevel::Error);
445-
$output = null;
444+
if($contentType = 'text/xml')
445+
{
446+
try {
447+
$output = $response->xml();
448+
} catch (\Guzzle\Common\Exception\RuntimeException $e) {
449+
PlacidPlugin::log($e->getMessage(), LogLevel::Error);
450+
$output = null;
451+
}
446452
}
453+
else
454+
{
455+
try {
456+
$output = $response->json();
457+
} catch (\Guzzle\Common\Exception\RuntimeException $e) {
458+
PlacidPlugin::log($e->getMessage(), LogLevel::Error);
459+
$output = null;
460+
}
461+
}
462+
463+
if($this->config['cache'])
464+
{
465+
craft()->placid_cache->set($request->getUrl(), $output, $this->config['duration']);
466+
}
467+
447468

448469
return $output;
449470
}

0 commit comments

Comments
 (0)