Skip to content

Commit 710b78a

Browse files
committed
Initial commit
0 parents  commit 710b78a

10 files changed

Lines changed: 282 additions & 0 deletions

File tree

.gitignore

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Created by https://www.gitignore.io/api/python,pycharm
2+
3+
### Python ###
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*,cover
46+
.hypothesis/
47+
48+
# Translations
49+
*.mo
50+
*.pot
51+
52+
# Django stuff:
53+
*.log
54+
local_settings.py
55+
56+
# Flask stuff:
57+
instance/
58+
.webassets-cache
59+
60+
# Scrapy stuff:
61+
.scrapy
62+
63+
# Sphinx documentation
64+
docs/_build/
65+
66+
# PyBuilder
67+
target/
68+
69+
# IPython Notebook
70+
.ipynb_checkpoints
71+
72+
# pyenv
73+
.python-version
74+
75+
# celery beat schedule file
76+
celerybeat-schedule
77+
78+
# dotenv
79+
.env
80+
81+
# virtualenv
82+
venv/
83+
ENV/
84+
85+
# Spyder project settings
86+
.spyderproject
87+
88+
# Rope project settings
89+
.ropeproject
90+
91+
92+
### PyCharm ###
93+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
94+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
95+
96+
# User-specific stuff:
97+
.idea/*
98+
99+
## File-based project format:
100+
*.iws
101+
102+
## Plugin-specific files:
103+
104+
# IntelliJ
105+
/out/
106+
107+
# mpeltonen/sbt-idea plugin
108+
.idea_modules/
109+
110+
# JIRA plugin
111+
atlassian-ide-plugin.xml
112+
113+
# Crashlytics plugin (for Android Studio and IntelliJ)
114+
com_crashlytics_export_strings.xml
115+
crashlytics.properties
116+
crashlytics-build.properties
117+
fabric.properties
118+
119+
### PyCharm Patch ###
120+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
121+
122+
# *.iml
123+
# modules.xml

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2010-2016 Google, Inc. http://angularjs.org
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Welcome to __Instasent Python SDK__. This repository contains Instasent's Python SDK and samples for REST API.
2+
3+
## Installation
4+
5+
The easiest way to install the instasent package is either via pip:
6+
7+
```
8+
$ pip install instasent
9+
```
10+
11+
or manually by downloading the source and run the setup.py script:
12+
13+
```
14+
$ python setup.py install
15+
```
16+
17+
## Example
18+
### Send an SMS
19+
You can check 'examples/send-sms.py' file.
20+
```python
21+
22+
import instasent
23+
24+
client = instasent.Client('my-token')
25+
response = client.send_sms('Mi company', '+34666666666', 'test message')
26+
27+
print response['response_code']
28+
print response['response_body']
29+
30+
```
31+
## Available functions
32+
```
33+
instasent.send_sms(sender, to, text)
34+
instasent.get_sms(page, per_page)
35+
instasent.get_sms_by_id(message_id)
36+
```
37+
## Documentation
38+
Complete documentation at :
39+
[http://docs.instasent.com/](http://docs.instasent.com/).
40+
41+
# Getting help
42+
43+
If you need help installing or using the library, please contact Instasent Support at support@instasent.com first.
44+
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!

examples/get-sms-by-id.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import instasent
2+
3+
client = instasent.Client('my-token')
4+
response = client.get_sms_by_id('id')
5+
6+
print response['response_code']
7+
print response['response_body']

examples/get-sms.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import instasent
2+
3+
client = instasent.Client('my-token')
4+
response = client.get_sms(1, 50)
5+
6+
print response['response_code']
7+
print response['response_body']
8+

examples/send-sms.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import instasent
2+
3+
client = instasent.Client('my-token')
4+
response = client.send_sms('My company', '+34666666666', 'test message')
5+
6+
print response['response_code']
7+
print response['response_body']

instasent/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from instasent.client import Client

instasent/client.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import json
2+
import requests
3+
4+
5+
class Client(object):
6+
rootEndpoint = 'http://api.instasent.com/'
7+
secureChannel = 'https://api.instasent.com/'
8+
useSecureChannel = True
9+
10+
def __init__(self, token, use_secure_channel=True):
11+
self.token = token
12+
self.useSecureChannel = use_secure_channel
13+
14+
def send_sms(self, sender, to, text, client_id=''):
15+
if self.useSecureChannel:
16+
url = self.secureChannel + 'sms/'
17+
else:
18+
url = self.rootEndpoint + 'sms/'
19+
20+
http_method = 'POST'
21+
22+
data = {'from': sender, 'to': to, 'text': text}
23+
24+
return self.execute_request(url, http_method, data)
25+
26+
def get_sms_by_id(self, id):
27+
if self.useSecureChannel:
28+
url = self.secureChannel + 'sms/' + id
29+
else:
30+
url = self.rootEndpoint + 'sms/' + id
31+
32+
http_method = 'GET'
33+
34+
return self.execute_request(url, http_method)
35+
36+
def get_sms(self, page=1, per_page=10):
37+
if self.useSecureChannel:
38+
url = self.secureChannel + 'sms/?page=' + str(page) + 'per_page=' + str(per_page)
39+
else:
40+
url = self.rootEndpoint + 'sms/?page=' + str(page) + 'per_page=' + str(per_page)
41+
42+
http_method = 'GET'
43+
44+
return self.execute_request(url, http_method)
45+
46+
def execute_request(self, url='', http_method='', data=''):
47+
headers = {'Authorization': 'Bearer ' + self.token}
48+
49+
if http_method == 'GET':
50+
response = requests.get(url, headers=headers)
51+
elif http_method == 'POST':
52+
response = requests.post(url, data=json.dumps(data), headers=headers)
53+
54+
return {'response_body': response.json(), 'response_code': response.status_code}
55+

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description-file = README.md

setup.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from setuptools import setup
2+
3+
setup(
4+
name='instasent',
5+
packages=['instasent'],
6+
version='0.1.3',
7+
description="Instasent's REST API",
8+
author='Instasent',
9+
author_email='support@instasent.com',
10+
url='https://github.com/instasent/instasent-python-lib',
11+
download_url='https://github.com/instasent/instasent-python-lib/archive/master.zip',
12+
keywords=['instasent', 'sms'],
13+
install_requires=['requests'],
14+
)

0 commit comments

Comments
 (0)