Merge pull request #6251 from LevityNL/master
[civicrm-core.git] / api / v3 / CxnApp.php
index 89d3a4d0684124aec621792d3d893c324104c52c..2b811e408c15920a59e8adf06ec6f7f1bef67d41 100644 (file)
@@ -94,13 +94,18 @@ function _civicrm_api3_cxn_app_get_spec(&$spec) {
  * @throws \Civi\Cxn\Rpc\Exception\InvalidMessageException
  */
 function civicrm_api3_cxn_app_get($params) {
-  // FIXME: We should cache, but CRM_Utils_Cache and CRM_Core_BAO_Cache don't seem to support TTL...
-  list ($status, $blob) = CRM_Utils_HttpClient::singleton()->get(\Civi\Cxn\Rpc\Constants::OFFICIAL_APPMETAS_URL);
-  if (CRM_Utils_HttpClient::STATUS_OK != $status) {
+  // You should not change CIVICRM_CXN_APPS_URL in production; this is for local development.
+  $url = defined('CIVICRM_CXN_APPS_URL') ? CIVICRM_CXN_APPS_URL : \Civi\Cxn\Rpc\Constants::OFFICIAL_APPMETAS_URL;
+
+  list ($headers, $blob, $code) = CRM_Cxn_CiviCxnHttp::singleton()->send('GET', $url, '');
+  if ($code != 200) {
     throw new API_Exception("Failed to download application list.");
   }
-  $agent = new \Civi\Cxn\Rpc\Agent(CRM_Cxn_BAO_Cxn::getCACert(), NULL, NULL);
+
+  $agent = new \Civi\Cxn\Rpc\Agent(NULL, NULL);
+  $agent->setCertValidator(CRM_Cxn_BAO_Cxn::createCertificateValidator());
   $message = $agent->decode(array(AppMetasMessage::NAME, GarbledMessage::NAME), $blob);
+
   if ($message instanceof AppMetasMessage) {
     return _civicrm_api3_basic_array_get('CxnApp', $params, $message->getData(), 'appId',
       array('appId', 'appUrl', 'desc', 'appCert', 'perm'));