Skip to content

Commit

Permalink
Merge pull request #65 from livechat/correct-handling-of-config-file
Browse files Browse the repository at this point in the history
Correct handling of config file
  • Loading branch information
skamieniarz authored Feb 16, 2022
2 parents aa62e2b + b4024cf commit 39dc926
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 84 deletions.
4 changes: 0 additions & 4 deletions configs/main.ini

This file was deleted.

32 changes: 21 additions & 11 deletions livechat/agent/rtm/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@

import typing
from abc import ABCMeta
from configparser import ConfigParser

from livechat.config import CONFIG
from livechat.utils.helpers import prepare_payload
from livechat.utils.structures import RtmResponse
from livechat.utils.ws_client import WebsocketClient

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
api_url = CONFIG.get('url')


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

def unfollow_chat(self, id: str = None, payload: dict = None) -> RtmResponse:
def unfollow_chat(self,
id: str = None,
payload: dict = None) -> RtmResponse:
''' Removes the requester from the chat followers.
Args:
Expand Down Expand Up @@ -601,7 +601,9 @@ def untag_thread(self,

# Customers

def get_customer(self, id: str = None, payload: dict = None) -> RtmResponse:
def get_customer(self,
id: str = None,
payload: dict = None) -> RtmResponse:
''' Returns the info about the Customer with a given ID.
Args:
Expand Down Expand Up @@ -718,7 +720,9 @@ def ban_customer(self,
payload = prepare_payload(locals())
return self.ws.send({'action': 'ban_customer', 'payload': payload})

def follow_customer(self, id: str = None, payload: dict = None) -> RtmResponse:
def follow_customer(self,
id: str = None,
payload: dict = None) -> RtmResponse:
''' Marks a customer as followed.
Args:
Expand All @@ -734,7 +738,9 @@ def follow_customer(self, id: str = None, payload: dict = None) -> RtmResponse:
payload = prepare_payload(locals())
return self.ws.send({'action': 'follow_customer', 'payload': payload})

def unfollow_customer(self, id: str = None, payload: dict = None) -> RtmResponse:
def unfollow_customer(self,
id: str = None,
payload: dict = None) -> RtmResponse:
''' Removes the agent from the list of customer's followers.
Args:
Expand Down Expand Up @@ -842,7 +848,9 @@ def set_routing_status(self,
'payload': payload
})

def set_away_status(self, away: bool = None, payload: dict = None) -> RtmResponse:
def set_away_status(self,
away: bool = None,
payload: dict = None) -> RtmResponse:
''' Sets an Agent's connection to the away state.
Args:
Expand Down Expand Up @@ -995,7 +1003,9 @@ class AgentRTM33(AgentRTMInterface):

# Chats

def deactivate_chat(self, id: str = None, payload: dict = None) -> RtmResponse:
def deactivate_chat(self,
id: str = None,
payload: dict = None) -> RtmResponse:
''' Deactivates a chat by closing the currently open thread.
Args:
Expand Down
8 changes: 3 additions & 5 deletions livechat/agent/web/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@

import typing
from abc import ABCMeta
from configparser import ConfigParser

import httpx

from livechat.config import CONFIG
from livechat.utils.helpers import prepare_payload
from livechat.utils.httpx_logger import HttpxLogger

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
api_url = CONFIG.get('url')


# pylint: disable=R0903
Expand Down
7 changes: 7 additions & 0 deletions livechat/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
''' Basic configuration module. '''

CONFIG = {
'url': 'api.livechatinc.com',
'stable': '3.4',
'dev': '3.5',
}
8 changes: 3 additions & 5 deletions livechat/configuration/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
from __future__ import annotations

from abc import ABCMeta
from configparser import ConfigParser

import httpx

from livechat.config import CONFIG
from livechat.utils.helpers import prepare_payload
from livechat.utils.httpx_logger import HttpxLogger

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
api_url = CONFIG.get('url')


