From 16342123a25fc85dca8e0d9e24fe1c49ec78b646 Mon Sep 17 00:00:00 2001 From: Michael Karpitsky Date: Thu, 25 Jul 2013 16:30:17 +0300 Subject: [PATCH] Project formatted to python package. --- .gitignore | 8 +++ LICENSE.txt | 24 +++++++ README | 3 - README.md | 63 +++++++++++++++++++ nexmosample.py => demos/simple/nexmosample.py | 0 nexmomessage/__init__.py | 1 + nexmomessage.py => nexmomessage/nexmo.py | 2 + setup.py | 20 ++++++ 8 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 LICENSE.txt delete mode 100644 README create mode 100644 README.md rename nexmosample.py => demos/simple/nexmosample.py (100%) create mode 100644 nexmomessage/__init__.py rename nexmomessage.py => nexmomessage/nexmo.py (99%) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba24073 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*~ +*.pyc +build/* +dist/* +*/dist/* +*.egg +*.egg-info +src/*.egg-info/* \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..0f41508 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,24 @@ +Copyright (c) 2013 Marco Londero +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README b/README deleted file mode 100644 index 1f84fcc..0000000 --- a/README +++ /dev/null @@ -1,3 +0,0 @@ -Simple python library to interact with Nexmo API - -See "nexmosample.py" for usage diff --git a/README.md b/README.md new file mode 100644 index 0000000..9175653 --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +nexmomessage +============ + + +A Python wrapper for the [Nexmo API](https://www.nexmo.com/documentation/api/index.html). + + +Installation +------------ + + $ pip install -e git+https://github.com/marcuz/libpynexmo.git#egg=nexmomessage + + +Quick start (sending a message) +------------------------------- + +First you need to load up the package and construct a dictionary +with your API credentials and message, like this: + +```python +from nexmomessage import NexmoMessage + +msg = { + 'reqtype': 'json', + 'api_key': YOUR_API_KEY, + 'api_secret': YOUR_API_SECRET_KEY, + 'from': YOUR_PHONE_NUMBER, + 'to': DESTINATION_PHONE_NUMBER, + 'text': 'Hello world!' +} +sms = NexmoMessage(msg) +sms.set_text_info(msg['text']) +``` + +Then you have a choice. For a "fire and forget" approach to sending a message, +use the `send_message` method, like this: + +```python +sms.send_request() +``` + +This method call returns the message data if the message was sent successfully, +or return Flase if there was an error. + +```python +response = sms.send_request() + +if response: + # do something with response data +else: + # handle the error +``` + + +Troubleshooting +--------------- + +Remember that phone numbers should be specified in international format. + +The Nexmo documentation contains a [list of error codes](http://nexmo.com/documentation/index.html#response_code) +which may be useful if you have problems sending a message. + +Please report all bugs/issues via the GitHub issue tracker. \ No newline at end of file diff --git a/nexmosample.py b/demos/simple/nexmosample.py similarity index 100% rename from nexmosample.py rename to demos/simple/nexmosample.py diff --git a/nexmomessage/__init__.py b/nexmomessage/__init__.py new file mode 100644 index 0000000..f2528a8 --- /dev/null +++ b/nexmomessage/__init__.py @@ -0,0 +1 @@ +from nexmo import NexmoMessage diff --git a/nexmomessage.py b/nexmomessage/nexmo.py similarity index 99% rename from nexmomessage.py rename to nexmomessage/nexmo.py index 177ab4e..e6a3486 100644 --- a/nexmomessage.py +++ b/nexmomessage/nexmo.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- # # Copyright (c) 2013 Marco Londero # All rights reserved. diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ac7d158 --- /dev/null +++ b/setup.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +try: + from setuptools import setup +except ImportError: + from distutils.core import setup + +VERSION = '0.1.0' + +setup( + name='nexmomessage', + version=VERSION, + description='A Python wrapper for the Nexmo API', + author='Marco Londero', + author_email='marco.londero@linux.it', + license='BSD', + url='https://github.com/marcuz/libpynexmo', + keywords=['Nexmo', 'Python'], + packages=['nexmomessage'], +) \ No newline at end of file