3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 use \Civi\Cxn\Rpc\Message\AppMetasMessage
;
29 use \Civi\Cxn\Rpc\Message\GarbledMessage
;
32 * The CxnApp API provides a pseudo-entity for exploring the list
33 * of published applications. It is a read-only API which
34 * downloads and validates the application list from civicrm.org.
36 * At time of writing, this API only supports simple filtering on
37 * equality. If you'd like more advanced filters, consider updating
38 * _civicrm_api3_basic_array_get() and api_v3_UtilsTest::testBasicArrayGet.
40 * NOTE: SyntaxConformanceTest is disabled for CxnApp. As a rough
41 * equivalent, see api_v3_UtilsTest::testBasicArrayGet.
45 * Adjust metadata for "register" action.
50 function _civicrm_api3_cxn_app_get_spec(&$spec) {
51 $spec['appCert'] = array(
53 'type' => CRM_Utils_Type
::T_TEXT
,
54 'title' => ts('Certificate'),
55 'description' => 'PEM-encoded certificate',
57 $spec['appId'] = array(
59 'type' => CRM_Utils_Type
::T_STRING
,
60 'title' => ts('Application GUID'),
61 'description' => 'Application GUID',
63 'size' => CRM_Utils_Type
::HUGE
,
65 $spec['appUrl'] = array(
67 'type' => CRM_Utils_Type
::T_STRING
,
68 'title' => ts('Registration URL'),
69 'description' => 'An endpoint to notify when performing registration',
71 'size' => CRM_Utils_Type
::HUGE
,
73 $spec['desc'] = array(
75 'type' => CRM_Utils_Type
::T_TEXT
,
76 'title' => ts('Description'),
77 'description' => 'Description',
79 //$spec['perm'] = array(
81 // 'type' => CRM_Utils_Type::T_TEXT,
82 // 'title' => ts('Permissions'),
83 // 'description' => 'Permissions expected for the service (struct)',
88 * Get a list of applications available for connections.
90 * @param array $params
92 * @throws API_Exception
93 * @throws CRM_Core_Exception
94 * @throws \Civi\Cxn\Rpc\Exception\InvalidMessageException
96 function civicrm_api3_cxn_app_get($params) {
97 // You should not change CIVICRM_CXN_APPS_URL in production; this is for local development.
98 $url = defined('CIVICRM_CXN_APPS_URL') ? CIVICRM_CXN_APPS_URL
: \Civi\Cxn\Rpc\Constants
::OFFICIAL_APPMETAS_URL
;
100 list ($headers, $blob, $code) = CRM_Cxn_CiviCxnHttp
::singleton()->send('GET', $url, '');
102 throw new API_Exception("Failed to download application list.");
105 $agent = new \Civi\Cxn\Rpc\
Agent(NULL, NULL);
106 $agent->setCertValidator(CRM_Cxn_BAO_Cxn
::createCertificateValidator());
107 $message = $agent->decode(array(AppMetasMessage
::NAME
, GarbledMessage
::NAME
), $blob);
109 if ($message instanceof AppMetasMessage
) {
110 return _civicrm_api3_basic_array_get('CxnApp', $params, $message->getData(), 'appId',
111 array('appId', 'appUrl', 'desc', 'appCert', 'perm'));
113 elseif ($message instanceof GarbledMessage
) {
114 return civicrm_api3_create_error('Received garbled response', array(
115 'garbled_message' => $message->getData(),
119 return civicrm_api3_create_error("Unrecognized message");