diff options
author | Filipp Lepalaan <filipp@mac.com> | 2011-12-03 23:16:16 +0200 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2011-12-03 23:16:16 +0200 |
commit | 5ac597d3d0b3f44699f96b47bc6c62348f5b0d26 (patch) | |
tree | 235a6af4036bd1c216e5b610d3b1baa8ea9105d3 | |
parent | 6ffa28a28f11490f0e27dcdbbc67210d492fac0e (diff) | |
download | gsxlib-5ac597d3d0b3f44699f96b47bc6c62348f5b0d26.tar.gz gsxlib-5ac597d3d0b3f44699f96b47bc6c62348f5b0d26.tar.bz2 gsxlib-5ac597d3d0b3f44699f96b47bc6c62348f5b0d26.zip |
Added fetching product model, onsite dispatch details
-rw-r--r-- | README.md | 4 | ||||
-rwxr-xr-x | gsxcl | 8 | ||||
-rw-r--r-- | gsxlib.php | 81 |
3 files changed, 72 insertions, 21 deletions
@@ -27,8 +27,8 @@ If you're in the US, remember to set the fifth argument to the constructor to 'a ##gsxcl## -The package includes a rudimentary command line client to the GSX API called gsxcl. -Currently it can perform warranty checks and part lookups. +The package includes a rudimentary command line client to the GSX API called gsxcl. It can perform various functions in the library and is meant +mainly as a simple test tool for the library. ##License## @@ -18,7 +18,7 @@ if (FALSE) { error_reporting(E_ALL|E_STRICT); } -$modes = array('warranty', 'parts', 'pending', 'repair', 'lookup', 'status', 'label'); +$modes = array( 'warranty', 'parts', 'pending', 'repair', 'lookup', 'status', 'label', 'model', 'osdispatchdetail' ); $modes_str = implode(', ', $modes); require 'gsxlib.php'; @@ -97,6 +97,12 @@ switch ($mode) case 'comptia': $result = $gsx->compTiaCodes(); break; + case 'model': + $result = $gsx->productModel( $query ); + break; + case 'osdispatchdetail': + $result = $gsx->onsiteDispatchDetail( $query ); + break; case 'label': list($order, $part) = explode(':', $query); $result = $gsx->returnLabel($order, $part); @@ -79,7 +79,10 @@ class GsxLib ->userSessionId; } catch (SoapFault $e) { - exit('Authentication with GSX failed. Does this account have access to '.$environment.' ?'); + if( empty( $environment )) { + $environment = 'production'; + } + exit('Authentication with GSX failed. Does this account have access to '.$environment."?\n"); } // there's a session going, put the credentials in there @@ -281,15 +284,9 @@ class GsxLib /** * A shortcut for checking warranty status of device */ - public function warrantyStatus($serialNumber) + public function warrantyStatus( $serialNumber ) { - $serialNumber = trim($serialNumber); - // SNs should never start with an S, but they're often coded into barcodes - // and since an "old- ormat" SN + S would still qualify as a "new format" SN, - // we strip it here - $serialNumber = ltrim($serialNumber, 'sS'); - - if (!self::looksLike($serialNumber, 'serialNumber')) { + if( !$this->isValidSerialNumber( $serialNumber )) { exit('Invalid serial number: ' . $serialNumber); } @@ -301,6 +298,54 @@ class GsxLib } + public function productModel( $serialNumber ) + { + if( !$this->isValidSerialNumber( $serialNumber )) { + exit('Invalid serial number: ' . $serialNumber); + } + + $req = array( 'FetchProductModelRequest' => array( + 'userSession' => array( 'userSessionId' => $this->session_id ), + 'productModelRequest' => array( 'serialNumber' => $serialNumber ) + )); + + $response = $this->client->FetchProductModel( $req )->FetchProductModelResponse; + return $response->productModelResponse; + + } + + public function onsiteDispatchDetail( $query ) + { + if( !self::looksLike( $query, 'dispatchId' )) { + exit( "Invalid dispatch ID: $query" ); + } + + $req = array( 'OnsiteDispatchDetailRequest' => array( + 'userSession' => array( 'userSessionId' => $this->session_id ), + 'lookupRequestData' => array( + 'dispatchId' => $query, + 'dispatchSentFromDate' => '', + 'dispatchSentToDate' => '' + ) + )); + + $response = $this->client->OnsiteDispatchDetail( $req )->OnsiteDispatchDetailResponse; + + return $response->onsiteDispatchDetails; + + } + + public function isValidSerialNumber( $serialNumber ) + { + $serialNumber = trim( $serialNumber ); + // SNs should never start with an S, but they're often coded into barcodes + // and since an "old- ormat" SN + S would still qualify as a "new format" SN, + // we strip it here and not in self::looksLike + $serialNumber = ltrim($serialNumber, 'sS'); + + return self::looksLike( $serialNumber, 'serialNumber' ); + } + /** * return the GSX user session ID * I still keep the property private since it should not be modified @@ -315,24 +360,24 @@ class GsxLib /** * Do the actual SOAP request */ - private function request($req) + private function request( $req ) { $result = FALSE; // split the request name and data - list($r, $p) = each($req); + list( $r, $p ) = each( $req ); // add session info - $p['userSession'] = array('userSessionId' => $this->session_id); - $request = array($r.'Request' => $p); - + $p['userSession'] = array( 'userSessionId' => $this->session_id ); + $request = array( $r.'Request' => $p ); + print_r( $request ); try { - $result = $this->client->$r($request); + $result = $this->client->$r( $request ); $resp = "{$r}Response"; return $result->$resp; } catch (SoapFault $e) { - print($this->client->__getLastRequest()); - trigger_error($e->getMessage()); + print( $this->client->__getLastRequest() ); + trigger_error( $e->getMessage() ); } return $result; @@ -346,7 +391,7 @@ class GsxLib * unfortunately, it's no longer the case * @param string $string string to check */ - static function looksLike($string, $what = null) + static function looksLike( $string, $what = null ) { $result = false; |