Skip to content

Commit

Permalink
Issues/189: add ability to supply submit_sm SMSC fields during submit…
Browse files Browse the repository at this point in the history
…_sm call (#193)

What:
- add ability to supply submit_sm SMSC fields during submit_sm call

Why:
- Fixes: #189

Usage:
```python
import naz

broker = naz.broker.SimpleBroker(maxsize=1000)
client = naz.Client(
        smsc_host="127.0.0.1",
        smsc_port=2775,
        system_id="smppclient1",
        password=os.getenv("password", "password"),
        broker=broker,
    )
msg = naz.protocol.SubmitSM(
    short_message="hello world",
    source_addr="255700111222",
    destination_addr="255799000888",
    log_id="some-id",
    source_addr_ton=16,  # National
    dest_addr_npi=4368,  # Internet
)
await client.send_message(msg)
```
  • Loading branch information
komuw authored Dec 6, 2019
1 parent 309030d commit 8274fb8
Show file tree
Hide file tree
Showing 57 changed files with 2,901 additions and 1,274 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
most recent version is listed first.


## **version:** v0.7.6
- Add ability to supply more `submit_sm` parameters when enquiuing `submit_sm`: https://github.com/komuw/naz/pull/193


## **version:** v0.7.5
- Rename `naz.nazcodec.BaseNazCodec` to `naz.codec.BaseCodec`: https://github.com/komuw/naz/pull/191
- Rename `naz.Client.codec_class` to `naz.Client.codec`: https://github.com/komuw/naz/pull/191
Expand Down
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ cli = naz.Client(
# queue messages to send
for i in range(0, 4):
print("submit_sm round:", i)
msg = naz.protocol.SubmitSM(
short_message="Hello World-{0}".format(str(i)),
log_id="myid12345",
source_addr="254722111111",
destination_addr="254722999999",
)
loop.run_until_complete(
cli.submit_sm(
short_message="Hello World-{0}".format(str(i)),
log_id="myid12345",
source_addr="254722111111",
destination_addr="254722999999",
)
cli.send_message(msg)
)


try:
# 1. connect to the SMSC host
# 2. bind to the SMSC host
Expand Down Expand Up @@ -380,13 +382,14 @@ then in your application, queue items to the queue;
```python
# queue messages to send
for i in range(0, 4):
msg = naz.protocol.SubmitSM(
short_message="Hello World-{0}".format(str(i)),
log_id="myid12345",
source_addr="254722111111",
destination_addr="254722999999",
)
loop.run_until_complete(
cli.submit_sm(
short_message="Hello World-{0}".format(str(i)),
log_id="myid12345",
source_addr="254722111111",
destination_addr="254722999999",
)
cli.send_message(msg)
)
```
Expand Down Expand Up @@ -454,13 +457,14 @@ then queue on your application side;
# queue messages to send
for i in range(0, 5):
print("submit_sm round:", i)
msg = naz.protocol.SubmitSM(
short_message="Hello World-{0}".format(str(i)),
log_id="myid12345",
source_addr="254722111111",
destination_addr="254722999999",
)
loop.run_until_complete(
cli.submit_sm(
short_message="Hello World-{0}".format(str(i)),
log_id="myid12345",
source_addr="254722111111",
destination_addr="254722999999",
)
cli.send_message(msg)
)
```

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
broker=MyRedisBroker(),
hook=BenchmarksHook(),
logger=BenchmarksLogger(
logger_name="naz.benchmarks", level="DEBUG", log_metadata={"project": "naz_benchmarks"},
logger_name="naz.benchmarks", level="DEBUG", log_metadata={"project": "naz_benchmarks"}
),
socket_timeout=15.00,
enquire_link_interval=80.00,
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/message_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ async def send_messages():
"MSGS_SENT": MSGS_SENT,
},
)
await my_naz_client.submit_sm(
msg = naz.protocol.SubmitSM(
short_message=msg,
log_id=log_id,
source_addr=source_addr,
destination_addr=destination_addr,
)
await my_naz_client.send_message(msg)

logger.log(
logging.INFO,
{
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/redis_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ async def dequeue(self) -> naz.protocol.Message:
item = await _redis.brpop(self.queue_name, timeout=self.timeout)
if item:
dequed_item = item[1].decode()
return naz.protocol.Message.from_json(dequed_item)
return naz.protocol.json_to_Message(dequed_item)
else:
await asyncio.sleep(5)
6 changes: 3 additions & 3 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Overview: module code &mdash; naz v0.7.5 documentation</title>
<title>Overview: module code &mdash; naz v0.7.6 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.7.5
v0.7.6
</div>


Expand All @@ -86,7 +86,7 @@

<ul>
<li class="toctree-l1"><a class="reference internal" href="../introduction.html">Introduction to naz</a></li>
<li class="toctree-l1"><a class="reference internal" href="../example_demo.html">Example demo of using naz</a></li>
<li class="toctree-l1"><a class="reference internal" href="../step_by_step_demo.html">Step by step tutorial of using naz</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../client.html">Client</a></li>
Expand Down
17 changes: 9 additions & 8 deletions docs/_modules/naz/broker.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>naz.broker &mdash; naz v0.7.5 documentation</title>
<title>naz.broker &mdash; naz v0.7.6 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
v0.7.5
v0.7.6
</div>


Expand All @@ -86,7 +86,7 @@

<ul>
<li class="toctree-l1"><a class="reference internal" href="../../introduction.html">Introduction to naz</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../example_demo.html">Example demo of using naz</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../step_by_step_demo.html">Step by step tutorial of using naz</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../client.html">Client</a></li>
Expand Down Expand Up @@ -166,7 +166,7 @@ <h1>Source code for naz.broker</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">abc</span>
<span class="kn">import</span> <span class="nn">asyncio</span>

<span class="kn">from</span> <span class="nn">.</span> <span class="k">import</span> <span class="n">protocol</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">protocol</span>


<div class="viewcode-block" id="BaseBroker"><a class="viewcode-back" href="../../broker.html#naz.broker.BaseBroker">[docs]</a><span class="k">class</span> <span class="nc">BaseBroker</span><span class="p">(</span><span class="n">abc</span><span class="o">.</span><span class="n">ABC</span><span class="p">):</span>
Expand All @@ -184,8 +184,8 @@ <h1>Source code for naz.broker</h1><div class="highlight"><pre>
<span class="sd"> enqueue/save an item.</span>

<span class="sd"> Parameters:</span>
<span class="sd"> item: The item to be enqueued/saved</span>
<span class="sd"> The item/message is a `naz.protocol.Message` class instance;</span>
<span class="sd"> message: The item to be enqueued/saved</span>
<span class="sd"> The message is a `naz.protocol.Message` class instance;</span>
<span class="sd"> It is up to the broker implementation to do the serialization(if neccesary) in order to be able to store it.</span>
<span class="sd"> `naz.protocol.Message` has a `to_json()` method that you can use to serialize a `naz.protocol.Message` class instance into json.</span>
<span class="sd"> &quot;&quot;&quot;</span>
Expand All @@ -200,7 +200,8 @@ <h1>Source code for naz.broker</h1><div class="highlight"><pre>
<span class="sd"> item that was dequeued.</span>
<span class="sd"> The item has to be returned as a `naz.protocol.Message` class instance.</span>
<span class="sd"> It is up to the broker implementation to do the de-serialization(if neccesary).</span>
<span class="sd"> `naz.protocol.Message` has a `from_json()` method that you can use to de-serialize a json string into `naz.protocol.Message` class instance.</span>
<span class="sd"> `naz.protocol` module has a utility function :func:`json_to_Message &lt;naz.protocol.json_to_Message&gt;`</span>
<span class="sd"> that you can use to de-serialize a json string into `naz.protocol.Message` class instance.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;dequeue method must be implemented.&quot;</span><span class="p">)</span></div></div>

Expand All @@ -212,7 +213,7 @@ <h1>Source code for naz.broker</h1><div class="highlight"><pre>
<span class="sd"> Note: It should only be used for tests and demo purposes.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<div class="viewcode-block" id="SimpleBroker.__init__"><a class="viewcode-back" href="../../broker.html#naz.broker.SimpleBroker.__init__">[docs]</a> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">maxsize</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2500</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<div class="viewcode-block" id="SimpleBroker.__init__"><a class="viewcode-back" href="../../broker.html#naz.broker.SimpleBroker.__init__">[docs]</a> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">maxsize</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2500</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parameters:</span>
<span class="sd"> maxsize: the maximum number of items(not size) that can be put in the queue.</span>
Expand Down
Loading

0 comments on commit 8274fb8

Please sign in to comment.