Skip to content

Commit

Permalink
Merge pull request #50 from livechat/API-9774-Support-Organization-ID…
Browse files Browse the repository at this point in the history
…-In-Protocol

API-9774: Introduce support for organization ID in v3.4
  • Loading branch information
kacperf531 authored Oct 13, 2021
2 parents bc20275 + a24c965 commit a93b2e1
Show file tree
Hide file tree
Showing 7 changed files with 1,016 additions and 321 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.1.7] - 2021-10-13

### Changed

- Support for `organization_id` in Customer(rtm/web) v3.4.

## [0.1.6] - 2021-10-06

### Added
Expand Down
171 changes: 122 additions & 49 deletions docs/customer_rtm.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ <h1 class="title">Module <code>client</code></h1>
</summary>
<pre><code class="python">&#39;&#39;&#39; Customer RTM client implementation. &#39;&#39;&#39;

# pylint: disable=W0613,W0622,C0103,R0913,R0903,W0107
# pylint: disable=W0613,W0622,C0103,R0913,R0903,W0107,W0231

from __future__ import annotations

from abc import ABCMeta

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

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

Returns:
CustomerRTMInterface: API client object for specified version.

Raises:
ValueError: If the specified version does not exist.
&#39;&#39;&#39;
client = {
&#39;3.3&#39;: CustomerRTM33(license_id, version, base_url),
&#39;3.4&#39;: CustomerRTM34(license_id, version, base_url)
client = {&#39;3.3&#39;: CustomerRTM33, &#39;3.4&#39;: CustomerRTM34}.get(version)
client_kwargs = {
&#39;3.3&#39;: {
&#39;license_id&#39;: license_id,
&#39;version&#39;: version,
&#39;url&#39;: base_url
},
&#39;3.4&#39;: {
&#39;organization_id&#39;: organization_id,
&#39;version&#39;: version,
&#39;url&#39;: base_url
}
}.get(version)
if not client:
raise ValueError(&#39;Provided version does not exist.&#39;)
return client
if client:
return client(**client_kwargs)
raise ValueError(&#39;Provided version does not exist.&#39;)


class CustomerRTMInterface(metaclass=ABCMeta):
&#39;&#39;&#39; CustomerRTM interface class. &#39;&#39;&#39;
def __init__(self, license_id, version, url):
if not license_id or not isinstance(license_id, int):
raise ValueError(
&#39;Pipe was not opened. Something`s wrong with your `license_id`.&#39;
)
self.ws = WebsocketClient(
url=
f&#39;wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}&#39;)
def __init__(self, license_id: int, version: str, url: str,
organization_id: str) -&gt; CustomerRTMInterface:
# Dummy ws object - must be overwritten in concrete classes.
self.ws = WebsocketClient()

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

class CustomerRTM33(CustomerRTMInterface):
&#39;&#39;&#39; Customer RTM version 3.3 class. &#39;&#39;&#39;
def __init__(self, license_id: int, version: str,
url: str) -&gt; CustomerRTM33:
if isinstance(license_id, int):
self.ws = WebsocketClient(
url=
f&#39;wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}&#39;
)
else:
raise ValueError(
&#39;Pipe was not opened. Please check your `license_id` argument.&#39;
)


class CustomerRTM34(CustomerRTMInterface):
&#39;&#39;&#39; Customer RTM version 3.4 class. &#39;&#39;&#39;</code></pre>
&#39;&#39;&#39; Customer RTM version 3.4 class. &#39;&#39;&#39;
def __init__(self, organization_id: str, version: str,
url: str) -&gt; CustomerRTM34:
if isinstance(organization_id, str):
self.ws = WebsocketClient(
url=
f&#39;wss://{url}/v{version}/customer/rtm/ws?organization_id={organization_id}&#39;
)
else:
raise ValueError(
&#39;Pipe was not opened. Please check your `organization_id` argument.&#39;
)</code></pre>
</details>
</section>
<section>
Expand All @@ -683,43 +714,56 @@ <h2 class="section-title" id="header-classes">Classes</h2>
@staticmethod
def get_client(license_id: int = None,
version: str = &#39;3.3&#39;,
base_url: str = &#39;api.livechatinc.com&#39;):
base_url: str = &#39;api.livechatinc.com&#39;,
organization_id: str = None) -&gt; CustomerRTMInterface:
&#39;&#39;&#39; Returns client for specific Customer RTM version.

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

Returns:
CustomerRTMInterface: API client object for specified version.

Raises:
ValueError: If the specified version does not exist.
&#39;&#39;&#39;
client = {
&#39;3.3&#39;: CustomerRTM33(license_id, version, base_url),
&#39;3.4&#39;: CustomerRTM34(license_id, version, base_url)
client = {&#39;3.3&#39;: CustomerRTM33, &#39;3.4&#39;: CustomerRTM34}.get(version)
client_kwargs = {
&#39;3.3&#39;: {
&#39;license_id&#39;: license_id,
&#39;version&#39;: version,
&#39;url&#39;: base_url
},
&#39;3.4&#39;: {
&#39;organization_id&#39;: organization_id,
&#39;version&#39;: version,
&#39;url&#39;: base_url
}
}.get(version)
if not client:
raise ValueError(&#39;Provided version does not exist.&#39;)
return client</code></pre>
if client:
return client(**client_kwargs)
raise ValueError(&#39;Provided version does not exist.&#39;)</code></pre>
</details>
<h3>Static methods</h3>
<dl>
<dt id="client.CustomerRTM.get_client"><code class="name flex">
<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>
<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>
</code></dt>
<dd>
<div class="desc"><p>Returns client for specific Customer RTM version.</p>
<h2 id="args">Args</h2>
<dl>
<dt><strong><code>license_id</code></strong> :&ensp;<code>int</code></dt>
<dd>License ID.</dd>
<dd>License ID. Required to use API v3.3.</dd>
<dt><strong><code>version</code></strong> :&ensp;<code>str</code></dt>
<dd>API's version. Defaults to <code>3.3</code>.</dd>
<dt><strong><code>base_url</code></strong> :&ensp;<code>str</code></dt>
<dd>API's base url. Defaults to <code>api.livechatinc.com</code>.</dd>
<dt><strong><code>organization_id</code></strong> :&ensp;<code>str</code></dt>
<dd>Organization ID, replaced license ID in v3.4.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
Expand All @@ -738,34 +782,45 @@ <h2 id="raises">Raises</h2>
<pre><code class="python">@staticmethod
def get_client(license_id: int = None,
version: str = &#39;3.3&#39;,
base_url: str = &#39;api.livechatinc.com&#39;):
base_url: str = &#39;api.livechatinc.com&#39;,
organization_id: str = None) -&gt; CustomerRTMInterface:
&#39;&#39;&#39; Returns client for specific Customer RTM version.

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

Returns:
CustomerRTMInterface: API client object for specified version.

Raises:
ValueError: If the specified version does not exist.
&#39;&#39;&#39;
client = {
&#39;3.3&#39;: CustomerRTM33(license_id, version, base_url),
&#39;3.4&#39;: CustomerRTM34(license_id, version, base_url)
client = {&#39;3.3&#39;: CustomerRTM33, &#39;3.4&#39;: CustomerRTM34}.get(version)
client_kwargs = {
&#39;3.3&#39;: {
&#39;license_id&#39;: license_id,
&#39;version&#39;: version,
&#39;url&#39;: base_url
},
&#39;3.4&#39;: {
&#39;organization_id&#39;: organization_id,
&#39;version&#39;: version,
&#39;url&#39;: base_url
}
}.get(version)
if not client:
raise ValueError(&#39;Provided version does not exist.&#39;)
return client</code></pre>
if client:
return client(**client_kwargs)
raise ValueError(&#39;Provided version does not exist.&#39;)</code></pre>
</details>
</dd>
</dl>
</dd>
<dt id="client.CustomerRTM33"><code class="flex name class">
<span>class <span class="ident">CustomerRTM33</span></span>
<span>(</span><span>license_id, version, url)</span>
<span>(</span><span>license_id: int, version: str, url: str)</span>
</code></dt>
<dd>
<div class="desc"><p>Customer RTM version 3.3 class.</p></div>
Expand All @@ -774,7 +829,18 @@ <h2 id="raises">Raises</h2>
<span>Expand source code</span>
</summary>
<pre><code class="python">class CustomerRTM33(CustomerRTMInterface):
&#39;&#39;&#39; Customer RTM version 3.3 class. &#39;&#39;&#39;</code></pre>
&#39;&#39;&#39; Customer RTM version 3.3 class. &#39;&#39;&#39;
def __init__(self, license_id: int, version: str,
url: str) -&gt; CustomerRTM33:
if isinstance(license_id, int):
self.ws = WebsocketClient(
url=
f&#39;wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}&#39;
)
else:
raise ValueError(
&#39;Pipe was not opened. Please check your `license_id` argument.&#39;
)</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
Expand Down Expand Up @@ -819,7 +885,7 @@ <h3>Inherited members</h3>
</dd>
<dt id="client.CustomerRTM34"><code class="flex name class">
<span>class <span class="ident">CustomerRTM34</span></span>
<span>(</span><span>license_id, version, url)</span>
<span>(</span><span>organization_id: str, version: str, url: str)</span>
</code></dt>
<dd>
<div class="desc"><p>Customer RTM version 3.4 class.</p></div>
Expand All @@ -828,7 +894,18 @@ <h3>Inherited members</h3>
<span>Expand source code</span>
</summary>
<pre><code class="python">class CustomerRTM34(CustomerRTMInterface):
&#39;&#39;&#39; Customer RTM version 3.4 class. &#39;&#39;&#39;</code></pre>
&#39;&#39;&#39; Customer RTM version 3.4 class. &#39;&#39;&#39;
def __init__(self, organization_id: str, version: str,
url: str) -&gt; CustomerRTM34:
if isinstance(organization_id, str):
self.ws = WebsocketClient(
url=
f&#39;wss://{url}/v{version}/customer/rtm/ws?organization_id={organization_id}&#39;
)
else:
raise ValueError(
&#39;Pipe was not opened. Please check your `organization_id` argument.&#39;
)</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
Expand Down Expand Up @@ -873,7 +950,7 @@ <h3>Inherited members</h3>
</dd>
<dt id="client.CustomerRTMInterface"><code class="flex name class">
<span>class <span class="ident">CustomerRTMInterface</span></span>
<span>(</span><span>license_id, version, url)</span>
<span>(</span><span>license_id: int, version: str, url: str, organization_id: str)</span>
</code></dt>
<dd>
<div class="desc"><p>CustomerRTM interface class.</p></div>
Expand All @@ -883,14 +960,10 @@ <h3>Inherited members</h3>
</summary>
<pre><code class="python">class CustomerRTMInterface(metaclass=ABCMeta):
&#39;&#39;&#39; CustomerRTM interface class. &#39;&#39;&#39;
def __init__(self, license_id, version, url):
if not license_id or not isinstance(license_id, int):
raise ValueError(
&#39;Pipe was not opened. Something`s wrong with your `license_id`.&#39;
)
self.ws = WebsocketClient(
url=
f&#39;wss://{url}/v{version}/customer/rtm/ws?license_id={license_id}&#39;)
def __init__(self, license_id: int, version: str, url: str,
organization_id: str) -&gt; CustomerRTMInterface:
# Dummy ws object - must be overwritten in concrete classes.
self.ws = WebsocketClient()

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

0 comments on commit a93b2e1

Please sign in to comment.