From d9b7519391b86f79573c756c357a84eda83fa725 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Wed, 4 May 2011 10:21:42 +0300 Subject: Added repairStatus() --- gsxlib.php | 90 +++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 30 deletions(-) diff --git a/gsxlib.php b/gsxlib.php index 7f6be8c..ca133f4 100644 --- a/gsxlib.php +++ b/gsxlib.php @@ -66,7 +66,7 @@ class GsxLib try { $this->session_id = $this->client->Authenticate($a)->AuthenticateResponse->userSessionId; } catch (SoapFault $e) { - exit('Authentication with GSX failed. Does this GSX account have access to this environment?'); + exit('Authentication with GSX failed. Does this account have access to '.$environment.' ?'); } // there's a session going, put the credentials in there @@ -77,6 +77,36 @@ class GsxLib } + /** + * Get current GSX status of repair + * @param mixed $dispatchId + */ + public function repairStatus($dispatchId) + { + $toCheck = array(); + + if (!is_array($dispatchId)) { + $dispatchId = array($dispatchId); + } + + foreach ($dispatchId as $id) { + if (self::looksLike($id, 'dispatchId')) { + $toCheck[] = $id; + } + } + + if (empty($toCheck)) { + exit('No valid dispatch IDs given'); + } + + $req = array('RepairStatus' => array( + 'repairConfirmationNumbers' => $toCheck + )); + + return $this->request($req)->repairStatus; + + } + /** * Return details for given dispatch ID * @param string $dispatchId @@ -117,35 +147,6 @@ class GsxLib } - /** - * Try to "categorise" a string - * About identifying serial numbers - before 2010, Apple had a logical - * serial number format, with structure, that you could id quite reliably. - * unfortunately, it's no longer the case - * @param string $string - */ - static function looksLike($string, $what = null) - { - $result = false; - - $rex = array( - 'partNumber' => '/^[a-z]?\d{3}\-\d{4}$/i', - 'serialNumber' => '/^[a-z0-9]{11,12}$/i', - 'eeeCode' => '/^[a-z0-9]{3,4}$/i', - 'repairNumber' => '/^\d{12}$/', - 'dispatchId' => '/^G\d{9}$/i' - ); - - foreach ($rex as $k => $v) { - if (preg_match($v, $string)) { - $result = $k; - } - } - - return ($what) ? ($result == $what) : $result; - - } - /** * A shortcut for checking warranty status of device */ @@ -196,6 +197,35 @@ class GsxLib } + /** + * Try to "categorise" a string + * About identifying serial numbers - before 2010, Apple had a logical + * serial number format, with structure, that you could id quite reliably. + * unfortunately, it's no longer the case + * @param string $string + */ + static function looksLike($string, $what = null) + { + $result = false; + + $rex = array( + 'partNumber' => '/^[a-z]?\d{3}\-\d{4}$/i', + 'serialNumber' => '/^[a-z0-9]{11,12}$/i', + 'eeeCode' => '/^[a-z0-9]{3,4}$/i', + 'repairNumber' => '/^\d{12}$/', + 'dispatchId' => '/^G\d{9}$/i' + ); + + foreach ($rex as $k => $v) { + if (preg_match($v, $string)) { + $result = $k; + } + } + + return ($what) ? ($result == $what) : $result; + + } + } -- cgit v1.2.3