Skip to content
Merged
32 changes: 32 additions & 0 deletions forms-bridge/addons/bigin/class-bigin-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,38 @@ public function ping( $backend ) {
return true;
}

/**
* Performs an introspection of the backend API and returns a list of available endpoints.
*
* @param string $backend Target backend name.
* @param string|null $method HTTP method.
*
* @return array|WP_Error
*/
public function get_endpoints( $backend, $method = null ) {
$bridge = new Bigin_Form_Bridge(
array(
'name' => '__bigin-' . time(),
'endpoint' => '/bigin/v2/settings/modules',
'method' => 'GET',
'backend' => $backend,
)
);

$response = $bridge->submit();

if ( is_wp_error( $response ) ) {
return array();
}

return array_map(
function ( $module ) {
return '/bigin/v2/' . $module['api_name'];
},
$response['data']['modules'],
);
}

/**
* Performs an introspection of the backend endpoint and returns API fields.
*
Expand Down
4 changes: 2 additions & 2 deletions forms-bridge/addons/bigin/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function ( $defaults, $addon, $schema ) {
'ref' => '#credential',
'name' => 'scope',
'value' =>
'ZohoBigin.modules.ALL,ZohoBigin.settings.layouts.READ,ZohoBigin.users.READ',
'ZohoBigin.modules.ALL,ZohoBigin.settings.modules.READ,ZohoBigin.settings.layouts.READ,ZohoBigin.users.READ',
),
),
'credential' => array(
'scope' =>
'ZohoBigin.modules.ALL,ZohoBigin.settings.layouts.READ,ZohoBigin.users.READ',
'ZohoBigin.modules.ALL,ZohoBigin.settings.modules.READ,ZohoBigin.settings.layouts.READ,ZohoBigin.users.READ',
),
),
$defaults,
Expand Down
65 changes: 38 additions & 27 deletions forms-bridge/addons/brevo/class-brevo-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class Brevo_Addon extends Addon {
*
* @var string
*/
public const OAS_URL = 'https://developers.brevo.com/reference/get_companies?json=on';
// public const OAS_URL = 'https://developers.brevo.com/reference/get_companies?json=on';
public const OAS_URL = 'https://api.brevo.com/v3/swagger_definition_v3.yml';

/**
* Performs a request against the backend to check the connexion status.
Expand Down Expand Up @@ -79,41 +80,51 @@ public function ping( $backend ) {
/**
* Fetch available models from the OAS spec.
*
* @param Backend $backend HTTP backend object.
* @param string $backend Backend name.
* @param string|null $method HTTP method.
*
* @return array
*
* @todo Implementar el endpoint de consulta de endpoints disponibles.
*/
public function get_endpoints( $backend ) {
$response = wp_remote_get(
self::OAS_URL,
array(
'headers' => array(
'Accept' => 'application/json',
'Host' => 'developers.brevo.com',
'Referer' => 'https://developers.brevo.com/reference/get_companies',
'Alt-Used' => 'developers.brevo.com',
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0',
),
)
);
public function get_endpoints( $backend, $method = null ) {
if ( function_exists( 'yaml_parse' ) ) {
$response = wp_remote_get( self::OAS_URL );

if ( is_wp_error( $response ) ) {
return array();
}
if ( ! is_wp_error( $response ) ) {
$data = yaml_parse( $response['body'] );

$data = json_decode( $response['body'], true );
$oa_explorer = new OpenAPI( $data['oasDefinition'] );
if ( $data ) {
$oa_explorer = new OpenAPI( $data );

$paths = $oa_explorer->paths();
$paths = $oa_explorer->paths();

return array_map(
function ( $path ) {
return '/v3' . $path;
},
$paths,
);
if ( $method ) {
$method = strtolower( $method );
$method_paths = array();

foreach ( $paths as $path ) {
$path_obj = $oa_explorer->path_obj( $path );

if ( $path_obj && isset( $path_obj[ $method ] ) ) {
$method_paths[] = $path;
}
}

$paths = $method_paths;
}

return array_map(
function ( $path ) {
return '/v3' . $path;
},
$paths,
);
}
}

return array( '/v3/contacts' );
}
}

/**
Expand Down
56 changes: 56 additions & 0 deletions forms-bridge/addons/dolibarr/class-dolibarr-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,62 @@ public function get_endpoint_schema( $endpoint, $backend, $method = null ) {

return $fields;
}

/**
* Performs an introspection of the backend API and returns a list of available endpoints.
*
* @param string $backend Backend name.
* @param string|null $method HTTP method.
*
* @return array|WP_Error
*/
public function get_endpoints( $backend, $method = null ) {
$bridge = new Dolibarr_Form_Bridge(
array(
'name' => '__dolibarr-' . time(),
'endpoint' => self::SWAGGER_ENDPOINT,
'backend' => $backend,
'method' => 'GET',
)
);

$response = $bridge->submit();

if ( is_wp_error( $response ) ) {
return array();
}

$version = $response['data']['swagger'] ?? null;
if ( ! $version ) {
return array();
}

$oa_explorer = new OpenAPI( $response['data'] );

$paths = $oa_explorer->paths();

if ( $method ) {
$method = strtolower( $method );
$method_paths = array();

foreach ( $paths as $path ) {
$path_obj = $oa_explorer->path_obj( $path );

if ( $path_obj && isset( $path_obj[ $method ] ) ) {
$method_paths[] = $path;
}
}

$paths = $method_paths;
}

return array_map(
function ( $path ) {
return '/api/index.php' . $path;
},
$paths,
);
}
}

