Simple PHP API in a single class

Submitted by rainer on Wed, 04/22/2015 - 15:25

This class allowas simple communication with the flashteams.org backend.

Example Usage:

include_once 'SimpleSynchronousFlashTeamsOrgV1Client.inc';

$c = new SimpleSynchronousFlashTeamsOrgV1Client("Rainer", "X 24", "supersecret");

// create the user
$response = $c->checkUser("phpapi"); sleep(1);
print $response->outdata->rctext."\n";

// create the testroom
$response = $c->checkRoom("Testroom",	"1", "0", "X 24"); sleep(1);
echo $response->outdata->rctext."\n";

// post a message
$response = $c->postMsg("Testroom", "Hello World!"); sleep(1);
print $response->outdata->rctext."\n";

// post another message
$response = $c->postMsg("Testroom", "This is an API test"); sleep(1);
print $response->outdata->rctext."\n";

// retrieve and print all msgs in that room
$response = $c->getMsgs("Testroom", "1"); sleep(1);
print $response->outdata->rctext."\n";

foreach ($response->outdata->params->msgs as $msg) {
	print date("H:i:s", $msg->timestamp)." ".$msg->user."@".$msg->team
			.": ".$msg->post."\n";
}

// get users state and show as print_r
$response = $c->checkUser("phpapi"); sleep(1);
print_r($response); 

// delete that user
$response = $c->deleteSelf(); sleep(1);
print $response->outdata->rctext."\n";

echo "DONE\n";

This will generate the output as follows:

> php test.php 
OK: New user created
OK: Room created
Room exists, you have access
Room exists, you have access
Room exists, you have access
15:10:13 Rainer@X 24: This is an API test
15:10:12 Rainer@X 24: Hello World!
stdClass Object
(
    [indata] => stdClass Object
        (
            [cmd] => checkUser
            [cmdversion] => 1
            [timestamp] => 22.04.2015 15:10:15
            [params] => stdClass Object
                (
                    [device] => phpapi
                    [user] => Rainer
                    [passwd] => supersecret
                    [team] => X 24
                )

        )

    [outdata] => stdClass Object
        (
            [rccode] => 2
            [rctext] => OK: User well known
            [params] => stdClass Object
                (
                    [created] => 1429708209
                    [lastbeat] => 1429708215
                    [device] => phpapi
                    [teams] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [team] => X 24
                                    [size] => 1
                                )

                        )

                    [rooms] => Array
                        (
                        )

                    [bossrooms] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [room] => Testroom
                                    [teampublic] => X 24
                                )

                        )

                )

        )

)
User and all of her assets are deleted
DONE

It's well documented, I hope you get along

Attachments

Comments

Add new comment

Restricted HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <h4> <h5> <h6>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.