diff options
author | Filipp Lepalaan <filipp@mac.com> | 2011-04-29 11:49:41 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2011-04-29 11:49:41 +0300 |
commit | 462031fb499ae21a3a5deffd856c007697c9168d (patch) | |
tree | 054d2ac185001ebdc5003675df7fcea47eeca2b0 /gsxlib.php | |
download | gsxlib-462031fb499ae21a3a5deffd856c007697c9168d.tar.gz gsxlib-462031fb499ae21a3a5deffd856c007697c9168d.tar.bz2 gsxlib-462031fb499ae21a3a5deffd856c007697c9168d.zip |
first commit
Diffstat (limited to 'gsxlib.php')
-rw-r--r-- | gsxlib.php | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/gsxlib.php b/gsxlib.php new file mode 100644 index 0000000..6f61703 --- /dev/null +++ b/gsxlib.php @@ -0,0 +1,116 @@ +<?php +/** + * gsxlib/gsxlib.php + * @author Filipp Lepalaan <filipp@mcare.fi> + * 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 |