Skip to content

Commit 58b28ca

Browse files
author
Jeffrey Bostoen
committed
- Add detection of iTop API versions 1.3 and 1.4.
- Improve error message: Include hints on what to validate.
1 parent 2081047 commit 58b28ca

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

core/restclient.class.inc.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,29 @@ protected static function ExecOperation($aOperation, $sVersion = '1.0')
129129
return $aResults;
130130
}
131131

132-
public static function GetNewestKnownVersion()
133-
{
134-
$sNewestVersion = '1.0';
132+
133+
/**
134+
* Gets the iTop API version in use. It tries all the known versions, starting from the newest one.
135+
*
136+
* @return string The newest supported version.
137+
* @throws Exception If no supported version is found.
138+
*/
139+
public static function GetNewestKnownVersion() : string {
140+
135141
$oC = new RestClient();
136-
$aKnownVersions = array('1.0', '1.1', '1.2', '2.0');
142+
// Order: Put the newest versions first.
143+
$aKnownVersions = array('1.4', '1.3', '1.2', '1.1', '1.0');
137144
foreach ($aKnownVersions as $sVersion) {
138145
$oC->SetVersion($sVersion);
139146
$aRet = $oC->ListOperations();
140147
if ($aRet['code'] == 0) {
141-
// Supported version
142-
$sNewestVersion = $sVersion;
148+
// A non-error code (0) means the version is supported.
149+
return $sVersion;
143150
}
144151
}
145152

146-
return $sNewestVersion;
153+
throw new Exception("Unable to detect an iTop API. Validate the URL and the credentials, and check if appropriate profiles have been assigned to the user (e.g. 'REST Services User').");
154+
147155
}
148156

149157
/**

0 commit comments

Comments
 (0)