| Welcome to the Zimbra - Forums! | |
Welcome, if you would like to post a comment in the forums, please register and review our posting policy & tips.
We also encourage you to explore all things Zimbra with our team and members of the community.
|  | | 
11-18-2005, 10:04 AM
| | | 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 01:31 PM.
| 
11-19-2005, 07:04 AM
| | | 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. | 
11-19-2005, 08:31 AM
| | | 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 | 
11-20-2005, 07:40 AM
| | | 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. | 
11-21-2005, 11:22 AM
| | | 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 11:26 AM.
| 
11-21-2005, 04:25 PM
| | | 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. | 
02-16-2006, 07:10 PM
| | | 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.  | 
02-17-2006, 02:15 AM
| | | 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 02:12 PM.
| 
08-01-2006, 02:57 PM
| | | 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 | 
08-10-2006, 08:51 PM
| | Zimbra Employee | |
Posts: 4,784
| | Sounds cool Marty. If you want you can setup a spot on the wiki to post details and code drops. | | Thread Tools | | | | Display Modes | Linear Mode | | Why Join? Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.  |