jgillman's Liquid Web Update Unofficial tips, tricks, and happenings from a Liquid Web sales engineer

30Apr/120

Interactive Storm API Testing Script

What happens when I get bored? I code apparently.

Here's a piece of PHP code that runs purely command line. What it does is allow you to interactively work with the StormOnDemand API.

Although the output is just a straight print_r() of the returned data set, it does provide a nice easy way if you want to see the returns from various methods (or while feeding the same method different parameter/value pairs) in an expedient manner - all without having to write/replace code in a static script.

Enjoy!

 PHP | 
 
 copy code |
?

01
02
<?php
03
	/*
04
	 * Author: Jason Gillman Jr.
05
	 * Description: My attempt at writing a simple interactive CLI script for dumping raw data from Storm API returns.
06
	 * 				All you are going to get is print_r() of the returned array.
07
	 * 				Hope it's useful!
08
	 */
09
 
10
	require_once('StormAPI.class.php');
11
 
12
	// Initial information
13
	echo "\nAPI Username: "; $api_user = trim(fgets(STDIN));
14
	echo "Password: "; $api_pass = trim(fgets(STDIN));
15
	echo "Initial Method: "; $api_method = trim(fgets(STDIN));
16
 
17
	$storm = new StormAPI($api_user, $api_pass, $api_method);
18
 
19
	// Menu
20
	while(!isset($stop))
21
	{
22
		echo "\n\nPick your poison... \n";
23
		echo "1. Change method (will clear params) \n";
24
		echo "2. Add parameter \n";
25
		echo "3. Clear parameters \n";
26
		echo "4. Execute request and display \n";
27
		echo "5. Get me out of here \n";
28
		echo "Enter a number: "; fscanf(STDIN, "%d\n", $choice); // Get the choice
29
 
30
		switch($choice)
31
		{
32
			case 1:
33
				echo "\nEnter your new method: "; $api_method = trim(fgets(STDIN));
34
				$storm->new_method($api_method);
35
				break;
36
			case 2:
37
				echo "\nEnter the parameter: "; $parameter = trim(fgets(STDIN));
38
				echo "\nEnter the value: "; $value = trim(fgets(STDIN));
39
				$storm->add_param($parameter, $value);
40
				unset($parameter, $value);
41
				break;
42
			case 3:
43
				$storm->clear_params();
44
				break;
45
			case 4:
46
				print_r($storm->request());
47
				break;
48
			case 5:
49
				echo "\n\n";
50
				$stop = TRUE;
51
				break;
52
			default:
53
				echo "Really? How about you enter a valid value?";
54
				break;
55
		}
56
	}
57
?>
58

   
FireStats icon Powered by FireStats
Optimization WordPress Plugins & Solutions by W3 EDGE