Flash API v1.0.4

This WordPress plugin serves as a faux web service that outputs data from the WP Database to a Flash application in the format of XML, JSON, TEXT or any other way you wish. It is intended to make managing data for Flash projects easier by leveraging WordPress’s awesome admin and data management.

* Note: PHP and WordPress knowledge is required to create your own functions and data outputs.


Screen Shots

Download


Documentation


Installation

  1. Upload `flash_api` directory to the `/wp-content/plugins/` directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Click Flash API from the Admin -> Settings Menu.
  4. Set the Application key (this is generated by default but it is wise to change this).
  5. Set the Codex Category (this is set by default but if you wish to name your codex entries something else, do so here).
  6. Open the `/wp-content/plugins/flash_api/services.php` file and begin extending the plugin with your own functions. This is done just like editing the functions.php of a theme.

Usage

See ‘/wp-content/plugins/flash_api/flash_example/flash_api_example.fla’
import fl.controls.List;
import fl.controls.Button;
import fl.data.DataProvider;
import flash.net.navigateToURL;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
 
// DOWNLOAD BUTTON
var btn:Button = downloadButton as Button;
btn.addEventListener(MouseEvent.CLICK, downloadFile); 
 
// LIST
var lst:List = mediaList as List;
lst.labelField = 'title';
 
// URL REST VARIABLES
var rest:URLVariables = new URLVariables();
rest.apiKey = '1e7abba6c6b8b6aead1d57ffcf4c9943';
rest.service = 'attachments';
 
// URL REQUEST
var url:URLRequest = new URLRequest('http://dev.illumifi.net/wp-content/plugins/flash_api/wsrv.php');
url.data = rest;
url.method = 'POST';
 
// URL LOADER
var ldr:URLLoader = new URLLoader();
ldr.addEventListener(Event.COMPLETE, dataLoaded);
 
/* === INITIATE === */
ldr.load(url);
 
// FUNCTIONS
 
// DATA RETURNED FROM FLASH API
function dataLoaded(evt:Event):void {
	// dp stores the data for the list
	var dp:DataProvider = new DataProvider();
 
	// convert the http return into an XML Object
	var xml:XML = new XML(evt.target.data);
	xml.ignoreWhitespace = true;
 
	// select only the list nodes from the XML Object
	var xmlList:XMLList = new XMLList(xml['node']); 
 
	// loop through each node and read it's attributes into an object
	for (var i:uint = 0; i < xmlList.length(); i++) {
		var node:XML = xmlList[i];
		var obj:Object = objectifyAttr(node); 
 
		// add object to the dataProvider
		dp.addItem(obj);
	}
 
	// set the list's dataProvider
	lst.dataProvider = dp;
 
	// hide preloader
	preloader.visible = false; 
 
	// show list and download button
	lst.visible = true;
	btn.visible = true;
}
 
// CONVERT A NODE INTO AN OBJECT
function objectifyAttr(node:XML):Object {
	var obj:Object = {};
 
	// Loop through attributes
	for (var a:uint = 0; a < node.attributes().length(); a++) {
		var attr:String = String(node.attributes()[a].name());
		var val:* = node.attributes()[a];
		obj[attr] = val;
	}
	return obj;
}
 
// DOWNLOAD CLICKED -> DOWNLOAD FILE
function downloadFile(evt:MouseEvent):void {
	var sel:String = (lst['selectedItem']) ? lst.selectedItem.link : null;
	if (sel != null) {
		var u:URLRequest = new URLRequest(lst.selectedItem.link);
		navigateToURL(u);
	}
}

FAQ

Q: Can I set API keys for individual Users?

A: YES!

  1. Edit the user’s profile -> Flash API -> API Key value.
  2. Give that apiKey to the user to use for their flash apps.

You can then alter your services to work only for specific API keys.
You can also set user permissions within your services via WordPress’s user levels manangement (see WordPress Codex -> User Levels).



You must be logged in to post a comment.