Skip to content

Commit

Permalink
Add verify, lookup and account functions
Browse files Browse the repository at this point in the history
  • Loading branch information
senenh committed Aug 26, 2016
1 parent 710b78a commit 5812180
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,25 @@ print response['response_body']
```
## Available functions
```
SMS
instasent.send_sms(sender, to, text)
instasent.get_sms(page, per_page)
instasent.get_sms_by_id(message_id)
VERIFY
instasent.request_verify(sender, to, text); // text must include %token% string
instasent.check_verify(id, token)
instasent.get_verify_by_id(id)
instasent.get_verify()
LOOKUP
instasent.do_lookup(to)
instasent.get_lookup_by_id(id)
instasent.get_lookups(page, per_page)
ACCOUNT
instasent.get_account_balance()
```
## Documentation
Complete documentation at :
Expand Down
7 changes: 7 additions & 0 deletions examples/account/get-account-value.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_account_balance()

print response['response_code']
print response['response_body']
7 changes: 7 additions & 0 deletions examples/lookup/do-lookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import instasent

client = instasent.Client('my-token')
response = client.do_lookup('+34666666666')

print response['response_code']
print response['response_body']
7 changes: 7 additions & 0 deletions examples/lookup/get-lookup-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_lookup_by_id('id')

print response['response_code']
print response['response_body']
7 changes: 7 additions & 0 deletions examples/lookup/get-lookups.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_lookups('id')

print response['response_code']
print response['response_body']
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions examples/verify/check-verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import instasent

client = instasent.Client('my-token')
response = client.check_verify('id', 'token')

print response['response_code']
print response['response_body']
7 changes: 7 additions & 0 deletions examples/verify/get-verify-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_verify('id')

print response['response_code']
print response['response_body']
7 changes: 7 additions & 0 deletions examples/verify/get-verify.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_verify(1, 10)

print response['response_code']
print response['response_body']
7 changes: 7 additions & 0 deletions examples/verify/request-verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import instasent

client = instasent.Client('my-token')
response = client.request_verify('My company', '+34666666666', 'Your code is %token%')

print response['response_code']
print response['response_body']
71 changes: 69 additions & 2 deletions instasent/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Client(object):
rootEndpoint = 'http://api.instasent.com/'
rootEndpoint = 'https://api.instasent.com/'
secureChannel = 'https://api.instasent.com/'
useSecureChannel = True

Expand Down Expand Up @@ -43,8 +43,75 @@ def get_sms(self, page=1, per_page=10):

return self.execute_request(url, http_method)

def request_verify(self, sender, to, text, token_length='', timeout='', client_id=''):
url = self.secureChannel + 'verify/' if self.useSecureChannel else self.rootEndpoint + 'verify/'
http_method = 'POST'
data = {'sms': {'from': sender, 'to': to, 'text': text}}

if client_id != '':
data['clientId'] = client_id

if token_length != '':
data['tokenLength'] = token_length

if timeout != '':
data['timeout'] = timeout

return self.execute_request(url, http_method, data)

def check_verify(self, id, token):
url = self.secureChannel + 'verify/' + id if self.useSecureChannel else self.rootEndpoint + 'verify/' + id
url += '?token=' + token
http_method = 'GET'

return self.execute_request(url, http_method, {})

def get_verify_by_id(self, id):
url = self.secureChannel + 'verify/' + id if self.useSecureChannel else self.rootEndpoint + 'verify/' + id
http_method = 'GET'

return self.execute_request(url, http_method, {})

def get_verify(self, page=1, per_page=10):
if self.useSecureChannel:
url = self.secureChannel + 'verify/?page=' + str(page) + 'per_page=' + str(per_page)
else:
url = self.rootEndpoint + 'verify/?page=' + str(page) + 'per_page=' + str(per_page)

http_method = 'GET'

return self.execute_request(url, http_method)

def do_lookup(self, to):
url = self.secureChannel + 'lookup/' if self.useSecureChannel else self.rootEndpoint + 'lookup/'
http_method = 'POST'
data = {'to': to}

return self.execute_request(url, http_method, data)

def get_lookup_by_id(self, id):
url = self.secureChannel + 'lookup/' + id if self.useSecureChannel else self.rootEndpoint + 'lookup/' + id
http_method = 'GET'

return self.execute_request(url, http_method, {})

def get_lookups(self, page=1, per_page=10):
if self.useSecureChannel:
url = self.secureChannel + 'lookup/?page=' + str(page) + 'per_page=' + str(per_page)
else:
url = self.rootEndpoint + 'lookup/?page=' + str(page) + 'per_page=' + str(per_page)
http_method = 'GET'

return self.execute_request(url, http_method, {})

def get_account_balance(self):
url = self.secureChannel + 'organization/account/' if self.useSecureChannel else self.rootEndpoint + 'organization/account/'
http_method = 'GET'

return self.execute_request(url, http_method, {})

def execute_request(self, url='', http_method='', data=''):
headers = {'Authorization': 'Bearer ' + self.token}
headers = {'Authorization': 'Bearer ' + self.token, 'Accept': 'application/json', 'Content-Type': 'application/json'}

if http_method == 'GET':
response = requests.get(url, headers=headers)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
setup(
name='instasent',
packages=['instasent'],
version='0.1.3',
version='0.1.4',
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',
download_url='https://github.com/instasent/instasent-python-lib/tarball/0.1.4',
keywords=['instasent', 'sms'],
install_requires=['requests'],
)

0 comments on commit 5812180

Please sign in to comment.