Skip to content

Commit a93b2e1

Browse files
authored
Merge pull request #50 from livechat/API-9774-Support-Organization-ID-In-Protocol
API-9774: Introduce support for organization ID in v3.4
2 parents bc20275 + a24c965 commit a93b2e1

File tree

7 files changed

+1016
-321
lines changed

7 files changed

+1016
-321
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [0.1.7] - 2021-10-13
5+
6+
### Changed
7+
8+
- Support for `organization_id` in Customer(rtm/web) v3.4.
9+
410
## [0.1.6] - 2021-10-06
511

612
### Added

docs/customer_rtm.html

Lines changed: 122 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ <h1 class="title">Module <code>client</code></h1>
2929
</summary>
3030
<pre><code class="python">&#39;&#39;&#39; Customer RTM client implementation. &#39;&#39;&#39;
3131

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
3335

3436
from abc import ABCMeta
3537

@@ -42,39 +44,46 @@ <h1 class="title">Module <code>client</code></h1>
4244
@staticmethod
4345
def get_client(license_id: int = None,
4446
version: str = &#39;3.3&#39;,
45-
base_url: str = &#39;api.livechatinc.com&#39;):
47+
base_url: str = &#39;api.livechatinc.com&#39;,
48+
organization_id: str = None) -&gt; CustomerRTMInterface:
4649
&#39;&#39;&#39; Returns client for specific Customer RTM version.
4750

4851
Args:
49-
license_id (int): License ID.
52+
license_id (int): License ID. Required to use API v3.3.
5053
version (str): API&#39;s version. Defaults to `3.3`.
5154
base_url (str): API&#39;s base url. Defaults to `api.livechatinc.com`.
55+
organization_id (str): Organization ID, replaced license ID in v3.4.
5256

5357
Returns:
5458
CustomerRTMInterface: API client object for specified version.
5559

