aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2011-04-29 11:49:41 +0300
committerFilipp Lepalaan <filipp@mac.com>2011-04-29 11:49:41 +0300
commit462031fb499ae21a3a5deffd856c007697c9168d (patch)
tree054d2ac185001ebdc5003675df7fcea47eeca2b0
downloadgsxlib-462031fb499ae21a3a5deffd856c007697c9168d.tar.gz
gsxlib-462031fb499ae21a3a5deffd856c007697c9168d.tar.bz2
gsxlib-462031fb499ae21a3a5deffd856c007697c9168d.zip
first commit
-rw-r--r--README.md33
-rw-r--r--gsxlib.php116
2 files changed, 149 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..62d4feb
--- /dev/null
+++ b/README.md
@@ -0,0 +1,33 @@
+##About##
+GsxLib is a PHP library that simplifies communication with Apple's GSX web service API. It frees the application developer
+from knowing the underlying PHP SOAP architecture and to some extent even the GSX API itself. GsxLib also tries to provide
+some performance benefits by minimizing the number of requests made to the servers as well as doing some rudimentary input
+validation (as opposed to burdening Apple's servers with totally invalid requests).
+
+##Requrements##
+Your PHP should have SOAP support enabled. Most distributions should (including OS X Server 10.6 or later).
+For more details, consult your distribution or http://php.net/manual/en/book.soap.php.
+
+##Usage##
+
+ <?php
+
+ include 'gsxlib/gsxlib.php';
+ $gsx = new GsxLib('your sold-to account', 'gsx user', 'password');
+ $info = $gsx->warrantyStatus('serialnumber');
+
+ ?>
+
+
+##License##
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
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