Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
senenh committed May 30, 2016
0 parents commit 710b78a
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 0 deletions.
123 changes: 123 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 [email protected] 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!
7 changes: 7 additions & 0 deletions examples/get-sms-by-id.py
Original file line number Diff line number Diff line change
@@ -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']
8 changes: 8 additions & 0 deletions examples/get-sms.py
Original file line number Diff line number Diff line change
@@ -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']

7 changes: 7 additions & 0 deletions examples/send-sms.py
Original file line number Diff line number Diff line change
@@ -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']
1 change: 1 addition & 0 deletions instasent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from instasent.client import Client
55 changes: 55 additions & 0 deletions instasent/client.py
Original file line number Diff line number Diff line change
@@ -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}

2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
14 changes: 14 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
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'],
)

0 comments on commit 710b78a

Please sign in to comment.