My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
GenerateFlexFromRails  
How to generate ActionScript classes from Rails ActionControllers using the pocogese:generate Rake task
Updated Feb 4, 2010 by ernest.m...@gmail.com

Introduction

The Pocogese Rails plugin creates a template Rake task: lib\tasks\pocogese_generate.rake. Running this task will generate Flex clients for each controller in the project. In addition to each controller client, a separate ActionScript interface is generated that could helps you when implementing Stubs for your project.

Details

Example

  • Modify the pocogese:generate task to specify source and targets
  • namespace :pocogese do
    
    desc "Generates ActionScript classes with Command and Selection API methods for ActionControllers"
    task :generate  => :environment do
      require 'lib/generators/flex_generator'
    
      # Generates clients and interfaces in Flex
      #  
      project('c:/dev/cae/pocogese-flex-demo') {
        package('com.company.app.user') {
          controller :UserController     
        }
      }
      
    end # task
    
    end # namespace
  • run this task by: rake pocogese:generate
  • package com.company.app.user.controllers.impl
    {
    	// UserControllerClient is generated by Pocogese on Sat, 10 Nov 2007 14:04:23 GMT
    
    	import flash.net.URLVariables;
    	import com.philemonworks.flex.net.Command;
    	import com.philemonworks.flex.net.HttpClient;
    	import com.company.app.user.controllers.api.UserController;
    	
    	public class UserControllerClient implements com.company.app.user.controllers.api.UserController {
    		private var _baseURL:String;
    		
    		/**
    		 * Constructor
    		 *
    		 * @param baseURL String
    		 */
    		public function UserControllerClient(baseURL:String = "") {
    			super()
    			this._baseURL = baseURL
    		}	
    		/**
    		 * Command API function. The _replyReceivedHandler function (optional) will be called with a Reply object 
    		 *
    		 * @param _replyReceivedHandler Function called when the command has been processed and a Reply is received.		 
    		 */
    		public function changePassword(user_login:String,old_password:String,new_password:String,_replyReceivedHandler:Function = null):void {
    			trace('UserController#changePassword(user_login,old_password,new_password)')
    			var _cmd:Command = new Command("changePassword")
    			_cmd.setParameter("user_login",user_login)
    			_cmd.setParameter("old_password",old_password)
    			_cmd.setParameter("new_password",new_password)				
    			new HttpClient("e4x").send_post(_cmd.toXML(),this._baseURL + "user/service",_replyReceivedHandler)
    		}
    		/**
    		 * Command API function. The _replyReceivedHandler function (optional) will be called with a Reply object 
    		 *
    		 * @param _replyReceivedHandler Function called when the command has been processed and a Reply is received.		 
    		 */
    		public function destroy(id:String,_replyReceivedHandler:Function = null):void {
    			trace('UserController#destroy(id)')
    			var _cmd:Command = new Command("destroy")
    			_cmd.setParameter("id",id)				
    			new HttpClient("e4x").send_post(_cmd.toXML(),this._baseURL + "user/service",_replyReceivedHandler)
    		}
    		/**
    		 * Command API function. The _replyReceivedHandler function (optional) will be called with a Reply object 
    		 *
    		 * @param _replyReceivedHandler Function called when the command has been processed and a Reply is received.		 
    		 */
    		public function saveOrUpdate(recordXML:String,_replyReceivedHandler:Function = null):void {
    			trace('UserController#saveOrUpdate(recordXML)')
    			var _cmd:Command = new Command("saveOrUpdate")
    			_cmd.setParameter("recordXML",recordXML)				
    			new HttpClient("e4x").send_post(_cmd.toXML(),this._baseURL + "user/service",_replyReceivedHandler)
    		}
    
    		/**
    		 * Selection API function.  _xmlReceivedHandler is called with an XML object
    		 *
    		 * @param _xmlReceivedHandler Function called when the selection is processed and the XML data is received.		 
    		 */
    		public function find(record_id:String,_xmlReceivedHandler:Function):void {
    			trace('UserController#find(record_id)')
    			var _vars:URLVariables = new URLVariables()
    			HttpClient.storeQueryPair(_vars,'record_id',record_id)
    			
    			var _urn:String = "user/service/find?" + _vars.toString()
    			new HttpClient("e4x").send_get(this._baseURL + _urn,_xmlReceivedHandler)
    		}
    		/**
    		 * Selection API function.  _xmlReceivedHandler is called with an XML object
    		 *
    		 * @param _xmlReceivedHandler Function called when the selection is processed and the XML data is received.		 
    		 */
    		public function getAllUsers(_xmlReceivedHandler:Function):void {
    			trace('UserController#getAllUsers()')
    			var _vars:URLVariables = new URLVariables()
    			
    			var _urn:String = "user/service/getAllUsers?" + _vars.toString()
    			new HttpClient("e4x").send_get(this._baseURL + _urn,_xmlReceivedHandler)
    		}
    		/**
    		 * Selection API function.  _xmlReceivedHandler is called with an XML object
    		 *
    		 * @param _xmlReceivedHandler Function called when the selection is processed and the XML data is received.		 
    		 */
    		public function listPage(from:String,to:String,sortkey:String,sortmethod:String,searchpattern:String,_xmlReceivedHandler:Function):void {
    			trace('UserController#listPage(from,to,sortkey,sortmethod,searchpattern)')
    			var _vars:URLVariables = new URLVariables()
    			HttpClient.storeQueryPair(_vars,'from',from)
    			HttpClient.storeQueryPair(_vars,'to',to)
    			HttpClient.storeQueryPair(_vars,'sortkey',sortkey)
    			HttpClient.storeQueryPair(_vars,'sortmethod',sortmethod)
    			HttpClient.storeQueryPair(_vars,'searchpattern',searchpattern)
    			
    			var _urn:String = "user/service/listPage?" + _vars.toString()
    			new HttpClient("e4x").send_get(this._baseURL + _urn,_xmlReceivedHandler)
    		}
    	
    	}
    }

Next

CallServiceFromFlex explains how to use the generated clients.


Sign in to add a comment
Powered by Google Project Hosting