Dolibarr_Addon::setup();
16 changes: 16 additions & 0 deletions forms-bridge/addons/financoop/class-financoop-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ public function ping( $backend ) {
return true;
}

/**
* Performs an introspection of the backend API and returns a list of available endpoints.
*
* @param string $backend Target backend name.
* @param string|null $method HTTP method.
*
* @return array|WP_Error
*/
public function get_endpoints( $backend, $method = null ) {
return array(
'/api/campaign/{campaign_id}/subscription_request',
'/api/campaign/{campaign_id}/donation_request',
'/api/campaign/{campaign_id}/loan_request',
);
}

/**
* Performs an introspection of the backend endpoint and returns API fields
* and accepted content type.
Expand Down
23 changes: 23 additions & 0 deletions forms-bridge/addons/gcalendar/class-gcalendar-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@ public function fetch( $endpoint, $backend ) {
return $response;
}

/**
* Performs an introspection of the backend API and returns a list of available endpoints.
*
* @param string $backend Target backend name.
* @param string|null $method HTTP method.
*
* @return array|WP_Error
*/
public function get_endpoints( $backend, $method = null ) {
$response = $this->fetch( null, $backend );

if ( is_wp_error( $response ) || empty( $response['data']['items'] ) ) {
return array();
}

return array_map(
function ( $calendar ) {
return '/calendar/v3/calendars/' . $calendar['id'] . '/events';
},
$response['data']['items']
);
}

/**
* Performs an introspection of the backend endpoint and returns API fields
* and accepted content type.
Expand Down
23 changes: 23 additions & 0 deletions forms-bridge/addons/gsheets/class-gsheets-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,29 @@ public function fetch( $endpoint, $backend ) {
return $response;
}

/**
* Performs an introspection of the backend API and returns a list of available endpoints.
*
* @param string $backend Target backend name.
* @param string|null $method HTTP method.
*
* @return array|WP_Error
*/
public function get_endpoints( $backend, $method = null ) {
$response = $this->fetch( null, $backend );

if ( is_wp_error( $response ) || empty( $response['data']['files'] ) ) {
return array();
}

return array_map(
function ( $file ) {
return '/v4/spreadsheets/' . $file['id'];
},
$response['data']['files']
);
}

/**
* Performs an introspection of the backend endpoint and returns API fields
* and accepted content type.
Expand Down
68 changes: 68 additions & 0 deletions forms-bridge/addons/holded/class-holded-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,74 @@ public function ping( $backend ) {
return true;
}

/**
* Performs an introspection of the backend API and returns a list of available endpoints.
*
* @param string $backend Target backend name.
* @param string|null $method HTTP method.
*
* @return array|WP_Error
*/
public function get_endpoints( $backend, $method = null ) {
$paths = array();

foreach ( self::OAS_URLS as $module => $oas_path ) {
$oas_url = self::OAS_BASE_URL . $oas_path . '?dereference=false&reduce=false';

$response = wp_remote_get(
$oas_url,
array(
'headers' => array(
'Accept' => 'application/json',
'Host' => 'developers.holded.com',
'Alt-Used' => 'developers.holded.com',
'Referer' => 'https://developers.holded.com/reference/list-contacts-1',
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0',
),
),
);

if ( is_wp_error( $response ) ) {
continue;
}

$data = json_decode( $response['body'], true );
if ( ! $data ) {
continue;
}

$oa_explorer = new OpenAPI( $data['data']['api']['schema'] );

$module_paths = $oa_explorer->paths();

if ( $method ) {
$method = strtolower( $method );
$method_paths = array();

foreach ( $module_paths as $path ) {
$path_obj = $oa_explorer->path_obj( $path );

if ( $path_obj && isset( $path_obj[ $method ] ) ) {
$method_paths[] = $path;
}
}

$module_paths = $method_paths;
}

$module_paths = array_map(
function ( $path ) use ( $module ) {
return '/api/' . $module . '/v1' . $path;
},
$module_paths,
);

$paths = array_merge( $paths, $module_paths );
}

return $paths;
}

/**
* Performs an introspection of the backend endpoint and returns API fields
* and accepted content type.
Expand Down
Loading