Contribution Libre Développement Ruby 2014 | 06 | 19

Bintje an OpenObject XMLRPC ruby client

Few month ago, I released Bintje, a minimal interface to OpenERP’s xmlrpc API. It is available on github, as a ruby gem, and can be included in the ruby class of your choice (as a Rails model for example).

It still an early version, but is usable in production.

Why Bintje ?

So why it is named Bintje ? Because it is part of a bigger piece of architecture called “Barakafrites” which in french means this :

baraque a frites

Yes, they sell “french fries”.

Bintje is potato variety used for french fries (and have it’s own dedicated character).

Now you clearly understand why this project is called Bintje … ( Just kidding … )

Using Bintje

First it needs OpenERP / OpenObject backend address, an example setup :

## It is up to you to define how you load config ( initilizer ,  config object, yaml file ... )
## Bintje supports the options below ( but common and object are pointless now ... ) = 'localhost'
OpenObject.port = '8069'
OpenObject.common = '/xmlrpc/common'
OpenObject.object = '/xmlrpc/object'
OpenObject.logger =

Then create a Ruby Class, it could be Rails model if you want :

 class OpenObject::Partner
   include OpenObjectModel 
   set_open_object_model 'res.partner'
   ## Where user context is the trinity : {uid: Int , dbname: String , pwd: String}
   def my_custom_method(user_context)
     OpenObject.rescue_xmlrpc_fault do
       response = self.class.connection(user_context).execute(self.class.open_object_model, 'remoteOpenObjectMethod', true, content: response)

This class inherits the CRUD basic methods, and have an example of custom method declaration.

You first need to include the module, once done your class will inherit module’s class methods (see documentation), and gain the open_object_model class variable which is inferred from your ruby object name, but can be overriden as you can see in this gist above.

Then you can query the OpenObject Backend and obtain a BackendResponse Object (see documentation):

## Search for a partner:
resps ={uid: 3, dbname: "example", pwd: "example_pwd"}, [["name", "=", "The World Compagny"]

if resps.success
    puts resps.content
else puts resps.errors

## Create a partner ...
Partner.create({uid: 3, dbname: "example", pwd: "example_pwd"},{name:"Through Voidness ..."})

Yes it is that simple …

To get more methods, have a look to the documentation.

The behaviour specifications extracted from Rspec tests.