Completed
Pull Request — master (#93)
by Koen
31s
created

capakey_factory()   B

Complexity

Conditions 4

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
dl 0
loc 38
rs 8.5806
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
'''
3
This module contains utility functions for interacting with AGIV SOAP services.
4
5
.. versionadded:: 0.1.0
6
'''
7
8
from __future__ import unicode_literals
9
10
import logging
11
log = logging.getLogger(__name__)
12
13
from suds.client import Client
14
15
16
def crab_factory(**kwargs):
17
    '''
18
    Factory that generates a CRAB client.
19
20
    A few parameters will be handled by the factory, other parameters will
21
    be passed on to the client.
22
23
    :param wsdl: `Optional.` Allows overriding the default CRAB wsdl url.
24
    :param proxy: `Optional.` A dictionary of proxy information that is passed
25
        to the underlying :class:`suds.client.Client`
26
    :rtype: :class:`suds.client.Client`
27
    '''
28
    if 'wsdl' in kwargs:
29
        wsdl = kwargs['wsdl']
30
        del kwargs['wsdl']
31
    else:
32
        wsdl = "http://crab.agiv.be/wscrab/wscrab.svc?wsdl"
33
    log.info('Creating CRAB client with wsdl: %s', wsdl)
34
    c = Client(
35
        wsdl,
36
        **kwargs
37
    )
38
    return c
39
40
41
def crab_request(client, action, *args):
42
    '''
43
    Utility function that helps making requests to the CRAB service.
44
45
    :param client: A :class:`suds.client.Client` for the CRAB service.
46
    :param string action: Which method to call, eg. `ListGewesten`
47
    :returns: Result of the SOAP call.
48
49
    .. versionadded:: 0.3.0
50
    '''
51
    log.debug('Calling %s on CRAB service.', action)
52
    return getattr(client.service, action)(*args)
53