From 462031fb499ae21a3a5deffd856c007697c9168d Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Fri, 29 Apr 2011 11:49:41 +0300 Subject: first commit --- gsxlib.php | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 gsxlib.php (limited to 'gsxlib.php') diff --git a/gsxlib.php b/gsxlib.php new file mode 100644 index 0000000..6f61703 --- /dev/null +++ b/gsxlib.php @@ -0,0 +1,116 @@ + + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/wtfpl/COPYING for more details. + */ +class GsxLib +{ + private $client; + private $region; + private $session_id; + private $environment; + + + function __construct($account, $username, $password, $environment = 'ws', $region = 'emea', $tz = 'CEST') + { + if (!class_exists('SoapClient')) { + exit('Looks like your PHP lacks SOAP support'); + } + + if (!preg_match('/\d+/', $account)) { + exit('Invalid Sold-To: ' . $account); + } + + $regions = array('am', 'emea', 'apac', 'la'); + + if (!in_array($region, $regions)) { + exit('Region must be one of: ' . implode(', ', $regions)); + } + + $envirs = array('ws', 'ut', 'it'); + + if (!in_array($environment, $envirs)) { + exit('Environment must be one of: ' . implode(', ', $envir)); + } + + $wsdl = 'https://gsx'.$environment.'.apple.com/gsx-ws/services/'.$region.'/asp?wsdl'; + $this->client = new SoapClient($wsdl, array('exceptions' => TRUE, 'trace' => 1)); + + if (session_id()) { + $_SESSION['_gsxlib_client'] = serialize($this->client); + } + + if (!$this->client) { + exit('Failed to create SOAP client.'); + } + + $a = array( + 'AuthenticateRequest' => array( + 'userId' => $username, + 'password' => $password, + 'serviceAccountNo' => $account, + 'languageCode' => 'en', + 'userTimeZone' => $tz) + ); + + if (@$_SESSION['_gsxlib_session_timeout'] > time()) { + return $this->session_id = $_SESSION['_gsxlib_session_id']; + } + + try { + $this->session_id = $this->client->Authenticate($a)->AuthenticateResponse->userSessionId; + } catch (Exception $e) { + exit('Authentication with GSX failed'); + } + + // there's a session going, put the credentials in the + if (session_id()) { + $_SESSION['_gsxlib_session_id'] = $this->session_id; + $_SESSION['_gsxlib_session_timeout'] = time()+60*30; + } + + } + + public function partDetails($partNumber) + { + if (!preg_match('/^\w+\-\w+^/', $partNumber)) { + exit('Invalid part number: ' . $partNumber); + } + + } + + /** + * A shortcut for checking warranty status of device + */ + public function warrantyStatus($serialNumber) + { + if (!preg_match('/^[a-z0-9]{7,18}$/i', $serialNumber)) { + exit('Invalid serial number: ' . $serialNumber); + } + + $a = array( + 'WarrantyStatusRequest' => array( + 'userSession' => array('userSessionId' => $this->session_id), + 'unitDetail' => array('serialNumber' => $serialNumber) + )); + + $result = $this->client->WarrantyStatus($a); + return $result->WarrantyStatusResponse->warrantyDetailInfo; + + } + + public function request($args) + { + $info = $client->WarrantyStatus($a); + $out[] = $info->WarrantyStatusResponse->warrantyDetailInfo; + } + +} + + +?> \ No newline at end of file -- cgit v1.2.3