Results 1 to 8 of 8

Thread: Zimbra and Ruby On Rails

  1. #1
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    10

    Default Zimbra and Ruby On Rails

    Hey guys, I am starting this thread to correspond to my development wiki pages up at http://wiki.zimbra.com/index.php?title=User:JoshPrismon . The goal of this project is to write a stand alone application that integrates in cleanly with Zimbra to provide basic time management (timecards, project creation/deletion, invoicing) for Zimbra.

    I decided to do this project as part of the Zimlet contest (although I was not happy with where the zimlet was when I submitted it at the deadline). I also don't want to put technical issues on wiki page until I understand them better.

    The idea is that I want the entire API to basically be REST and JSON. I prefer to skip soap simply because it is more complexity then I need, plus ruby does REST much better then SOAP.

    I am running into some problems however:

    a) The XMLRPC library really seems to have issues talking to rails. Rails completly rejects requests from Zimbra if no content is actually in the payload. So for example

    Code:
    Org_Technicaldetails_Projects.prototype._fetchProjects = function() {
    var url = ZmZimletBase.PROXY + arguments;
    var result=AjxRpc.invoke(null,url, null, null, false);
    Will always fail talking to Rail's built in Webrick server. You must have something in the first argument, even if it is just nonsense.

    Code:
    Org_Technicaldetails_Projects.prototype._fetchProjects = function() {
    var url = ZmZimletBase.PROXY + arguments;
    var result=AjxRpc.invoke("blah",url, null, null, false);
    Works

    b) Rails's to_json method that they added in the last release absolutly rocks. Basically once you have the request in your controller, do the magic to read the object from ActiveRecord, and then simply type:

    Code:
    @project = Project.find(params[:id])
    render :text=>@project.to_json
    Unfortunitly here we run into another problem with Webrick. Ruby on Rails has a built in method called respond_to that looks at the accept header to determine what type of information the front end wants. In particular if the front end wants json (or javascript), Ruby on rails wants the Accept: header to be text/javascript.

    Code:
    def list
        @projects = Project.find_all
        respond_to do |wants|
                    wants.html { render :text=>@projects.to_json }
                    wants.js   { render :text=>@projects.to_json }
                    wants.xml  { render :xml => @projects.to_xml }
        end
      end
    Unfortunitly, even when you construct a header that is correct and send it to the ruby on rails server, rails barfs of it and calls the wants.html. This means that we have to repeat ourself (the cardnial sin of the RoR world) and add more methods like view_ajax that only get called from the javascript front end. Non ideal.

    For whatever reason, Ruby on Rails also rejects paramaters passed in the body. This I suspect is easily fixed, but I have not figured out how.

    Code:
    Org_Technicaldetails_Projects.prototype._fetchProjects = function() {
    var url = ZmZimletBase.PROXY + arguments;
    var result=AjxRpc.invoke("id=23&name=Josh",url, null, null, false);
    Should work, but Ruby on Rails never picks up the arguments in the body itself.

  2. #2
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    10

    Default Trick - Get your treeitem for a zimlet in Ruby on Rails

    One of the features I really want is to have a user be able to drag their calender event, or email directly to a Treeitem, and have that be the only thing needed to add time to their project.

    Unfortunitly this isn't documented inside of the zimlet specification. It is how the treeitem is grabbed internally in the ZimletBase class, but it probably still is verboten. Use at your own risk.

    This code is also important because it shows you how to get the context. That allows you to get very useful things like the user's username and primary email address.


    Code:
    Org_Technicaldetails_Projects.prototype._getRootNode = function()
    {
     
           /// Note that the following code may suddenly combust into flames, 
           /// sparking a reaction that will end all life on earth. Not documented
           /// in the zimlet spec, so use at your own risk. 
     
            var appCtxt = this.getAppCtxt();
            var ctrl = appCtxt.getOverviewController();
    
            var treeView = ctrl.getTreeView(ZmZimbraMail._OVERVIEW_ID, ZmOrganizer.ZIMLET);
            _treeRootNode = treeView.getTreeItemById(this.xmlObj().getOrganizer().id);
            _treeRootNode.setText("This is my icon for my zimlet); 
    };

  3. #3
    Join Date
    Aug 2005
    Location
    San Mateo, CA
    Posts
    4,789
    Rep Power
    19

    Default

    FYI ... There was some other RoR work here:

    http://www.zimbra.com/forums/showthread.php?t=622
    Looking for new beta users -> Co-Founder of Acompli. Previously worked at Zimbra (and Yahoo! & VMware) since 2005.

  4. #4
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    10

    Default

    Quote Originally Posted by KevinH
    FYI ... There was some other RoR work here:

    http://www.zimbra.com/forums/showthread.php?t=622
    Yeah. I took a look at it. There were a couple of problems with it.
    1. Active Service is not nearly as well supported as the current REST based front end.
    2. Rails implemented their own to_json method which is cleaner then this method.


    I am goiing to keep on hacking away on this for right now, if nothing else to simply learn RoR

  5. #5
    Join Date
    Apr 2006
    Posts
    1
    Rep Power
    9

    Thumbs up Zimbra and Ruby On Rails

    Hello LostKnight,

    Wow! Your stuff is really rocking
    I would always love to mashup Zimbra stuff with a ROR application but don't find a good way.
    I have also a look at smies post, but it is outdate with the new funtionalities you find in Rails 1.1.x ( RESTFul, RJS, to_json, etc..).

    Lostknight, I am not a good developer but i can help to test and document..

    I have a trainee in my company till end of july who have already developped two small projects in ROR 1.0.
    Please let me know if he can join your project..
    Congrat for your idea.

    Cheers,

    Brice
    e-mail: bmk@inbizvision.com

  6. #6
    Join Date
    Mar 2006
    Posts
    21
    Rep Power
    9

    Default

    Hey Guys,

    I also use a RoR proxy server that feeds my Zimlet data. I haven't run into any troubles really. I did notice that the respond_to wasn't useful. I certainly would love an option to set AjxRpc to use different headers so that it did work. I ended up just creating actions specific to my data calls and didn't implement pure REST services. I also went with json for my data packing but I did use builder initially to send xml. I ultimately decided there was no good reason when I controlled both sides of the call to deal with xml. Json is just fine for my purposes.

    Cheers,
    Marty

  7. #7
    Join Date
    Aug 2005
    Location
    San Mateo, CA
    Posts
    4,789
    Rep Power
    19

    Default

    You can set AjxRpc headers like this:

    Code:
    var rpcId = AjxRpc.invoke(requestStr, uri, {"Content-Type": "application/soap+xml; charset=utf-8"}, rpcCallback);
    Looking for new beta users -> Co-Founder of Acompli. Previously worked at Zimbra (and Yahoo! & VMware) since 2005.

  8. #8
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    10

    Default

    Quote Originally Posted by KevinH
    You can set AjxRpc headers like this:

    Code:
    var rpcId = AjxRpc.invoke(requestStr, uri, {"Content-Type": "application/soap+xml; charset=utf-8"}, rpcCallback);

    Excellent. I will work that into the documentation!

Similar Threads

  1. SOAP & ruby ... Help needed
    By antonio.meireles in forum Developers
    Replies: 11
    Last Post: 09-27-2008, 01:27 PM
  2. Suggestion on Zimbra's Architecture
    By czaveri in forum Developers
    Replies: 2
    Last Post: 10-20-2006, 01:40 PM
  3. Ruby On Rails JSON webservice plugin
    By smies in forum Developers
    Replies: 2
    Last Post: 12-22-2005, 03:02 PM
  4. Support for Ruby or Python
    By CyberSynergies in forum Developers
    Replies: 2
    Last Post: 12-15-2005, 12:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •