Skip to content

Commit 39dc926

Browse files
authored
Merge pull request #65 from livechat/correct-handling-of-config-file
Correct handling of config file
2 parents aa62e2b + b4024cf commit 39dc926

15 files changed

+66
-84
lines changed

configs/main.ini

Lines changed: 0 additions & 4 deletions
This file was deleted.

livechat/agent/rtm/client.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55

66
import typing
77
from abc import ABCMeta
8-
from configparser import ConfigParser
98

9+
from livechat.config import CONFIG
1010
from livechat.utils.helpers import prepare_payload
1111
from livechat.utils.structures import RtmResponse
1212
from livechat.utils.ws_client import WebsocketClient
1313

14-
config = ConfigParser()
15-
config.read('configs/main.ini')
16-
stable_version = config.get('api', 'stable')
17-
api_url = config.get('api', 'url')
14+
stable_version = CONFIG.get('stable')
15+
api_url = CONFIG.get('url')
1816

1917

2018
class AgentRTM:
@@ -244,7 +242,9 @@ def follow_chat(self, id: str = None, payload: dict = None) -> RtmResponse:
244242
payload = prepare_payload(locals())
245243
return self.ws.send({'action': 'follow_chat', 'payload': payload})
246244

247-
def unfollow_chat(self, id: str = None, payload: dict = None) -> RtmResponse:
245+
def unfollow_chat(self,
246+
id: str = None,
247+
payload: dict = None) -> RtmResponse:
248248
''' Removes the requester from the chat followers.
249249
250250
Args:
@@ -601,7 +601,9 @@ def untag_thread(self,
601601

602602
# Customers
603603

604-
def get_customer(self, id: str = None, payload: dict = None) -> RtmResponse:
604+
def get_customer(self,
605+
id: str = None,
606+
payload: dict = None) -> RtmResponse:
605607
''' Returns the info about the Customer with a given ID.
606608
607609
Args:
@@ -718,7 +720,9 @@ def ban_customer(self,
718720
payload = prepare_payload(locals())
719721
return self.ws.send({'action': 'ban_customer', 'payload': payload})
720722

721-
def follow_customer(self, id: str = None, payload: dict = None) -> RtmResponse:
723+
def follow_customer(self,
724+
id: str = None,
725+
payload: dict = None) -> RtmResponse:
722726
''' Marks a customer as followed.
723727
724728
Args:
@@ -734,7 +738,9 @@ def follow_customer(self, id: str = None, payload: dict = None) -> RtmResponse:
734738
payload = prepare_payload(locals())
735739
return self.ws.send({'action': 'follow_customer', 'payload': payload})
736740

737-
def unfollow_customer(self, id: str = None, payload: dict = None) -> RtmResponse:
741+
def unfollow_customer(self,
742+
id: str = None,
743+
payload: dict = None) -> RtmResponse:
738744
''' Removes the agent from the list of customer's followers.
739745
740746
Args:
@@ -842,7 +848,9 @@ def set_routing_status(self,
842848
'payload': payload
843849
})
844850

845-
def set_away_status(self, away: bool = None, payload: dict = None) -> RtmResponse:
851+
def set_away_status(self,
852+
away: bool = None,
853+
payload: dict = None) -> RtmResponse:
846854
''' Sets an Agent's connection to the away state.
847855
848856
Args:
@@ -995,7 +1003,9 @@ class AgentRTM33(AgentRTMInterface):
9951003

9961004
# Chats
9971005

998-
def deactivate_chat(self, id: str = None, payload: dict = None) -> RtmResponse:
1006+
def deactivate_chat(self,
1007+
id: str = None,
1008+
payload: dict = None) -> RtmResponse:
9991009
''' Deactivates a chat by closing the currently open thread.
10001010
10011011
Args:

livechat/agent/web/client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55

66
import typing
77
from abc import ABCMeta
8-
from configparser import ConfigParser
98

109
import httpx
1110

11+
from livechat.config import CONFIG
1212
from livechat.utils.helpers import prepare_payload
1313
from livechat.utils.httpx_logger import HttpxLogger
1414

15-
config = ConfigParser()
16-
config.read('configs/main.ini')
17-
stable_version = config.get('api', 'stable')
18-
api_url = config.get('api', 'url')
15+
stable_version = CONFIG.get('stable')
16+
api_url = CONFIG.get('url')
1917

2018

2119
# pylint: disable=R0903

livechat/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
''' Basic configuration module. '''
2+
3+
CONFIG = {
4+
'url': 'api.livechatinc.com',
5+
'stable': '3.4',
6+
'dev': '3.5',
7+
}

livechat/configuration/client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
from __future__ import annotations
55

66
from abc import ABCMeta
7-
from configparser import ConfigParser
87

98
import httpx
109

10+
from livechat.config import CONFIG
1111
from livechat.utils.helpers import prepare_payload
1212
from livechat.utils.httpx_logger import HttpxLogger
1313

14-
config = ConfigParser()
15-
config.read('configs/main.ini')
16-
stable_version = config.get('api', 'stable')
17-
api_url = config.get('api', 'url')
14+
stable_version = CONFIG.get('stable')
15+
api_url = CONFIG.get('url')
1816

1917

2018
class ConfigurationApi:

livechat/customer/rtm/client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
from __future__ import annotations
66

77
from abc import ABCMeta
8-
from configparser import ConfigParser
98

9+
from livechat.config import CONFIG
1010
from livechat.utils.helpers import prepare_payload
1111
from livechat.utils.structures import RtmResponse
1212
from livechat.utils.ws_client import WebsocketClient
1313

14-
config = ConfigParser()
15-
config.read('configs/main.ini')
16-
stable_version = config.get('api', 'stable')
17-
api_url = config.get('api', 'url')
14+
stable_version = CONFIG.get('stable')
15+
api_url = CONFIG.get('url')
1816

1917

2018
class CustomerRTM:

livechat/customer/web/client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55

66
import typing
77
from abc import ABCMeta
8-
from configparser import ConfigParser
98

109
import httpx
1110

11+
from livechat.config import CONFIG
1212
from livechat.utils.helpers import prepare_payload
1313
from livechat.utils.httpx_logger import HttpxLogger
1414

15-
config = ConfigParser()
16-
config.read('configs/main.ini')
17-
stable_version = config.get('api', 'stable')
18-
api_url = config.get('api', 'url')
15+
stable_version = CONFIG.get('stable')
16+
api_url = CONFIG.get('url')
1917

2018

2119
# pylint: disable=R0903

livechat/reports/client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
from __future__ import annotations
66

77
from abc import ABCMeta
8-
from configparser import ConfigParser
98

109
import httpx
1110

11+
from livechat.config import CONFIG
1212
from livechat.utils.helpers import prepare_payload
1313
from livechat.utils.httpx_logger import HttpxLogger
1414

15-
config = ConfigParser()
16-
config.read('configs/main.ini')
17-
stable_version = config.get('api', 'stable')
18-
api_url = config.get('api', 'url')
15+
stable_version = CONFIG.get('stable')
16+
api_url = CONFIG.get('url')
1917

2018

2119
class ReportsApi:

livechat/tests/test_agent_rtm_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
# pylint: disable=E1120,W0621,C0103
44

5-
from configparser import ConfigParser
6-
75
import pytest
86

97
from livechat.agent.rtm.client import AgentRTM
8+
from livechat.config import CONFIG
109

11-
config = ConfigParser()
12-
config.read('configs/main.ini')
13-
stable_version = config.get('api', 'stable')
14-
api_url = config.get('api', 'url')
10+
stable_version = CONFIG.get('stable')
11+
api_url = CONFIG.get('url')
1512

1613

1714
def test_get_client_with_non_existing_version():

livechat/tests/test_agent_web_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
# pylint: disable=E1120,W0621
44

5-
from configparser import ConfigParser
6-
75
import pytest
86

97
from livechat.agent.web.client import AgentWeb
8+
from livechat.config import CONFIG
109

11-
config = ConfigParser()
12-
config.read('configs/main.ini')
13-
stable_version = config.get('api', 'stable')
14-
api_url = config.get('api', 'url')
10+
stable_version = CONFIG.get('stable')
11+
api_url = CONFIG.get('url')
1512
ACCESS_TOKEN_INVALID = 'foo'
1613

1714

livechat/tests/test_configuration_api_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
# pylint: disable=E1120,W0621
44

5-
from configparser import ConfigParser
6-
75
import pytest
86

7+
from livechat.config import CONFIG
98
from livechat.configuration.client import ConfigurationApi
109

11-
config = ConfigParser()
12-
config.read('configs/main.ini')
13-
stable_version = config.get('api', 'stable')
14-
api_url = config.get('api', 'url')
10+
stable_version = CONFIG.get('stable')
11+
api_url = CONFIG.get('url')
1512

1613

1714
@pytest.fixture

livechat/tests/test_customer_rtm_client.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
# pylint: disable=E1120,W0621,C0103
44

5-
from configparser import ConfigParser
6-
75
import pytest
86

7+
from livechat.config import CONFIG
98
from livechat.customer.rtm.client import CustomerRTM
109

11-
config = ConfigParser()
12-
config.read('configs/main.ini')
13-
stable_version = config.get('api', 'stable')
14-
dev_version = config.get('api', 'dev')
15-
api_url = config.get('api', 'url')
10+
stable_version = CONFIG.get('stable')
11+
dev_version = CONFIG.get('dev')
12+
api_url = CONFIG.get('url')
1613

1714
ORGANIZATION_ID = '30007dab-4c18-4169-978d-02f776e476a5'
1815

livechat/tests/test_customer_web_client.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
# pylint: disable=E1120,W0621
44

5-
from configparser import ConfigParser
6-
75
import pytest
86

7+
from livechat.config import CONFIG
98
from livechat.customer.web.client import CustomerWeb
109

11-
config = ConfigParser()
12-
config.read('configs/main.ini')
13-
stable_version = config.get('api', 'stable')
14-
dev_version = config.get('api', 'dev')
15-
api_url = config.get('api', 'url')
10+
stable_version = CONFIG.get('stable')
11+
dev_version = CONFIG.get('dev')
12+
api_url = CONFIG.get('url')
1613

1714
ORGANIZATION_ID = '30007dab-4c18-4169-978d-02f776e476a5'
1815
ACCESS_TOKEN_INVALID = 'foo'

livechat/tests/test_reports_api_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
# pylint: disable=E1120,W0621
44

5-
from configparser import ConfigParser
6-
75
import pytest
86

7+
from livechat.config import CONFIG
98
from livechat.reports.client import ReportsApi
109

11-
config = ConfigParser()
12-
config.read('configs/main.ini')
13-
stable_version = config.get('api', 'stable')
14-
api_url = config.get('api', 'url')
10+
stable_version = CONFIG.get('stable')
11+
api_url = CONFIG.get('url')
1512

1613

1714
@pytest.fixture

livechat/tests/test_ws_client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
# pylint: disable=E1120,W0621,C0103,R1702
44

5-
from configparser import ConfigParser
6-
75
import pytest
86
import websocket
97

8+
from livechat.config import CONFIG
109
from livechat.utils.ws_client import WebsocketClient
1110

12-
config = ConfigParser()
13-
config.read('configs/main.ini')
14-
stable_version = config.get('api', 'stable')
15-
api_url = config.get('api', 'url')
11+
stable_version = CONFIG.get('stable')
12+
api_url = CONFIG.get('url')
1613
query_string = 'organization_id=30007dab-4c18-4169-978d-02f776e476a5'
1714

1815

0 commit comments

Comments
 (0)