#!/usr/bin/env php * @license * 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. */ if (TRUE) { error_reporting( E_ALL|E_STRICT ); } $nouns = array( 'repair', 'part', 'dispatch', 'order', 'return', 'warranty' ); $verbs = array( 'create', 'lookup', 'update', 'status', 'label', 'pending', 'details' ); $nouns_str = implode( ', ', $nouns ); $verbs_str = implode( ', ', $verbs ); require 'gsxlib.php'; if( count( $argv ) < 6 ) { echo <<warrantyStatus( $data ); break; } break; case 'part': switch( $verb ) { case 'lookup': $result = $gsx->partsLookup( $data ); break; case 'pending': $result = $gsx->partsPendingReturn( $data ); break; case 'details': $result = $gsx->partsPendingReturn( $data ); break; } break; case 'repair': switch( $verb ) { case 'lookup': $result = $gsx->repairLookup( $data ); break; case 'details': $result = $gsx->partsPendingReturn( $data ); break; case 'status': $result = $gsx->repairStatus( $query ); 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 ); $name = $result->returnLabelFileName; echo $result->returnLabelFileData; break; } switch( $format ) { case 'json': echo json_encode( $result ); break; case 'xml': if( !function_exists( 'simplexml_load_string' )) { exit( "Error: your PHP lacks SimpleXML support!\n" ); } $xml = simplexml_load_string( '' ); foreach ($result as $k => $v) { $key = (is_numeric( $k )) ? 'item' : $k; $value = (is_object( $v )) ? null : $v; $item = $xml->addChild( $key, $value ); if( is_object( $v )) { foreach( $v as $vk => $vv ) { $item->addChild( $vk, $vv ); } } } echo $xml->asXML(); break; case 'csv': $i = 0; $fo = fopen('php://stdout', 'w'); foreach( $result as $k => $v ) { if( is_object( $v )) { $keys = array(); $vals = array(); foreach ($v as $vk => $vv) { if ($i == 0) { $keys[] = $vk; } $vals[] = $vv; } // treat field names of first item as header row if ($i == 0) { fputcsv( $fo, $keys ); } fputcsv( $fo, $vals ); } else { $keys[] = $k; $vals[] = $v; } $i++; } if (count($result) === 1) { fputcsv($fo, $keys); fputcsv($fo, $vals); } fclose($fo); break; default: print_r($result); break; }