Creating a new Providerbackend for Iro

See also class documentation iro.offer.provider.Provider.

A very simple provider

For testing purpose it is nice to create a small provider.

1
2
3
4
5
6
7
from iro.offer import providers, Provider

class TestProvider(Provider):
    def __init__(self,name):
        Provider.__init__(self, name, {"sms" : ["a",]})

providers["myveryspecialProvider"] = TestProvider
  • line 3 – a Provider that supports message type sms, and has one route named a.

  • line 5 – register the provider type TestProvider in the global providers dict. Following section in configuraton file will create a new TestProvider object, with name="blablub":

    [blablub]
    #see line 5
    typ = myveryspecialProvider
    

Normally a new Provider wants to have extra options for configuration file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from iro.offer import providers, Provider
from iro.config import Option

def validater(value, field):
    return value

class TestProvider(Provider):
    def __init__(self,name):
        options =[("key", Option(validater,long="My Option explanation", must=True)),]
        Provider.__init__(self, name, {"sms" : ["a",]}, options)

providers["myveryspecialProvider"] = TestProvider

in line 9 we create a item list ( [(name,Option),...] – more information about iro.config.Option). validater have to be a function that returns value, if the value is valid. With this following section in configuration file is possible:

[balblub]
typ = myveryspecialProvider
#My Option explanation
key = mykey

Ok, now we know to get settings into the provider. But we have to do anything, when user want to send anything. So we have to create a send function.

Creating sipgate provider

Sipgate supports sending sms and faxes via XML-RPC. so it is easy to create a new providerbackend for iro via sipgate. First we get the XML-RPC Api documention for sipgate (http://www.sipgate.de/beta/public/static/downloads/basic/api/sipgate_api_documentation.pdf). Sipgate uses HTTP Basic Authentification, that’s we he create to options for our sipgate provider:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from iro.offer import providers, Provider
from iro.config import Option

class Sipgate(Provider):
    def __init__(self,name):
        options =[("username", Option(lambda x,y: x,long="Loginname for sipgate", must=True)),
                  ("password", Option(lambda x,y: x,long="Password for sipgate", must=True)),]
        Provider.__init__(self, name, {"sms" : [None], "fax":[None]}, options)

providers["sipgate"] = Sipgate
  • line 6/7 – we don’t have any ideas what is allowed as username/password, so we create a validator that accepts everything.
  • line 8 – sipgate supports fax and sms, but now diffrent routes, that’s we use None.

Now we have to possible options to implement the send function. either we implement a blocking interface or use the recommended solution: twisted non blocking solution. We show here the recommended version.

Table Of Contents

Previous topic

Installation of Iro

This Page