Passed
Push — master ( 525f7c...1e26bf )
by Dave
01:15
created

backend.fcmservice   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 12

6 Methods

Rating   Name   Duplication   Size   Complexity  
A Configuration.is_enabled() 0 8 3
A InfrastructureService.__init__() 0 7 1
A Configuration.get() 0 4 2
A Configuration.__init__() 0 2 1
A Telegram.__init__() 0 3 1
A Telegram.sendtelegramphoto() 0 4 4
1
import os
2
3
class ServiceName:
4
    '''names of infrastructure services'''
5
    messagebus = 'rabbit'
6
    cache = 'redis'
7
    database = 'mysql'
8
    email = 'gmail'
9
    telegram = 'telegram'
10
11
class InfrastructureService:
12
    '''configuration for a dependency'''
13
    def __init__(self, name, connection, host, port, user, password):
14
        self.name = name
15
        self.connection = connection
16
        self.host = host
17
        self.port = port
18
        self.user = user
19
        self.password = password
20
21
class Configuration(object):
22
    def __init__(self, config):
23
        self.__config = config
24
25
    def get(self, key):
26
        if not key in self.__config:
27
            return None
28
        return self.__config[key]
29
30
    def is_enabled(self, key):
31
        lookupkey = '{0}.enabled'.format(key)
32
        if not lookupkey in self.__config:
33
            return False
34
        value = self.__config[lookupkey]
35
        if isinstance(value, str):
36
            return value == 'true' or value == 'True'
37
        return value
38
39
class Telegram(object):
40
    def __init__(self, config, service):
41
        self.configuration = config
42
        self.service = service
43
44
    def sendtelegramphoto(self, file_name):
45
        if os.path.isfile(file_name) and os.path.getsize(file_name) > 0:
46
            if self.configuration.is_enabled('telegram'):
47
                sendphoto(file_name, self.service)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable sendphoto does not seem to be defined.
Loading history...
48
49