@@ -91,8 +91,6 @@ public function request($handle = null, array $config = array())
91
91
$ request = $ client ->createRequest ($ this ->config ['method ' ], $ this ->config ['url ' ]);
92
92
}
93
93
94
-
95
-
96
94
// Get a cached request
97
95
$ cachedRequest = craft ()->placid_cache ->get (base64_encode (urlencode ($ request ->getUrl ())));
98
96
$ caches = craft ()->placid_cache ->get (base64_encode (urlencode ($ request ->getUrl ())));
@@ -433,17 +431,40 @@ private function _getResponse(Client $client, $request)
433
431
}
434
432
}
435
433
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 == '' )
437
440
{
438
- craft ()-> placid_cache -> set ( $ request -> getUrl (), $ response -> json (), $ this -> config [ ' duration ' ]) ;
441
+ $ contentType = ' application/json ' ;
439
442
}
440
443
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
+ }
446
452
}
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
+
447
468
448
469
return $ output ;
449
470
}
0 commit comments