Matsiya introduces the first AMF API for communication between Flash / Flex and Magento.

Magento provides a soap/xmlrpc, not bad ! Flex can play with this soap/xmlrpc api , not bad ! But what about perfomances ? Actually we think that amf is the best way for Flex/Flash communication. But one thing was missing : Zend_Amf. With the first release of this pretty good stuff, we jumped on the opportunity to write an AMF wrapper for the entire magento API. Done ! All the functions defined in your magento installation can now be called in the Flash/Flex environment by a “just one click” install of our plugin. More, it automatically translates custom api resources into Amf so there’s no need in boring configuration files. Interested ? we will post an “how to” in the next few days. Stay tuned !

Something’s Happening…

Adobe Flex 4 - Ryan Stewart and Matt Chotin

Ryan Stewart starting a new show on Adobe TV called Tech Talk with Ryan Stewart. In his first episode he chat with Matt Chotin about new features in Flex 4 …

SOAP Rails + Flex and typed objects

Ruby on Rails gives the opportunity to build SOAP webservices in few lines. But as Ruby is a dynamic language, we have to define manually the types for inputs and outputs. From the point of view of Flex there is no problem to recover simple types as String, Integer, Datetime… etc. But how can we recover a more complex object ?
In the previous post we have introduced SchemaTypeRegistry which allows recovering personalized objects in Flex; no problems for services written in Java or C#, objects created with theses languages will be correctly defined in the wsdl and Flex will understand them without problems. However, we can imagine that we have a Ruby model called User, which point to the table users. Recovering this object in the SOAP, Flex will not be capable to understand it because none of its properties is explicitly defined.
A solution to this problem exists yet: ActionWebService::Struct. In defining a model inheriting from this class we could build a “package” of our based model and define these properties into it.

Example for a User model :
We define the UserStruct < ActionWebService::Struct > model and we add the properties :

class UserStruct
member :name, :string
member :pass, :string
end

and in our API class we specify the return as :

:returns =&gt; [{:answer =&gt;UserStruct}]

As Ruby is totally dynamic we can directly resend a User object in the controller, which one will be automatically transformed into a UserStruct. Example of a method in the controller :

def getUser(id)
User.find(id)
end

The received object will then be typed as userstruct (lowercase in the XML) and will contain all the values of User if they have been correctly defined.
Finally for a better readability we can name our object “User” in Flex too and specify the changed of the name in SchemaTypeRegistry (see previous post).

SOAP + Flex => SchemaTypeRegistry

There’s a Flex 3 feature that seems to have been unnoticed: the possibility to receive strongly typed objects from a SOAP service as we could do through the AMF protocol. Everything is done in the singleton class SchemaTypeRegistry. We just have to give the received object name, its namespace in the SOAP envelope and the destination class. A short example is better than a long speech: try to imagine that we want to map an object called user with the namespace http://www.matsiya.fr/user to the User class. We have just to add in the application (mapping will then concern all the services):

SchemaTypeRegistry.getInstance().registerClass(new
QName("http://www.matsiya.fr/user", "user"), User);

It’s also possible to define the SchemaTypeRegistry for a specific operation into the XMLDecoder:

var sr:SchemaTypeRegistry = new SchemaTypeRegistry();
sr.registerClass(new
QName("http://www.mastiya.fr/user", "user"), User);
op.decoder.typeRegistry = sr;
//op étant notre operation

It’s strange that Adobe don’t communicate on this feature, the documentation is virtually inexistent and especially on all that could concern XMLDecoder. Unfortunately, this method can just be used with SOAP services, to my knowledge it’s impossible to force the decoding of an external XML file or a REST service result through the XMLDecoder.