Skip to content

Commit 577ea2e

Browse files
committed
feat: zoho addons endpoints introspection
1 parent 08364ec commit 577ea2e

4 files changed

Lines changed: 68 additions & 4 deletions

File tree

forms-bridge/addons/bigin/class-bigin-addon.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,38 @@ public function ping( $backend ) {
103103
return true;
104104
}
105105

106+
/**
107+
* Performs an introspection of the backend API and returns a list of available endpoints.
108+
*
109+
* @param string $backend Target backend name.
110+
* @param string|null $method HTTP method.
111+
*
112+
* @return array|WP_Error
113+
*/
114+
public function get_endpoints( $backend, $method = null ) {
115+
$bridge = new Bigin_Form_Bridge(
116+
array(
117+
'name' => '__bigin-' . time(),
118+
'endpoint' => '/bigin/v2/settings/modules',
119+
'method' => 'GET',
120+
'backend' => $backend,
121+
)
122+
);
123+
124+
$response = $bridge->submit();
125+
126+
if ( is_wp_error( $response ) ) {
127+
return array();
128+
}
129+
130+
return array_map(
131+
function ( $module ) {
132+
return '/bigin/v2/' . $module['api_name'];
133+
},
134+
$response['data']['modules'],
135+
);
136+
}
137+
106138
/**
107139
* Performs an introspection of the backend endpoint and returns API fields.
108140
*

forms-bridge/addons/bigin/hooks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ function ( $defaults, $addon, $schema ) {
4343
'ref' => '#credential',
4444
'name' => 'scope',
4545
'value' =>
46-
'ZohoBigin.modules.ALL,ZohoBigin.settings.layouts.READ,ZohoBigin.users.READ',
46+
'ZohoBigin.modules.ALL,ZohoBigin.settings.modules.READ,ZohoBigin.settings.layouts.READ,ZohoBigin.users.READ',
4747
),
4848
),
4949
'credential' => array(
5050
'scope' =>
51-
'ZohoBigin.modules.ALL,ZohoBigin.settings.layouts.READ,ZohoBigin.users.READ',
51+
'ZohoBigin.modules.ALL,ZohoBigin.settings.modules.READ,ZohoBigin.settings.layouts.READ,ZohoBigin.users.READ',
5252
),
5353
),
5454
$defaults,

forms-bridge/addons/zoho/class-zoho-addon.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,38 @@ public function ping( $backend ) {
102102
return true;
103103
}
104104

105+
/**
106+
* Performs an introspection of the backend API and returns a list of available endpoints.
107+
*
108+
* @param string $backend Target backend name.
109+
* @param string|null $method HTTP method.
110+
*
111+
* @return array|WP_Error
112+
*/
113+
public function get_endpoints( $backend, $method = null ) {
114+
$bridge = new Zoho_Form_Bridge(
115+
array(
116+
'name' => '__zoho-' . time(),
117+
'endpoint' => '/crm/v7/settings/modules',
118+
'method' => 'GET',
119+
'backend' => $backend,
120+
)
121+
);
122+
123+
$response = $bridge->submit();
124+
125+
if ( is_wp_error( $response ) ) {
126+
return array();
127+
}
128+
129+
return array_map(
130+
function ( $module ) {
131+
return '/crm/v7/' . $module['api_name'];
132+
},
133+
$response['data']['modules'],
134+
);
135+
}
136+
105137
/**
106138
* Performs an introspection of the backend endpoint and returns API fields.
107139
*

forms-bridge/addons/zoho/hooks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function ( $defaults, $addon, $schema ) {
107107
'name' => 'scope',
108108
'label' => __( 'Scope', 'forms-bridge' ),
109109
'type' => 'text',
110-
'value' => 'ZohoCRM.modules.ALL,ZohoCRM.settings.layouts.READ,ZohoCRM.users.READ',
110+
'value' => 'ZohoCRM.modules.ALL,ZohoCRM.settings.modules.READ,ZohoCRM.settings.layouts.READ,ZohoCRM.users.READ',
111111
'required' => true,
112112
),
113113
array(
@@ -174,7 +174,7 @@ function ( $defaults, $addon, $schema ) {
174174
'name' => '',
175175
'schema' => 'Bearer',
176176
'oauth_url' => 'https://accounts.{region}/oauth/v2',
177-
'scope' => 'ZohoCRM.modules.ALL,ZohoCRM.settings.layouts.READ,ZohoCRM.users.READ',
177+
'scope' => 'ZohoCRM.modules.ALL,ZohoCRM.settings.modules.READ,ZohoCRM.settings.layouts.READ,ZohoCRM.users.READ',
178178
'client_id' => '',
179179
'client_secret' => '',
180180
'access_token' => '',

0 commit comments

Comments
 (0)