5660
Raises:
5761
ValueError: If the specified version does not exist.
5862
&#39;&#39;&#39;
59-
client = {
60-
&#39;3.3&#39;: CustomerRTM33(license_id, version, base_url),
61-
&#39;3.4&#39;: CustomerRTM34(license_id, version, base_url)
63+
client = {&#39;3.3&#39;: CustomerRTM33, &#39;3.4&#39;: CustomerRTM34}.get(version)
64+
client_kwargs = {
65+
&#39;3.3&#39;: {
66+
&#39;license_id&#39;: license_id,
67+
&#39;version&#39;: version,
68+
&#39;url&#39;: base_url
69+
},
70+
&#39;3.4&#39;: {
71+
&#39;organization_id&#39;: organization_id,
72+
&#39;version&#39;: version,
73+
&#39;url&#39;: base_url
74+
}
6275
}.get(version)
63-
if not client:
64-
raise ValueError(&#39;Provided version does not exist.&#39;)
65-
return client
76+
if client:
77+
return client(**client_kwargs)
78+
raise ValueError(&#39;Provided version does not exist.&#39;)
6679

6780

6881
class CustomerRTMInterface(metaclass=ABCMeta):
6982
&#39;&#39;&#39; CustomerRTM interface class. &#39;&#39;&#39;
70-
def __init__(self, license_id, version, url):
71-
if not license_id or not isinstance(license_id, int):
72-
raise ValueError(
73-
&#39;Pipe was not opened. Something`s wrong with your `license_id`.&#39;
74-
)
75-
self.ws = WebsocketClient(
76-
url=
77-
f&#39;wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}&#39;)
83+
def __init__(self, license_id: int, version: str, url: str,
84+
organization_id: str) -&gt; CustomerRTMInterface:
85+
# Dummy ws object - must be overwritten in concrete classes.
86+
self.ws = WebsocketClient()
7887

7988
def open_connection(self, origin: dict = None) -&gt; None:
8089
&#39;&#39;&#39; Opens WebSocket connection.
@@ -654,10 +663,32 @@ <h1 class="title">Module <code>client</code></h1>
654663

655664
class CustomerRTM33(CustomerRTMInterface):
656665
&#39;&#39;&#39; Customer RTM version 3.3 class. &#39;&#39;&#39;
666+
def __init__(self, license_id: int, version: str,
667+
url: str) -&gt; CustomerRTM33:
668+
if isinstance(license_id, int):
669+
self.ws = WebsocketClient(
670+
url=
671+
f&#39;wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}&#39;
672+
)
673+
else:
674+
raise ValueError(
675+
&#39;Pipe was not opened. Please check your `license_id` argument.&#39;
676+
)
657677

658678

659679
class CustomerRTM34(CustomerRTMInterface):
660-
&#39;&#39;&#39; Customer RTM version 3.4 class. &#39;&#39;&#39;</code></pre>
680+
&#39;&#39;&#39; Customer RTM version 3.4 class. &#39;&#39;&#39;
681+
def __init__(self, organization_id: str, version: str,
682+
url: str) -&gt; CustomerRTM34:
683+
if isinstance(organization_id, str):
684+
self.ws = WebsocketClient(
685+
url=
686+
f&#39;wss://{url}/v{version}/customer/rtm/ws?organization_id={organization_id}&#39;
687+
)
688+
else:
689+
raise ValueError(
690+
&#39;Pipe was not opened. Please check your `organization_id` argument.&#39;
691+
)</code></pre>
661692
</details>
662693
</section>
663694
<section>
@@ -683,43 +714,56 @@ <h2 class="section-title" id="header-classes">Classes</h2>
683714
@staticmethod
684715
def get_client(license_id: int = None,
685716
version: str = &#39;3.3&#39;,
686-
base_url: str = &#39;api.livechatinc.com&#39;):
717+
base_url: str = &#39;api.livechatinc.com&#39;,
718+
organization_id: str = None) -&gt; CustomerRTMInterface:
687719
&#39;&#39;&#39; Returns client for specific Customer RTM version.
688720

689721
Args:
690-
license_id (int): License ID.
722+
license_id (int): License ID. Required to use API v3.3.
691723
version (str): API&#39;s version. Defaults to `3.3`.
692724
base_url (str): API&#39;s base url. Defaults to `api.livechatinc.com`.
725+
organization_id (str): Organization ID, replaced license ID in v3.4.
693726

694727
Returns:
695728
CustomerRTMInterface: API client object for specified version.
696729

697730
Raises:
698731
ValueError: If the specified version does not exist.
699732
&#39;&#39;&#39;
700-
client = {
701-
&#39;3.3&#39;: CustomerRTM33(license_id, version, base_url),
702-
&#39;3.4&#39;: CustomerRTM34(license_id, version, base_url)
733+
client = {&#39;3.3&#39;: CustomerRTM33, &#39;3.4&#39;: CustomerRTM34}.get(version)
734+
client_kwargs = {
735+
&#39;3.3&#39;: {
736+
&#39;license_id&#39;: license_id,
737+
&#39;version&#39;: version,
738+
&#39;url&#39;: base_url
739+
},
740+
&#39;3.4&#39;: {
741+
&#39;organization_id&#39;: organization_id,
742+
&#39;version&#39;: version,
743+
&#39;url&#39;: base_url
744+
}
703745
}.get(version)
704-
if not client:
705-
raise ValueError(&#39;Provided version does not exist.&#39;)
706-
return client</code></pre>
746+
if client:
747+
return client(**client_kwargs)
748+
raise ValueError(&#39;Provided version does not exist.&#39;)</code></pre>
707749
</details>
708750
<h3>Static methods</h3>
709751
<dl>
710752
<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>
712754
</code></dt>
713755
<dd>
714756
<div class="desc"><p>Returns client for specific Customer RTM version.</p>
715757
<h2 id="args">Args</h2>
716758
<dl>
717759
<dt><strong><code>license_id</code></strong> :&ensp;<code>int</code></dt>
718-
<dd>License ID.</dd>
760+
<dd>License ID. Required to use API v3.3.</dd>
719761
<dt><strong><code>version</code></strong> :&ensp;<code>str</code></dt>
720762
<dd>API's version. Defaults to <code>3.3</code>.</dd>
721763
<dt><strong><code>base_url</code></strong> :&ensp;<code>str</code></dt>
722764
<dd>API's base url. Defaults to <code>api.livechatinc.com</code>.</dd>
765+
<dt><strong><code>organization_id</code></strong> :&ensp;<code>str</code></dt>
766+
<dd>Organization ID, replaced license ID in v3.4.</dd>
723767
</dl>
724768
<h2 id="returns">Returns</h2>
725769
<dl>
@@ -738,34 +782,45 @@ <h2 id="raises">Raises</h2>
738782
<pre><code class="python">@staticmethod
739783
def get_client(license_id: int = None,
740784
version: str = &#39;3.3&#39;,
741-
base_url: str = &#39;api.livechatinc.com&#39;):
785+
base_url: str = &#39;api.livechatinc.com&#39;,
786+
organization_id: str = None) -&gt; CustomerRTMInterface:
742787
&#39;&#39;&#39; Returns client for specific Customer RTM version.
743788

744789
Args:
745-
license_id (int): License ID.
790+
license_id (int): License ID. Required to use API v3.3.
746791
version (str): API&#39;s version. Defaults to `3.3`.
747792
base_url (str): API&#39;s base url. Defaults to `api.livechatinc.com`.
793+
organization_id (str): Organization ID, replaced license ID in v3.4.
748794

749795
Returns:
750796
CustomerRTMInterface: API client object for specified version.
751797

752798
Raises:
753799
ValueError: If the specified version does not exist.
754800
&#39;&#39;&#39;
755-
client = {
756-
&#39;3.3&#39;: CustomerRTM33(license_id, version, base_url),
757-
&#39;3.4&#39;: CustomerRTM34(license_id, version, base_url)
801+
client = {&#39;3.3&#39;: CustomerRTM33, &#39;3.4&#39;: CustomerRTM34}.get(version)
802+
client_kwargs = {
803+
&#39;3.3&#39;: {
804+
&#39;license_id&#39;: license_id,
805+
&#39;version&#39;: version,
806+
&#39;url&#39;: base_url
807+
},
808+
&#39;3.4&#39;: {
809+
&#39;organization_id&#39;: organization_id,
810+
&#39;version&#39;: version,
811+
&#39;url&#39;: base_url
812+
}
758813
}.get(version)
759-
if not client:
760-
raise ValueError(&#39;Provided version does not exist.&#39;)
761-
return client</code></pre>
814+
if client:
815+
return client(**client_kwargs)
816+
raise ValueError(&#39;Provided version does not exist.&#39;)</code></pre>
762817
</details>
763818
</dd>
764819
</dl>
765820
</dd>
766821
<dt id="client.CustomerRTM33"><code class="flex name class">
767822
<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>
769824
</code></dt>
770825
<dd>
771826
<div class="desc"><p>Customer RTM version 3.3 class.</p></div>
@@ -774,7 +829,18 @@ <h2 id="raises">Raises</h2>
774829
<span>Expand source code</span>
775830
</summary>
776831
<pre><code class="python">class CustomerRTM33(CustomerRTMInterface):
777-
&#39;&#39;&#39; Customer RTM version 3.3 class. &#39;&#39;&#39;</code></pre>
832+
&#39;&#39;&#39; Customer RTM version 3.3 class. &#39;&#39;&#39;
833+
def __init__(self, license_id: int, version: str,
834+
url: str) -&gt; CustomerRTM33:
835+
if isinstance(license_id, int):
836+
self.ws = WebsocketClient(
837+
url=
838+
f&#39;wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}&#39;
839+
)
840+
else:
841+
raise ValueError(
842+
&#39;Pipe was not opened. Please check your `license_id` argument.&#39;
843+
)</code></pre>
778844
</details>
779845
<h3>Ancestors</h3>
780846
<ul class="hlist">
@@ -819,7 +885,7 @@ <h3>Inherited members</h3>
819885
</dd>
820886
<dt id="client.CustomerRTM34"><code class="flex name class">
821887
<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>
823889
</code></dt>
824890
<dd>
825891
<div class="desc"><p>Customer RTM version 3.4 class.</p></div>
@@ -828,7 +894,18 @@ <h3>Inherited members</h3>
828894
<span>Expand source code</span>
829895
</summary>
830896
<pre><code class="python">class CustomerRTM34(CustomerRTMInterface):
831-
&#39;&#39;&#39; Customer RTM version 3.4 class. &#39;&#39;&#39;</code></pre>
897+
&#39;&#39;&#39; Customer RTM version 3.4 class. &#39;&#39;&#39;
898+
def __init__(self, organization_id: str, version: str,
899+
url: str) -&gt; CustomerRTM34:
900+
if isinstance(organization_id, str):
901+
self.ws = WebsocketClient(
902+
url=
903+
f&#39;wss://{url}/v{version}/customer/rtm/ws?organization_id={organization_id}&#39;
904+
)
905+
else:
906+
raise ValueError(
907+
&#39;Pipe was not opened. Please check your `organization_id` argument.&#39;
908+
)</code></pre>
832909
</details>
833910
<h3>Ancestors</h3>
834911
<ul class="hlist">
@@ -873,7 +950,7 @@ <h3>Inherited members</h3>
873950
</dd>
874951
<dt id="client.CustomerRTMInterface"><code class="flex name class">
875952
<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>
877954
</code></dt>
878955
<dd>
879956
<div class="desc"><p>CustomerRTM interface class.</p></div>
@@ -883,14 +960,10 @@ <h3>Inherited members</h3>
883960
</summary>
884961
<pre><code class="python">class CustomerRTMInterface(metaclass=ABCMeta):
885962
&#39;&#39;&#39; CustomerRTM interface class. &#39;&#39;&#39;
886-
def __init__(self, license_id, version, url):
887-
if not license_id or not isinstance(license_id, int):
888-
raise ValueError(
889-
&#39;Pipe was not opened. Something`s wrong with your `license_id`.&#39;
890-
)
891-
self.ws = WebsocketClient(
892-
url=
893-
f&#39;wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}&#39;)
963+
def __init__(self, license_id: int, version: str, url: str,
964+
organization_id: str) -&gt; CustomerRTMInterface:
965+
# Dummy ws object - must be overwritten in concrete classes.
966+
self.ws = WebsocketClient()
894967

895968
def open_connection(self, origin: dict = None) -&gt; None:
896969
&#39;&#39;&#39; Opens WebSocket connection.

0 commit comments

Comments
 (0)