Zimbra server/SOAP & ruby ... Help needed

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
antonio.meireles
Posts: 25
Joined: Fri Sep 12, 2014 9:56 pm

Zimbra server/SOAP & ruby ... Help needed

Postby antonio.meireles » Fri Nov 18, 2005 12:04 pm

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) ?


#!/usr/bin/ruby

require 'soap/rpc/driver'

require 'soap/driver'

require 'soap/header/simplehandler'
class ClientAuthHeaderHandler
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 <
response = drv.__send__(:GetAllAdminAccountsRequest)

p response

p response.a


Thanxs in advance and best regards... Have a nice weekend


smies
Posts: 45
Joined: Fri Sep 12, 2014 9:58 pm

Zimbra server/SOAP & ruby ... Help needed

Postby smies » Sat Nov 19, 2005 9: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: http://www.smies.com.
antonio.meireles
Posts: 25
Joined: Fri Sep 12, 2014 9:56 pm

Zimbra server/SOAP & ruby ... Help needed

Postby antonio.meireles » Sat Nov 19, 2005 10:31 am

[quote user="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:
Could">http://www.smies.com.[/QUOTE]
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
smies
Posts: 45
Joined: Fri Sep 12, 2014 9:58 pm

Zimbra server/SOAP & ruby ... Help needed

Postby smies » Sun Nov 20, 2005 9: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.
bhwang
Posts: 5
Joined: Fri Sep 12, 2014 9:55 pm

Zimbra server/SOAP & ruby ... Help needed

Postby bhwang » Mon Nov 21, 2005 1:22 pm

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




...
def GetNamePair(response)

response.account.each do |x|

class <
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([]))

smies
Posts: 45
Joined: Fri Sep 12, 2014 9:58 pm

Zimbra server/SOAP & ruby ... Help needed

Postby smies » Mon Nov 21, 2005 6:25 pm

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 http://www.smies.com. It also contains a complete RoR project with working example code.
Aaron Hawkins
Posts: 1
Joined: Fri Sep 12, 2014 10:05 pm

Zimbra server/SOAP & ruby ... Help needed

Postby Aaron Hawkins » Thu Feb 16, 2006 9:10 pm

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:



...

...*

...+


I can't figure out how to use ruby to pass information in that format for the 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. :)
bhwang
Posts: 5
Joined: Fri Sep 12, 2014 9:55 pm

Zimbra server/SOAP & ruby ... Help needed

Postby bhwang » Fri Feb 17, 2006 4:15 am

Here is one way to do this.





require 'soap/rpc/driver'


class A
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


http://www.w3.org/2001/XMLSchema"

xmlns:env=http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance">





a

4

4

b





mghaught
Posts: 21
Joined: Fri Sep 12, 2014 10:06 pm

Zimbra server/SOAP & ruby ... Help needed

Postby mghaught » Tue Aug 01, 2006 4: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
14319KevinH
Ambassador
Ambassador
Posts: 4558
Joined: Fri Sep 12, 2014 9:52 pm

Zimbra server/SOAP & ruby ... Help needed

Postby 14319KevinH » Thu Aug 10, 2006 10:51 pm

Sounds cool Marty. If you want you can setup a spot on the wiki to post details and code drops.

Return to “Developers”

Who is online

Users browsing this forum: No registered users and 4 guests