aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@230.to>2013-07-12 11:41:15 +0300
committerFilipp Lepalaan <f@230.to>2013-07-12 11:41:15 +0300
commit28e37f2f89091eafa1eeeb38dd9be9d9515e0be7 (patch)
treea2f4d61a7d697541f02fcb05ea7d0597a8f3b88b
parent6a6d4fe0e52d2b396c1eabebf4622df1d69e410a (diff)
downloadgsxlib-28e37f2f89091eafa1eeeb38dd9be9d9515e0be7.tar.gz
gsxlib-28e37f2f89091eafa1eeeb38dd9be9d9515e0be7.tar.bz2
gsxlib-28e37f2f89091eafa1eeeb38dd9be9d9515e0be7.zip
Added Mail-In repair support, some basic unit tests
-rw-r--r--gsxlib.php70
-rw-r--r--runtests.php105
2 files changed, 153 insertions, 22 deletions
diff --git a/gsxlib.php b/gsxlib.php
index 3540c2e..f405fed 100644
--- a/gsxlib.php
+++ b/gsxlib.php
@@ -2,7 +2,7 @@
/**
* gsxlib/gsxlib.php
* @package gsxlib
- * @author Filipp Lepalaan <filipp@mcare.fi>
+ * @author Filipp Lepalaan <filipp@fps.ee>
* https://gsxwsut.apple.com/apidocs/html/WSReference.html?user=asp
* @license
* This program is free software. It comes without any warranty, to
@@ -121,7 +121,7 @@ class GsxLib
->AuthenticateResponse
->userSessionId;
} catch(SoapFault $e) {
- if(empty($environment)) $environment = 'production';
+ if($environment == '2') $environment = 'production';
$error = 'Authentication with GSX failed. Does this account have access to '
.$environment."?\n";
@@ -180,23 +180,23 @@ class GsxLib
public function fetchiOsActivation($query)
{
- if( !is_array($query )) {
- $like = self::looksLike( $query );
- $query = array( $like => $query );
+ if(!is_array($query)) {
+ $like = self::looksLike($query);
+ $query = array($like => $query);
}
- $request = array( 'FetchIOSActivationDetails' => $query );
+ $request = array('FetchIOSActivationDetails' => $query);
return $this->request($request)->activationDetailsInfo;
}
-
- public function createCarryInRepair($repairData)
+
+ private function processRepairData($repairData)
{
- if( array_key_exists('fileData', $repairData ))
+ if(array_key_exists('fileData', $repairData))
{
$fp = $repairData['fileData'];
- if( is_readable( $fp ))
+ if(is_readable($fp))
{
$fh = fopen($fp, "r");
$contents = fread($fh, filesize($fp));
@@ -206,20 +206,47 @@ class GsxLib
}
}
+ return $repairData;
+
+ }
+
+ public function createCarryInRepair($repairData)
+ {
+ /**
+ * GSX validates the information and if all of the validations go through,
+ * it obtains a quote for the repair and creates the carry-in repair.
+ */
+ $repairData = $this->processRepairData($repairData);
+
$resp = $this->client->CreateCarryInRepair(
array('CreateCarryInRequest' => array(
'userSession' => array('userSessionId' => $this->getSessionId()),
'repairData' => $repairData
))
);
-
+
return $resp->CreateCarryInResponse;
-
+
}
public function createMailInRepair($repairData)
{
-
+ /**
+ * This API allows the submission of Mail-In Repair information into GSX,
+ * resulting in the creation of a GSX Mail-In Repair.
+ */
+
+ $repairData = $this->processRepairData($repairData);
+
+ $resp = $this->client->CreateMailInRepair(
+ array('CreateMailInRepairRequest' => array(
+ 'userSession' => array('userSessionId' => $this->getSessionId()),
+ 'repairData' => $repairData
+ ))
+ );
+
+ return $resp->CreateMailInRepairResponse;
+
}
public function bulkReturnProforma() {}
@@ -421,19 +448,19 @@ class GsxLib
*/
public function warrantyStatus($serialNumber)
{
- if( !is_array( $serialNumber )) {
+ if(!is_array($serialNumber)) {
$serialNumber = array('serialNumber' => $serialNumber);
}
- if( array_key_exists( 'alternateDeviceId', $serialNumber )) {
+ if(array_key_exists('alternateDeviceId', $serialNumber)) {
# checking warranty with IMEI code - must run activation check first
- $ad = $this->fetchiOsActivation( $serialNumber );
- $wty = $this->warrantyStatus( $ad->serialNumber );
+ $ad = $this->fetchiOsActivation($serialNumber);
+ $wty = $this->warrantyStatus($ad->serialNumber);
$wty->activationDetails = $ad;
return $wty;
}
- $req = array( 'WarrantyStatus' => array( 'unitDetail' => $serialNumber ));
+ $req = array('WarrantyStatus' => array('unitDetail' => $serialNumber));
return $this->request($req)->warrantyDetailInfo;
@@ -442,7 +469,8 @@ class GsxLib
public function productModel($serialNumber)
{
if(!$this->isValidSerialNumber($serialNumber)) {
- exit('Invalid serial number: ' . $serialNumber);
+ $error = sprintf('Invalid serial number: %s', $serialNumber);
+ throw new InvalidArgumentException($error);
}
$req = array( 'FetchProductModelRequest' => array(
@@ -454,9 +482,7 @@ class GsxLib
)
));
- $response = $this->client
- ->FetchProductModel($req)
- ->FetchProductModelResponse;
+ $response = $this->client->FetchProductModel($req)->FetchProductModelResponse;
return $response->productModelResponse;
}
diff --git a/runtests.php b/runtests.php
new file mode 100644
index 0000000..c1323e8
--- /dev/null
+++ b/runtests.php
@@ -0,0 +1,105 @@
+<?php
+
+require_once('simpletest/autorun.php');
+require_once('gsxlib.php');
+
+class GsxlibTest extends UnitTestCase
+{
+ function setUp() {
+ global $argv;
+ $this->gsx = GsxLib::getInstance($argv[1], $argv[2], $argv[3], 'ut');
+ }
+
+ function testWarranty() {
+ $wty = $this->gsx->warrantyStatus('RM6501PXU9C');
+ $this->assertEqual($wty->warrantyStatus, 'Out Of Warranty (No Coverage)');
+ }
+
+ function testCreateCarryInRepair() {
+ $repairData = array(
+ 'shipTo' => '6191',
+ 'serialNumber' => 'RM6501PXU9C',
+ 'diagnosedByTechId' => 'USA022SN',
+ 'symptom' => 'Sample symptom',
+ 'diagnosis' => 'Sample diagnosis',
+ 'unitReceivedDate' => '07/02/13',
+ 'unitReceivedTime' => '12:40 PM',
+ 'notes' => 'A sample notes',
+ 'poNumber' => '11223344',
+ 'popFaxed' => false,
+ 'orderLines' => array(
+ 'partNumber' => '076-1080',
+ 'comptiaCode' => '660',
+ 'comptiaModifier' => 'A',
+ 'abused' => false
+ ),
+ 'customerAddress' => array(
+ 'addressLine1' => 'Address line 1',
+ 'country' => 'US',
+ 'city' => 'Cupertino',
+ 'state' => 'CA',
+ 'street' => 'Valley Green Dr',
+ 'zipCode' => '95014',
+ 'regionCode' => '005',
+ 'companyName' => 'Apple Inc',
+ 'emailAddress' => 'test@example.com',
+ 'firstName' => 'Customer Firstname',
+ 'lastName' => 'Customer lastname',
+ 'primaryPhone' => '4088887766'
+ ),
+ );
+
+ $this->gsx->createCarryinRepair($repairData);
+
+ }
+
+ function testCreateMailInRepair() {
+ $repairData = array(
+ 'shipTo' => '6191',
+ 'accidentalDamage' => false,
+ 'addressCosmeticDamage' => false,
+ 'comptia' => array(
+ 'comptiaCode' => 'X01',
+ 'comptiaModifier' => 'D',
+ 'comptiaGroup' => 1,
+ 'technicianNote' => 'sample technician notes'
+ ),
+ 'requestReviewByApple' => false,
+ 'serialNumber' => 'RM6501PXU9C',
+ 'diagnosedByTechId' => 'USA022SN',
+ 'symptom' => 'Sample symptom',
+ 'diagnosis' => 'Sample diagnosis',
+ 'unitReceivedDate' => '07/02/13',
+ 'unitReceivedTime' => '12:40 PM',
+ 'notes' => 'A sample notes',
+ 'purchaseOrderNumber' => 'AB12345',
+ 'trackingNumber' => '12345',
+ 'shipper' => 'XDHL',
+ 'soldToContact' => 'Cupertino',
+ 'popFaxed' => false,
+ 'orderLines' => array(
+ 'partNumber' => '076-1080',
+ 'comptiaCode' => '660',
+ 'comptiaModifier' => 'A',
+ 'abused' => false
+ ),
+ 'customerAddress' => array(
+ 'addressLine1' => 'Address line 1',
+ 'country' => 'US',
+ 'city' => 'Cupertino',
+ 'state' => 'CA',
+ 'street' => 'Valley Green Dr',
+ 'zipCode' => '95014',
+ 'regionCode' => '005',
+ 'companyName' => 'Apple Inc',
+ 'emailAddress' => 'test@example.com',
+ 'firstName' => 'Customer Firstname',
+ 'lastName' => 'Customer lastname',
+ 'primaryPhone' => '4088887766'
+ ),
+ );
+
+ $this->gsx->createMailinRepair($repairData);
+
+ }
+}