[Python-modules-commits] [python-exotel] 01/02: New upstream version 0.1.5

Sophie Brun sbrun-guest at moszumanska.debian.org
Wed Oct 25 13:44:26 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbrun-guest pushed a commit to branch debian/branch
in repository python-exotel.

commit 4c45db9c01dcf8b66b88b68272040c155c506ec2
Author: Sophie Brun <sophie at freexian.com>
Date:   Wed Oct 25 15:23:34 2017 +0200

    New upstream version 0.1.5
---
 .coveragerc          |  7 ++++
 .gitignore           | 11 ++++++
 .travis.yml          | 18 ++++++++++
 LICENCE.txt          | 11 ++++++
 MANIFEST             |  4 +++
 MANIFEST.in          |  0
 Makefile             |  2 ++
 README.md            | 55 ++++++++++++++++++++++++++++++
 README.rst           | 38 +++++++++++++++++++++
 exotel/__init__.py   |  1 +
 exotel/_compat.py    |  8 +++++
 exotel/exotel.py     | 76 +++++++++++++++++++++++++++++++++++++++++
 requirements.txt     |  6 ++++
 setup.py             | 63 ++++++++++++++++++++++++++++++++++
 tests/conftest.py    | 13 +++++++
 tests/test_exotel.py | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tox.ini              | 12 +++++++
 17 files changed, 421 insertions(+)

diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..53061d2
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,7 @@
+[run]
+branch = True
+source = exotel/
+
+[paths]
+source =
+  .tox/*/lib/*/site-packages/
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..18c2cce
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,11 @@
+*~
+/exotel.egg-info/
+/venv/
+build/
+dist/
+*.pyc
+/htmlcov/
+/.coverage
+/.cache/
+/.tox/
+/__pycache__/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..4ff3613
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,18 @@
+language: python
+python:
+  - "2.7"
+  - "3.3"
+  - "3.4"
+  - "3.5"
+  - "3.5-dev" # 3.5 development branch
+  - "3.6"
+  - "3.6-dev" # 3.6 development branch
+  - "3.7-dev" # 3.7 development branch
+  - "nightly" # currently points to 3.7-dev
+# command to install dependencies
+install: "pip install -r requirements.txt"
+script:
+  # TODO: use `tox-travis` to re-use build steps from `tox.ini`.
+  - "python setup.py install"
+  - "coverage run -m pytest -s -vv tests/"
+  - "coverage report --fail-under=100"
diff --git a/LICENCE.txt b/LICENCE.txt
new file mode 100644
index 0000000..becaca6
--- /dev/null
+++ b/LICENCE.txt
@@ -0,0 +1,11 @@
+The MIT License (MIT)
+
+Copyright © 2015 <sarath s pillai>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Fork this project to create your own MIT license that you can always link to.
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..8b40969
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,4 @@
+# file GENERATED by distutils, do NOT edit
+setup.py
+exotel/__init__.py
+exotel/exotel.py
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..e69de29
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..3a67e17
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+publish:
+	python setup.py sdist upload -r pypi
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a7018de
--- /dev/null
+++ b/README.md
@@ -0,0 +1,55 @@
+# exotel-py #
+
+[![Join the chat at https://gitter.im/sarathsp06/exotel-py](https://badges.gitter.im/sarathsp06/exotel-py.svg)](https://gitter.im/sarathsp06/exotel-py?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/sarathsp06/exotel-py.svg?branch=master)](https://travis-ci.org/sarathsp06/exotel-py)
+
+Python module for exotels call and sms api's(Unofficial). 
+
+### installation ###
+`
+pip install exotel
+`
+
+## Usage ##
+ - Initialize
+
+   ```
+   from exotel import Exotel
+   client = Exotel(sid,token)
+   ```
+
+- make call to connect a number to another
+ 
+   ```
+   client.call_number('from_number','exophone','to_number')
+   ```
+
+- make call to connect a number to a flow
+
+   ```
+   client.call_flow('from_number','exophone','flow_id')
+   ```
+
+- send an sms
+
+   ```
+   client.sms('from_number',to_number',"sms_body")
+   ```
+
+- get details of an sms
+
+   ```
+   client.sms_details('sms_sid')
+   ```
+- get details of a call
+
+   ```
+   client.call_details('call_sid')
+   ```
+
+
+## Authors and Contributors ##
+
+In 2015, Sarath S Pllai ([@sarath_sp06](https://twitter.com/sarath_sp06)) started .Any bug reports would be addressed .Feel free to add more functions and send me the patch with updated README 
+
+## Support or Contact ##
+Having trouble using the library contact me at sarath.sp06 at gmail.com
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..b94e418
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,38 @@
+exotel-py
+---------
+
+Python module for exotels call and sms api’s
+
+installation
+~~~~~~~~~~~~
+
+``pip install exotel``
+
+Usage
+-----
+
+-  Initialize
+
+    ``from exotel import Exotel``
+
+    ``client = Exotel(sid,token)``
+
+- make call to connect a number to another
+
+    ``client.call_number('from_number','exophone','to_number')``
+
+-  make call to connect a number to a flow
+
+    ``client.call_flow('from_number','exophone','flow_id')``
+
+-  send an sms
+
+    ``client.sms('from_number',to_number',"sms_body")``
+
+- get details of an sms
+
+    ``client.sms_details('sms_sid')``
+
+- get details of a call
+
+    ``client.call_details('call_sid')``
diff --git a/exotel/__init__.py b/exotel/__init__.py
new file mode 100644
index 0000000..cf1efee
--- /dev/null
+++ b/exotel/__init__.py
@@ -0,0 +1 @@
+from .exotel import Exotel
diff --git a/exotel/_compat.py b/exotel/_compat.py
new file mode 100644
index 0000000..f224e68
--- /dev/null
+++ b/exotel/_compat.py
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+try:  # pragma: no cover
+    # py3
+    from urllib.parse import urljoin
+except ImportError:  # pragma: no cover
+    # py2
+    from urlparse import urljoin
diff --git a/exotel/exotel.py b/exotel/exotel.py
new file mode 100644
index 0000000..d50c75b
--- /dev/null
+++ b/exotel/exotel.py
@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+
+
+import datetime
+import requests
+
+from ._compat import urljoin
+
+
+class Exotel:
+    def __init__(self,sid,token, baseurl='https://twilix.exotel.in/'):
+        self.sid =  sid
+        self.token = token
+        self.baseurl = urljoin(baseurl, 'v1/Accounts/{sid}/'.format(sid=sid))
+
+    def sms(self, from_number, to, body,encoding_type = "plain", priority = "normal", status_callback = None ):
+        """
+        sms - sends sms using exotel api
+        """
+        return requests.post(urljoin(self.baseurl, 'Sms/send.json'),
+            auth = (self.sid, self.token),
+            data = {
+                'From': from_number,
+                'To': to,
+                'Body': body,
+                'EncodingType':encoding_type,
+                'Priority' : priority,
+                'StatusCallback' : status_callback
+             })
+
+    def call_flow(self,from_number,caller_id,flow_id,timelimit = 14400,timeout = 30,status_callback=None,custom_data = None):
+       """
+       call_flow -creates a call to from_number and flow_id with the exophone(caller_id)
+       """
+       return requests.post(urljoin(self.baseurl, 'Calls/connect.json'),
+        auth=(self.sid, self.token),
+        data={
+            'From': from_number,
+            'CallerId': caller_id,
+            'Url': "http://my.exotel.in/exoml/start/{flow_id}".format(flow_id=flow_id),
+            'TimeLimit': timelimit,
+            'CallType': "trans",
+            'TimeOut' : timeout,
+            'StatusCallback' : status_callback,
+            'CustomField' : custom_data
+
+        })
+
+    def call_number(self, from_number, caller_id, to,timelimit = 14400,timeout = 30,status_callback=None,custom_data = None):
+       """
+       call_number -creates a call to from_number and then to with the exophone(caller_id)
+       """
+       return requests.post(urljoin(self.baseurl, 'Calls/connect.json'),
+        auth=(self.sid, self.token),
+        data={
+            'From': from_number,
+            'CallerId': caller_id,
+            'To': to,
+            'TimeLimit': timelimit,
+            'CallType': "trans",
+            'TimeOut' : timeout,
+            'CustomField' : custom_data,
+            'StatusCallback' : status_callback
+        })
+
+    def call_details(self, call_sid):
+      """
+       call_details - returns call details object as a response object
+      """
+      return requests.get(urljoin(self.baseurl, 'Calls/{}.json'.format(call_sid)), auth=(self.sid, self.token))
+
+    def sms_details(self, sms_sid):
+      """
+       sms_details - returns sms details object as a response object provided the sms sid
+      """
+      return requests.get(urljoin(self.baseurl, 'Sms/Messages/{}.json'.format(sms_sid)), auth=(self.sid, self.token))
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..756c862
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,6 @@
+coverage==4.4.1
+docutils==0.13.1
+requests==2.18.1
+requests-mock==1.3.0
+pytest==3.1.3
+pytest-cov==2.5.1
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..d2784c5
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,63 @@
+from setuptools import setup, find_packages
+
+setup(
+    # Application name:
+    name="exotel",
+
+    # Version number (initial):
+    version="0.1.5",
+
+    # Application author details:
+    author="sarath",
+    author_email="sarath.sp06 at gmail.com",
+
+    # Packages
+    packages=find_packages(),
+
+    # Details
+    url="https://github.com/sarathsp06/exotel-py",
+    download_url = 'https://github.com/sarathsp06/exotel-py/archive/v0.1.5.tar.gz',
+    license="LICENSE.txt",
+    description="Python SDK for Exotel API[Unofficial]",
+    long_description="""
+exotel-py
+---------
+
+Python module for exotels call and sms api's
+
+installation
+~~~~~~~~~~~~
+
+``pip install exotel``
+
+Usage
+-----
+
+-  Initialize
+
+    ``from exotel import Exotel``
+
+    ``client = Exotel(sid,token)``
+
+- make call to connect a number to another
+
+    ``client.call_number('from_number','exophone','to_number')``
+
+-  make call to connect a number to a flow
+
+    ``client.call_flow('from_number','exophone','flow_id')``
+
+-  send an sms
+
+    ``client.sms('from_number',to_number',"sms_body")``
+
+- get details of an sms
+
+    ``client.sms_details('sms_sid')``
+
+- get details of a call
+
+    ``client.call_details('call_sid')``
+
+"""
+)
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..205dbc0
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+
+
+import pytest
+import requests_mock
+
+
+ at pytest.fixture(scope='function', autouse=True)
+def mock_http():
+    """pytest fixture to intercept outbound HTTP requests."""
+
+    with requests_mock.mock() as m:
+        yield m
diff --git a/tests/test_exotel.py b/tests/test_exotel.py
new file mode 100644
index 0000000..d13b6a3
--- /dev/null
+++ b/tests/test_exotel.py
@@ -0,0 +1,96 @@
+# -*- coding: utf-8 -*-
+
+
+from exotel import Exotel
+
+
+def test_sms(mock_http):
+    mock_http.register_uri(
+        'POST',
+        'https://twilix.exotel.in/v1/Accounts/123/Sms/send.json',
+        text=''.join((
+            '<?xml version="1.0" encoding="UTF-8"?>',
+            '<TwilioResponse>',
+            '<SMSMessage>...</SMSMessage>',
+            '</TwilioResponse>',
+        )),
+    )
+    e = Exotel(sid='123', token='abc')
+    rep = e.sms(
+        from_number='012-345-6789',
+        to='345-678-9012',
+        body='Hello, world!',
+    )
+    assert rep.status_code == 200
+
+
+def test_call_flow(mock_http):
+    mock_http.register_uri(
+        'POST',
+        'https://twilix.exotel.in/v1/Accounts/123/Calls/connect.json',
+        text=''.join((
+            '<?xml version="1.0" encoding="UTF-8"?>',
+            '<TwilioResponse>',
+            '<Call>...</Call>',
+            '</TwilioResponse>',
+        )),
+    )
+    e = Exotel(sid='123', token='abc')
+    rep = e.call_flow(
+        from_number='012-345-6789',
+        caller_id='345-678-9012',
+        flow_id='345',
+    )
+    assert rep.status_code == 200
+
+
+def test_call_number(mock_http):
+    mock_http.register_uri(
+        'POST',
+        'https://twilix.exotel.in/v1/Accounts/123/Calls/connect.json',
+        text=''.join((
+            '<?xml version="1.0" encoding="UTF-8"?>',
+            '<TwilioResponse>',
+            '<Call>...</Call>',
+            '</TwilioResponse>',
+        )),
+    )
+    e = Exotel(sid='123', token='abc')
+    rep = e.call_number(
+        from_number='012-345-6789',
+        to='345-678-9012',
+        caller_id='678-901-2345',
+    )
+    assert rep.status_code == 200
+
+
+def test_call_details(mock_http):
+    mock_http.register_uri(
+        'GET',
+        'https://twilix.exotel.in/v1/Accounts/123/Calls/234.json',
+        text=''.join((
+            '<?xml version="1.0" encoding="UTF-8"?>',
+            '<TwilioResponse>',
+            '<Call>...</Call>',
+            '</TwilioResponse>',
+        )),
+    )
+    e = Exotel(sid='123', token='abc')
+    rep = e.call_details(call_sid='234')
+    assert rep.status_code == 200
+
+
+def test_sms_details(mock_http):
+    mock_http.register_uri(
+        'GET',
+        'https://twilix.exotel.in/v1/Accounts/123/Sms/Messages/234.json',
+        text=''.join((
+            '<?xml version="1.0" encoding="UTF-8"?>',
+            '<TwilioResponse>',
+            '<Call>...</Call>',
+            '</TwilioResponse>',
+        )),
+    )
+    e = Exotel(sid='123', token='abc')
+    rep = e.sms_details(sms_sid='234')
+    assert rep.status_code == 200
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..0e9a29c
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,12 @@
+[tox]
+envlist = py27,py35
+
+[testenv]
+deps =
+  -rrequirements.txt
+commands =
+  py35: python setup.py check -s -r
+  coverage erase
+  coverage run -m pytest {posargs:-s -vv tests/}
+  coverage html
+  coverage report --fail-under=100

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-exotel.git



More information about the Python-modules-commits mailing list