class ConfigurationApi:
Expand Down
8 changes: 3 additions & 5 deletions livechat/customer/rtm/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
from __future__ import annotations

from abc import ABCMeta
from configparser import ConfigParser

from livechat.config import CONFIG
from livechat.utils.helpers import prepare_payload
from livechat.utils.structures import RtmResponse
from livechat.utils.ws_client import WebsocketClient

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
api_url = CONFIG.get('url')


class CustomerRTM:
Expand Down
8 changes: 3 additions & 5 deletions livechat/customer/web/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@

import typing
from abc import ABCMeta
from configparser import ConfigParser

import httpx

from livechat.config import CONFIG
from livechat.utils.helpers import prepare_payload
from livechat.utils.httpx_logger import HttpxLogger

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
api_url = CONFIG.get('url')


# pylint: disable=R0903
Expand Down
8 changes: 3 additions & 5 deletions livechat/reports/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
from __future__ import annotations

from abc import ABCMeta
from configparser import ConfigParser

import httpx

from livechat.config import CONFIG
from livechat.utils.helpers import prepare_payload
from livechat.utils.httpx_logger import HttpxLogger

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
api_url = CONFIG.get('url')


class ReportsApi:
Expand Down
9 changes: 3 additions & 6 deletions livechat/tests/test_agent_rtm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

# pylint: disable=E1120,W0621,C0103

from configparser import ConfigParser

import pytest

from livechat.agent.rtm.client import AgentRTM
from livechat.config import CONFIG

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
api_url = CONFIG.get('url')


def test_get_client_with_non_existing_version():
Expand Down
9 changes: 3 additions & 6 deletions livechat/tests/test_agent_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

# pylint: disable=E1120,W0621

from configparser import ConfigParser

import pytest

from livechat.agent.web.client import AgentWeb
from livechat.config import CONFIG

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
api_url = CONFIG.get('url')
ACCESS_TOKEN_INVALID = 'foo'


Expand Down
9 changes: 3 additions & 6 deletions livechat/tests/test_configuration_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

# pylint: disable=E1120,W0621

from configparser import ConfigParser

import pytest

from livechat.config import CONFIG
from livechat.configuration.client import ConfigurationApi

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
api_url = CONFIG.get('url')


@pytest.fixture
Expand Down
11 changes: 4 additions & 7 deletions livechat/tests/test_customer_rtm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

# pylint: disable=E1120,W0621,C0103

from configparser import ConfigParser

import pytest

from livechat.config import CONFIG
from livechat.customer.rtm.client import CustomerRTM

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
dev_version = config.get('api', 'dev')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
dev_version = CONFIG.get('dev')
api_url = CONFIG.get('url')

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

Expand Down
11 changes: 4 additions & 7 deletions livechat/tests/test_customer_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

# pylint: disable=E1120,W0621

from configparser import ConfigParser

import pytest

from livechat.config import CONFIG
from livechat.customer.web.client import CustomerWeb

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
dev_version = config.get('api', 'dev')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
dev_version = CONFIG.get('dev')
api_url = CONFIG.get('url')

ORGANIZATION_ID = '30007dab-4c18-4169-978d-02f776e476a5'
ACCESS_TOKEN_INVALID = 'foo'
Expand Down
9 changes: 3 additions & 6 deletions livechat/tests/test_reports_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

# pylint: disable=E1120,W0621

from configparser import ConfigParser

import pytest

from livechat.config import CONFIG
from livechat.reports.client import ReportsApi

config = ConfigParser()
config.read('configs/main.ini')
stable_version = config.get('api', 'stable')
api_url = config.get('api', 'url')
stable_version = CONFIG.get('stable')
api_url = CONFIG.get('url')


@pytest.fixture
Expand Down
9 changes: 3 additions & 6 deletions livechat/tests/test_ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

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

from configparser import ConfigParser

import pytest
import websocket

from livechat.config import CONFIG
from livechat.utils.ws_client import WebsocketClient

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


Expand Down

0 comments on commit 39dc926

Please sign in to comment.