Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: SOAP & ruby ... Help needed

  1. #1
    antonio.meireles is offline Active Member
    Join Date
    Oct 2005
    Posts
    25
    Rep Power
    9

    Default Zimbra server/SOAP & ruby ... Help needed

    To the ruby/soap experts around...

    How do i control/model the unmarshalling behaviour of the Zimbra SOAP response in the code snippet bellow in order to get not an array with (only) the 'values' on zimbra, but an hash with pairs (variable, value) ?


    Code:
    #!/usr/bin/ruby
    require 'soap/rpc/driver'
    require 'soap/driver'
    require 'soap/header/simplehandler'
    
    class ClientAuthHeaderHandler < SOAP::Header::SimpleHandler
        MyHeaderName = XSD::QName.new("urn:zimbra", "context")
        
        def initialize(sessionid = nil, authtoken = nil)
          super(MyHeaderName)
          @sessionid = sessionid
          @authtoken = authtoken       
        end
        
        def on_simple_outbound
          if @sessionid
            { "sessionId" => @sessionid, "authToken" => @authtoken }
          end     
        end 
    end
    
    drv = SOAP::RPC::Driver.new('https://zimbra:7071/service/admin/soap/', 'urn:zimbraAdmin')
    
    drv.wiredump_dev = STDERR  #if $DEBUG
    drv.options["protocol.http.ssl_config.verify_mode"] = nil 
    drv.add_method('GetAllAdminAccountsRequest')
    drv.add_method('AuthRequest',"name", "password")
    
    token, lifetime, sessionid = drv.AuthRequest('admin@zimbra,'zimbra')
    drv.headerhandler << ClientAuthHeaderHandler.new(sessionid, token) 
    
    response = drv.__send__(:GetAllAdminAccountsRequest)
    p response
    p response.a
    Thanxs in advance and best regards... Have a nice weekend
    Last edited by antonio.meireles; 11-18-2005 at 02:31 PM.

  2. #2
    smies is offline Senior Member
    Join Date
    Oct 2005
    Location
    Urmond, Netherlands
    Posts
    51
    Rep Power
    9

    Default

    I am using Ruby on Rails together with Zimbra and till now it's a great success. I already posted something about it, because I made a plugin for RoR that lets the webservice return JSON instead of SOAP. I have no problems with retrieving any key/value pairs of data. Also more complex data structure are no problem: array of structs and those structs contain structs . Maybe this is also an idea for you.

    Next week I will probably post some articles about the communication between ZimbraTK and Ruby On Rails. You will find these articles on my fairly new technical blog: www.smies.com.

  3. #3
    antonio.meireles is offline Active Member
    Join Date
    Oct 2005
    Posts
    25
    Rep Power
    9

    Default

    Quote Originally Posted by smies
    I am using Ruby on Rails together with Zimbra and till now it's a great success. I already posted something about it, because I made a plugin for RoR that lets the webservice return JSON instead of SOAP. I have no problems with retrieving any key/value pairs of data. Also more complex data structure are no problem: array of structs and those structs contain structs . Maybe this is also an idea for you.

    Next week I will probably post some articles about the communication between ZimbraTK and Ruby On Rails. You will find these articles on my fairly new technical blog: www.smies.com.
    Could you please provide a quick exeample of rails/ror SOAP/JSON interaction with zimbra… Fetch a request/changing a value from/to zimbra server?

    TIA

    Have a nice weekend. All the best

  4. #4
    smies is offline Senior Member
    Join Date
    Oct 2005
    Location
    Urmond, Netherlands
    Posts
    51
    Rep Power
    9

    Default

    I would like to provide you with a quick example but I don't have the time right now. Tomorrow I am going to write the article about this topic, so you will have to wait till then.

  5. #5
    bhwang is offline Zimbra Employee
    Join Date
    Sep 2005
    Posts
    6
    Rep Power
    9

    Default SOAP & ruby

    One way to achieve this is to use soap document style encoding. This basically means that the code will get the raw xml structure back and has to do its own parsing.

    Here is an example on how to do that, following the same code


    Code:
    ...
    
    def GetNamePair(response)
      response.account.each do |x| 
        class << x
          attr :configuration, true    
        end     
        x.configuration = Hash[*x.a.map do |y|
          [y.__xmlattr[XSD::QName.new(nil, 'n')], String.new(y)]
        end.flatten] 
      end
    end
    
    mNS = 'urn:zimbraAdmin'
    drv.add_document_method('GetAllAdminAccountsRequest', mNS, [XSD::QName.new(mNS, 'GetAllAdminAccountsRequest')],  
      [XSD::QName.new(mNS, 'GetAllAdminAccountsResponse')] )  
    
    puts YAML.dump(GetNamePair(drv.GetAllAdminAccountsRequest([]))
    Last edited by bhwang; 11-21-2005 at 12:26 PM.

  6. #6
    smies is offline Senior Member
    Join Date
    Oct 2005
    Location
    Urmond, Netherlands
    Posts
    51
    Rep Power
    9

    Default Done, finally

    I am finally done with the article. I hope that it is readable, because my English grammer isn't really great. Take a look at www.smies.com. It also contains a complete RoR project with working example code.

  7. #7
    Aaron Hawkins is offline Starter Member
    Join Date
    Feb 2006
    Posts
    1
    Rep Power
    9

    Question Problem creating new accounts

    I can create new accounts - using the code in this thread as a starting point. My problem is that I can only seem to specify the username and password using soap. I can't seem to figure out how to let zimbra know that I want to also set the display name, cos, first name, last name, and the other options.

    I know from reading the soap.txt that the create account request needs the following format:
    Code:
    <CreateAccountRequest>
      <name>...</name>
      <password>...</password>*
      <a n="attr-name>...</a>+
    </CreateAccountRequest>
    I can't figure out how to use ruby to pass information in that format for the <a n="attr-name"> elements.

    I've tried a hash, an array, but the information is just ignored (the account is created but with only the username and password).

    I'm sure that I could just use ruby to generate the expected soap xml call - but that seems silly.

    Many of the examples for using soap with ruby are based on accessing sites that have published a wsdl - so + on the need for a wsdl. (I know that was discussed in a previous post).

    Any help would be appreciated.

  8. #8
    bhwang is offline Zimbra Employee
    Join Date
    Sep 2005
    Posts
    6
    Rep Power
    9

    Default

    Here is one way to do this.

    Code:
    require 'soap/rpc/driver'  
    
     
    class A < SOAP::SOAPRawString 
      attr :extraattr, true      
      def initialize(name, value)
        super(value)
        @extraattr = {"n" => name}
      end
    end
    
    class CreateAccountRequest
       @@schema_element = [["name", "SOAP::SOAPString"], ["password", "SOAP::SOAPString"], ["a", "A[]"]]
      
      attr_accessor :name
      attr_accessor :password
      attr_accessor :a 
     
      
      def initialize(name = nil, password = nil, a = [])
        @name = name
        @password = password
        @a = a  
      end  
    end
    
    
    s = SOAP::RPC::Driver.new('https://zimbra:7071/service/admin/soap/', 
    'urn:zimbraAdmin') 
    s.options["protocol.http.ssl_config.verify_mode"] = nil 
    mNS = 'urn:zimbraAdmin'
    s.add_document_method('CreateAccountRequest', 'CreateAccountRequest', 
       [XSD::QName.new(mNS, 'CreateAccountRequest')], 
       [XSD::QName.new(mNS, 'CreateAccoutnResponse')])
    s.wiredump_dev = $stdout
    
    puts YAML.dump(s.CreateAccountRequest(
        CreateAccountRequest.new('a','b',[A.new('23','4'), A.new('45','4')])
    This will produce soap request

    Code:
    <?xml version="1.0" encoding="us-ascii" ?>
    <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <env:Body>
        <CreateAccountRequest xmlns="urn:zimbraAdmin">
          <name>a</name>
          <a n="23">4</a>
          <a n="45">4</a>
          <password>b</password>
        </CreateAccountRequest>
      </env:Body>
    </env:Envelope>
    Last edited by bhwang; 02-17-2006 at 03:12 PM.

  9. #9
    mghaught is offline Intermediate Member
    Join Date
    Mar 2006
    Posts
    21
    Rep Power
    9

    Default

    Hey Guys,

    I've started work on a ruby client for talking to the Zimbra soap api. Has anyone done anymore work on this area since this last post? I've successfully got admin login and account creation working but I'm not getting soap4r to return a useful response that I can look into (such as confirm details about the newly created account). I'll also be venturing into interfacing with the contact lists and mail sending api.

    When I'm done, I'll be happy to bundle up what I've written for others to use.

    Cheers,
    Marty

  10. #10
    KevinH's Avatar
    KevinH is offline Expert Member
    Join Date
    Aug 2005
    Location
    San Mateo, CA
    Posts
    4,789
    Rep Power
    19

    Default

    Sounds cool Marty. If you want you can setup a spot on the wiki to post details and code drops.
    Looking for new beta users -> Co-Founder of Acompli. Previously worked at Zimbra (and Yahoo! & VMware) since 2005.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. XSD/WSDL Files for the SOAP Server?
    By photoadrian in forum Developers
    Replies: 5
    Last Post: 12-23-2012, 02:32 AM
  2. Jar For Soap Client
    By wcameron in forum Developers
    Replies: 19
    Last Post: 06-03-2009, 02:04 PM
  3. Bug with preauth mechanism and SOAP headers?
    By Coilcore in forum Developers
    Replies: 3
    Last Post: 07-20-2006, 10:41 AM
  4. Zimbra and Ruby On Rails
    By JoshuaPrismon in forum Developers
    Replies: 7
    Last Post: 05-09-2006, 05:01 PM
  5. Ruby On Rails JSON webservice plugin
    By smies in forum Developers
    Replies: 2
    Last Post: 12-22-2005, 03:02 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
  •