@@ -29,7 +29,9 @@ <h1 class="title">Module <code>client</code></h1>
29
29
</ summary >
30
30
< pre > < code class ="python "> ''' Customer RTM client implementation. '''
31
31
32
- # pylint: disable=W0613,W0622,C0103,R0913,R0903,W0107
32
+ # pylint: disable=W0613,W0622,C0103,R0913,R0903,W0107,W0231
33
+
34
+ from __future__ import annotations
33
35
34
36
from abc import ABCMeta
35
37
@@ -42,39 +44,46 @@ <h1 class="title">Module <code>client</code></h1>
42
44
@staticmethod
43
45
def get_client(license_id: int = None,
44
46
version: str = '3.3',
45
- base_url: str = 'api.livechatinc.com'):
47
+ base_url: str = 'api.livechatinc.com',
48
+ organization_id: str = None) -> CustomerRTMInterface:
46
49
''' Returns client for specific Customer RTM version.
47
50
48
51
Args:
49
- license_id (int): License ID.
52
+ license_id (int): License ID. Required to use API v3.3.
50
53
version (str): API's version. Defaults to `3.3`.
51
54
base_url (str): API's base url. Defaults to `api.livechatinc.com`.
55
+ organization_id (str): Organization ID, replaced license ID in v3.4.
52
56
53
57
Returns:
54
58
CustomerRTMInterface: API client object for specified version.
55
59
56
60
Raises:
57
61
ValueError: If the specified version does not exist.
58
62
'''
59
- client = {
60
- '3.3': CustomerRTM33(license_id, version, base_url),
61
- '3.4': CustomerRTM34(license_id, version, base_url)
63
+ client = {'3.3': CustomerRTM33, '3.4': CustomerRTM34}.get(version)
64
+ client_kwargs = {
65
+ '3.3': {
66
+ 'license_id': license_id,
67
+ 'version': version,
68
+ 'url': base_url
69
+ },
70
+ '3.4': {
71
+ 'organization_id': organization_id,
72
+ 'version': version,
73
+ 'url': base_url
74
+ }
62
75
}.get(version)
63
- if not client:
64
- raise ValueError('Provided version does not exist.' )
65
- return client
76
+ if client:
77
+ return client(**client_kwargs )
78
+ raise ValueError('Provided version does not exist.')
66
79
67
80
68
81
class CustomerRTMInterface(metaclass=ABCMeta):
69
82
''' CustomerRTM interface class. '''
70
- def __init__(self, license_id, version, url):
71
- if not license_id or not isinstance(license_id, int):
72
- raise ValueError(
73
- 'Pipe was not opened. Something`s wrong with your `license_id`.'
74
- )
75
- self.ws = WebsocketClient(
76
- url=
77
- f'wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}')
83
+ def __init__(self, license_id: int, version: str, url: str,
84
+ organization_id: str) -> CustomerRTMInterface:
85
+ # Dummy ws object - must be overwritten in concrete classes.
86
+ self.ws = WebsocketClient()
78
87
79
88
def open_connection(self, origin: dict = None) -> None:
80
89
''' Opens WebSocket connection.
@@ -654,10 +663,32 @@ <h1 class="title">Module <code>client</code></h1>
654
663
655
664
class CustomerRTM33(CustomerRTMInterface):
656
665
''' Customer RTM version 3.3 class. '''
666
+ def __init__(self, license_id: int, version: str,
667
+ url: str) -> CustomerRTM33:
668
+ if isinstance(license_id, int):
669
+ self.ws = WebsocketClient(
670
+ url=
671
+ f'wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}'
672
+ )
673
+ else:
674
+ raise ValueError(
675
+ 'Pipe was not opened. Please check your `license_id` argument.'
676
+ )
657
677
658
678
659
679
class CustomerRTM34(CustomerRTMInterface):
660
- ''' Customer RTM version 3.4 class. '''</ code > </ pre >
680
+ ''' Customer RTM version 3.4 class. '''
681
+ def __init__(self, organization_id: str, version: str,
682
+ url: str) -> CustomerRTM34:
683
+ if isinstance(organization_id, str):
684
+ self.ws = WebsocketClient(
685
+ url=
686
+ f'wss://{url}/v{version}/customer/rtm/ws?organization_id={organization_id}'
687
+ )
688
+ else:
689
+ raise ValueError(
690
+ 'Pipe was not opened. Please check your `organization_id` argument.'
691
+ )</ code > </ pre >
661
692
</ details >
662
693
</ section >
663
694
< section >
@@ -683,43 +714,56 @@ <h2 class="section-title" id="header-classes">Classes</h2>
683
714
@staticmethod
684
715
def get_client(license_id: int = None,
685
716
version: str = '3.3',
686
- base_url: str = 'api.livechatinc.com'):
717
+ base_url: str = 'api.livechatinc.com',
718
+ organization_id: str = None) -> CustomerRTMInterface:
687
719
''' Returns client for specific Customer RTM version.
688
720
689
721
Args:
690
- license_id (int): License ID.
722
+ license_id (int): License ID. Required to use API v3.3.
691
723
version (str): API's version. Defaults to `3.3`.
692
724
base_url (str): API's base url. Defaults to `api.livechatinc.com`.
725
+ organization_id (str): Organization ID, replaced license ID in v3.4.
693
726
694
727
Returns:
695
728
CustomerRTMInterface: API client object for specified version.
696
729
697
730
Raises:
698
731
ValueError: If the specified version does not exist.
699
732
'''
700
- client = {
701
- '3.3': CustomerRTM33(license_id, version, base_url),
702
- '3.4': CustomerRTM34(license_id, version, base_url)
733
+ client = {'3.3': CustomerRTM33, '3.4': CustomerRTM34}.get(version)
734
+ client_kwargs = {
735
+ '3.3': {
736
+ 'license_id': license_id,
737
+ 'version': version,
738
+ 'url': base_url
739
+ },
740
+ '3.4': {
741
+ 'organization_id': organization_id,
742
+ 'version': version,
743
+ 'url': base_url
744
+ }
703
745
}.get(version)
704
- if not client:
705
- raise ValueError('Provided version does not exist.' )
706
- return client </ code > </ pre >
746
+ if client:
747
+ return client(**client_kwargs )
748
+ raise ValueError('Provided version does not exist.') </ code > </ pre >
707
749
</ details >
708
750
< h3 > Static methods</ h3 >
709
751
< dl >
710
752
< dt id ="client.CustomerRTM.get_client "> < code class ="name flex ">
711
- < span > def < span class ="ident "> get_client</ span > </ span > (< span > license_id: int = None, version: str = '3.3', base_url: str = 'api.livechatinc.com') </ span >
753
+ < span > def < span class ="ident "> get_client</ span > </ span > (< span > license_id: int = None, version: str = '3.3', base_url: str = 'api.livechatinc.com', organization_id: str = None) ‑ > < a title =" client.CustomerRTMInterface " href =" #client.CustomerRTMInterface " > CustomerRTMInterface </ a > </ span >
712
754
</ code > </ dt >
713
755
< dd >
714
756
< div class ="desc "> < p > Returns client for specific Customer RTM version.</ p >
715
757
< h2 id ="args "> Args</ h2 >
716
758
< dl >
717
759
< dt > < strong > < code > license_id</ code > </ strong > : < code > int</ code > </ dt >
718
- < dd > License ID.</ dd >
760
+ < dd > License ID. Required to use API v3.3. </ dd >
719
761
< dt > < strong > < code > version</ code > </ strong > : < code > str</ code > </ dt >
720
762
< dd > API's version. Defaults to < code > 3.3</ code > .</ dd >
721
763
< dt > < strong > < code > base_url</ code > </ strong > : < code > str</ code > </ dt >
722
764
< dd > API's base url. Defaults to < code > api.livechatinc.com</ code > .</ dd >
765
+ < dt > < strong > < code > organization_id</ code > </ strong > : < code > str</ code > </ dt >
766
+ < dd > Organization ID, replaced license ID in v3.4.</ dd >
723
767
</ dl >
724
768
< h2 id ="returns "> Returns</ h2 >
725
769
< dl >
@@ -738,34 +782,45 @@ <h2 id="raises">Raises</h2>
738
782
< pre > < code class ="python "> @staticmethod
739
783
def get_client(license_id: int = None,
740
784
version: str = '3.3',
741
- base_url: str = 'api.livechatinc.com'):
785
+ base_url: str = 'api.livechatinc.com',
786
+ organization_id: str = None) -> CustomerRTMInterface:
742
787
''' Returns client for specific Customer RTM version.
743
788
744
789
Args:
745
- license_id (int): License ID.
790
+ license_id (int): License ID. Required to use API v3.3.
746
791
version (str): API's version. Defaults to `3.3`.
747
792
base_url (str): API's base url. Defaults to `api.livechatinc.com`.
793
+ organization_id (str): Organization ID, replaced license ID in v3.4.
748
794
749
795
Returns:
750
796
CustomerRTMInterface: API client object for specified version.
751
797
752
798
Raises:
753
799
ValueError: If the specified version does not exist.
754
800
'''
755
- client = {
756
- '3.3': CustomerRTM33(license_id, version, base_url),
757
- '3.4': CustomerRTM34(license_id, version, base_url)
801
+ client = {'3.3': CustomerRTM33, '3.4': CustomerRTM34}.get(version)
802
+ client_kwargs = {
803
+ '3.3': {
804
+ 'license_id': license_id,
805
+ 'version': version,
806
+ 'url': base_url
807
+ },
808
+ '3.4': {
809
+ 'organization_id': organization_id,
810
+ 'version': version,
811
+ 'url': base_url
812
+ }
758
813
}.get(version)
759
- if not client:
760
- raise ValueError('Provided version does not exist.' )
761
- return client </ code > </ pre >
814
+ if client:
815
+ return client(**client_kwargs )
816
+ raise ValueError('Provided version does not exist.') </ code > </ pre >
762
817
</ details >
763
818
</ dd >
764
819
</ dl >
765
820
</ dd >
766
821
< dt id ="client.CustomerRTM33 "> < code class ="flex name class ">
767
822
< span > class < span class ="ident "> CustomerRTM33</ span > </ span >
768
- < span > (</ span > < span > license_id, version, url)</ span >
823
+ < span > (</ span > < span > license_id: int , version: str , url: str )</ span >
769
824
</ code > </ dt >
770
825
< dd >
771
826
< div class ="desc "> < p > Customer RTM version 3.3 class.</ p > </ div >
@@ -774,7 +829,18 @@ <h2 id="raises">Raises</h2>
774
829
< span > Expand source code</ span >
775
830
</ summary >
776
831
< pre > < code class ="python "> class CustomerRTM33(CustomerRTMInterface):
777
- ''' Customer RTM version 3.3 class. '''</ code > </ pre >
832
+ ''' Customer RTM version 3.3 class. '''
833
+ def __init__(self, license_id: int, version: str,
834
+ url: str) -> CustomerRTM33:
835
+ if isinstance(license_id, int):
836
+ self.ws = WebsocketClient(
837
+ url=
838
+ f'wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}'
839
+ )
840
+ else:
841
+ raise ValueError(
842
+ 'Pipe was not opened. Please check your `license_id` argument.'
843
+ )</ code > </ pre >
778
844
</ details >
779
845
< h3 > Ancestors</ h3 >
780
846
< ul class ="hlist ">
@@ -819,7 +885,7 @@ <h3>Inherited members</h3>
819
885
</ dd >
820
886
< dt id ="client.CustomerRTM34 "> < code class ="flex name class ">
821
887
< span > class < span class ="ident "> CustomerRTM34</ span > </ span >
822
- < span > (</ span > < span > license_id , version, url)</ span >
888
+ < span > (</ span > < span > organization_id: str , version: str , url: str )</ span >
823
889
</ code > </ dt >
824
890
< dd >
825
891
< div class ="desc "> < p > Customer RTM version 3.4 class.</ p > </ div >
@@ -828,7 +894,18 @@ <h3>Inherited members</h3>
828
894
< span > Expand source code</ span >
829
895
</ summary >
830
896
< pre > < code class ="python "> class CustomerRTM34(CustomerRTMInterface):
831
- ''' Customer RTM version 3.4 class. '''</ code > </ pre >
897
+ ''' Customer RTM version 3.4 class. '''
898
+ def __init__(self, organization_id: str, version: str,
899
+ url: str) -> CustomerRTM34:
900
+ if isinstance(organization_id, str):
901
+ self.ws = WebsocketClient(
902
+ url=
903
+ f'wss://{url}/v{version}/customer/rtm/ws?organization_id={organization_id}'
904
+ )
905
+ else:
906
+ raise ValueError(
907
+ 'Pipe was not opened. Please check your `organization_id` argument.'
908
+ )</ code > </ pre >
832
909
</ details >
833
910
< h3 > Ancestors</ h3 >
834
911
< ul class ="hlist ">
@@ -873,7 +950,7 @@ <h3>Inherited members</h3>
873
950
</ dd >
874
951
< dt id ="client.CustomerRTMInterface "> < code class ="flex name class ">
875
952
< span > class < span class ="ident "> CustomerRTMInterface</ span > </ span >
876
- < span > (</ span > < span > license_id, version, url)</ span >
953
+ < span > (</ span > < span > license_id: int , version: str , url: str, organization_id: str )</ span >
877
954
</ code > </ dt >
878
955
< dd >
879
956
< div class ="desc "> < p > CustomerRTM interface class.</ p > </ div >
@@ -883,14 +960,10 @@ <h3>Inherited members</h3>
883
960
</ summary >
884
961
< pre > < code class ="python "> class CustomerRTMInterface(metaclass=ABCMeta):
885
962
''' CustomerRTM interface class. '''
886
- def __init__(self, license_id, version, url):
887
- if not license_id or not isinstance(license_id, int):
888
- raise ValueError(
889
- 'Pipe was not opened. Something`s wrong with your `license_id`.'
890
- )
891
- self.ws = WebsocketClient(
892
- url=
893
- f'wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}')
963
+ def __init__(self, license_id: int, version: str, url: str,
964
+ organization_id: str) -> CustomerRTMInterface:
965
+ # Dummy ws object - must be overwritten in concrete classes.
966
+ self.ws = WebsocketClient()
894
967
895
968
def open_connection(self, origin: dict = None) -> None:
896
969
''' Opens WebSocket connection.
0 commit comments