diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a07e340 --- /dev/null +++ b/.gitignore @@ -0,0 +1,123 @@ +# Created by https://www.gitignore.io/api/python,pycharm + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject + + +### PyCharm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/* + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### PyCharm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c26264b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2010-2016 Google, Inc. http://angularjs.org + +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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ec01c80 --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +Welcome to __Instasent Python SDK__. This repository contains Instasent's Python SDK and samples for REST API. + +## Installation + +The easiest way to install the instasent package is either via pip: + +``` +$ pip install instasent +``` + +or manually by downloading the source and run the setup.py script: + +``` +$ python setup.py install +``` + +## Example +### Send an SMS +You can check 'examples/send-sms.py' file. +```python + +import instasent + +client = instasent.Client('my-token') +response = client.send_sms('Mi company', '+34666666666', 'test message') + +print response['response_code'] +print response['response_body'] + +``` +## Available functions +``` +instasent.send_sms(sender, to, text) +instasent.get_sms(page, per_page) +instasent.get_sms_by_id(message_id) +``` +## Documentation +Complete documentation at : +[http://docs.instasent.com/](http://docs.instasent.com/). + +# Getting help + +If you need help installing or using the library, please contact Instasent Support at support@instasent.com first. +If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo! \ No newline at end of file diff --git a/examples/get-sms-by-id.py b/examples/get-sms-by-id.py new file mode 100644 index 0000000..2499507 --- /dev/null +++ b/examples/get-sms-by-id.py @@ -0,0 +1,7 @@ +import instasent + +client = instasent.Client('my-token') +response = client.get_sms_by_id('id') + +print response['response_code'] +print response['response_body'] diff --git a/examples/get-sms.py b/examples/get-sms.py new file mode 100644 index 0000000..9736c53 --- /dev/null +++ b/examples/get-sms.py @@ -0,0 +1,8 @@ +import instasent + +client = instasent.Client('my-token') +response = client.get_sms(1, 50) + +print response['response_code'] +print response['response_body'] + diff --git a/examples/send-sms.py b/examples/send-sms.py new file mode 100644 index 0000000..6ba2585 --- /dev/null +++ b/examples/send-sms.py @@ -0,0 +1,7 @@ +import instasent + +client = instasent.Client('my-token') +response = client.send_sms('My company', '+34666666666', 'test message') + +print response['response_code'] +print response['response_body'] \ No newline at end of file diff --git a/instasent/__init__.py b/instasent/__init__.py new file mode 100644 index 0000000..d5b49ac --- /dev/null +++ b/instasent/__init__.py @@ -0,0 +1 @@ +from instasent.client import Client \ No newline at end of file diff --git a/instasent/client.py b/instasent/client.py new file mode 100644 index 0000000..15967e0 --- /dev/null +++ b/instasent/client.py @@ -0,0 +1,55 @@ +import json +import requests + + +class Client(object): + rootEndpoint = 'http://api.instasent.com/' + secureChannel = 'https://api.instasent.com/' + useSecureChannel = True + + def __init__(self, token, use_secure_channel=True): + self.token = token + self.useSecureChannel = use_secure_channel + + def send_sms(self, sender, to, text, client_id=''): + if self.useSecureChannel: + url = self.secureChannel + 'sms/' + else: + url = self.rootEndpoint + 'sms/' + + http_method = 'POST' + + data = {'from': sender, 'to': to, 'text': text} + + return self.execute_request(url, http_method, data) + + def get_sms_by_id(self, id): + if self.useSecureChannel: + url = self.secureChannel + 'sms/' + id + else: + url = self.rootEndpoint + 'sms/' + id + + http_method = 'GET' + + return self.execute_request(url, http_method) + + def get_sms(self, page=1, per_page=10): + if self.useSecureChannel: + url = self.secureChannel + 'sms/?page=' + str(page) + 'per_page=' + str(per_page) + else: + url = self.rootEndpoint + 'sms/?page=' + str(page) + 'per_page=' + str(per_page) + + http_method = 'GET' + + return self.execute_request(url, http_method) + + def execute_request(self, url='', http_method='', data=''): + headers = {'Authorization': 'Bearer ' + self.token} + + if http_method == 'GET': + response = requests.get(url, headers=headers) + elif http_method == 'POST': + response = requests.post(url, data=json.dumps(data), headers=headers) + + return {'response_body': response.json(), 'response_code': response.status_code} + diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..224a779 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..10a0299 --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +from setuptools import setup + +setup( + name='instasent', + packages=['instasent'], + version='0.1.3', + description="Instasent's REST API", + author='Instasent', + author_email='support@instasent.com', + url='https://github.com/instasent/instasent-python-lib', + download_url='https://github.com/instasent/instasent-python-lib/archive/master.zip', + keywords=['instasent', 'sms'], + install_requires=['requests'], +)