Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
senenh committed May 23, 2016
0 parents commit 63f04ae
Show file tree
Hide file tree
Showing 7 changed files with 313 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.
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Welcome to __Instasent PHP SDK__. This repository contains Instasent's PHP SDK and samples for REST API.

## Installation

You can install **instasent-php-lib** via composer or by downloading the source.

#### Via Composer:

You need to run:

```
composer require "instasent/instasent-php-lib"
```

#### Via ZIP file:

[Click here to download the source
(.zip)](https://github.com/instasent/instasent-php-lib/zipball/master)

Once you download the library, move the instasent-php-lib folder to your project
directory and then include the library file:

require '/path/to/instasent-php-lib/src/Instasent/InstasentClient.php';

and now you can use it!

## Quickstart

### Send an SMS

You can check 'examples/send-sms.php' file.

#### Composer way

```php
<?php

require __DIR__ . '/../vendor/autoload.php';

$instasentClient = new Instasent\InstasentClient("my-token");
$response = $instasentClient->sendSms("test", "+34647000000", "test message");

echo $response["response_code"];
echo $response["response_body"];
```

#### Direct way

```php
<?php

require_once(__DIR__ . '/path/to/lib/InstasentClient.php');

$instasentClient = new Instasent\InstasentClient("my-token");
$response = $instasentClient->sendSms("test", "+34647000000", "test message");

echo $response["response_code"];
echo $response["response_body"];
```

### Get SMS Info

#### Composer way

```php

require __DIR__ . '/../vendor/autoload.php';

$instasentClient = new Instasent\InstasentClient("my-token");
$response = $instasentClient->getSmsById("smsId");

echo $response["response_code"];
echo $response["response_body"];
```

#### Direct way

```php

require_once(__DIR__ . '/path/to/lib/InstasentClient.php');

$instasentClient = new Instasent\InstasentClient("my-token");
$response = $instasentClient->getSmsById("smsId");

echo $response["response_code"];
echo $response["response_body"];
```

## [Full Documentation](http://docs.instasent.com/)

## Prerequisites

* PHP >= 5.2.3

# 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!
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
54 changes: 54 additions & 0 deletions instasent/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import json
import requests


class Client(object):
rootEndpoint = 'http://api.instasent.codes/'
secureChannel = 'http://api.instasent.codes/'
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=' + page + 'per_page=' + per_page
else:
url = self.rootEndpoint + 'sms/?page=' + page + 'per_page=' + 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.json()
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.0',
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/tarball/0.1.0',
keywords=['instasent', 'sms'],
install_requires=['requests'],
)

0 comments on commit 63f04ae

Please sign in to comment.