Skip to content

Commit dfbe157

Browse files
committed
Bumped v1
Signed-off-by: Vishal Rana <[email protected]>
1 parent 5b40e3b commit dfbe157

19 files changed

+281
-99
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
test:
2+
nose2
3+
14
publish:
25
rm -rf dist
36
python setup.py sdist bdist_wheel

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Create a file `app.py` with the following content:
1414

1515
```python
16-
from labstack import Client, APIError
16+
from labstack import Client, LabStackError
1717

1818
client = new Client('<API_KEY>')
1919
geocode = client.geocode()

fix_virtualenv

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
ENV_PATH="$(dirname "$(dirname "$(which pip)")")"
3+
SYSTEM_VIRTUALENV="$(which -a virtualenv|tail -1)"
4+
5+
echo "Ensure the root of current virtualenv:"
6+
echo " $ENV_PATH"
7+
read -p "‼️ Say no if you are not sure (y/N) " -n 1 -r
8+
echo
9+
if [[ $REPLY =~ ^[Yy]$ ]]; then
10+
echo "♻️ Removing old symbolic links......"
11+
find "$ENV_PATH" -type l -delete -print
12+
echo "💫 Creating new symbolic links......"
13+
$SYSTEM_VIRTUALENV "$ENV_PATH"
14+
echo "🎉 Done!"
15+
fi

labstack/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# from .client import Client, APIError
2-
from .axis import Axis
1+
from .client import Client, LabStackError

labstack/axis.py

-79
This file was deleted.

labstack/client.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import requests
2+
from .currency import CurrencyService
3+
from .domain import DomainService
4+
from .email import EmailService
5+
from .ip import IPService
6+
from .webpage import WebpageService
7+
8+
9+
class _Interceptor(requests.auth.AuthBase):
10+
def __init__(self, key):
11+
self.key = key
12+
13+
def __call__(self, r):
14+
r.headers['Authorization'] = 'Bearer ' + self.key
15+
return r
16+
17+
18+
class Client():
19+
def __init__(self, key):
20+
self.key = key
21+
self.interceptor = _Interceptor(key)
22+
23+
def _request(self, method, url, params=None, files=None, data=None):
24+
r = requests.request(method, url, auth=self.interceptor,
25+
params=params, files=files, data=data)
26+
data = r.json()
27+
if self._is_error(r):
28+
raise LabStackError(data['code'], data['message'])
29+
return data
30+
31+
def _is_error(self, r):
32+
return not 200 <= r.status_code < 300
33+
34+
def currency(self):
35+
return CurrencyService(self)
36+
37+
def domain(self):
38+
return DomainService(self)
39+
40+
def email(self):
41+
return EmailService(self)
42+
43+
def ip(self):
44+
return IPService(self)
45+
46+
def webpage(self):
47+
return WebpageService(self)
48+
49+
50+
class LabStackError(Exception):
51+
def __init__(self, statusCode, code, message):
52+
self.statusCode = statusCode
53+
self.code = code
54+
self.message = message
55+
56+
def __str__(self):
57+
return self.message

labstack/currency.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import requests
2+
3+
4+
class CurrencyService():
5+
def __init__(self, client):
6+
self.client = client
7+
self.url = 'https://currency.labstack.com/api/v1'
8+
9+
def convert(self, request):
10+
return self.client._request('GET', '{}/convert/{}/{}/{}'.
11+
format(self.url, request['amount'],
12+
request['from'], request['to']))
13+
14+
def list(self, request):
15+
return self.client._request('GET', '{}/list'.format(self.url))

labstack/domain.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import requests
2+
3+
4+
class DomainService():
5+
def __init__(self, client):
6+
self.client = client
7+
self.url = 'https://domain.labstack.com/api/v1'
8+
9+
def dns(self, request):
10+
return self.client._request('GET', '{}/{}/{}'.
11+
format(self.url, request['type'], request['domain']))
12+
13+
def search(self, request):
14+
return self.client._request('GET', '{}/search/{}'.
15+
format(self.url, request['domain']))
16+
17+
def status(self, request):
18+
return self.client._request('GET', '{}/status/{}'.
19+
format(self.url, request['domain']))
20+
21+
def whois(self, request):
22+
return self.client._request('GET', '{}/whois/{}'.
23+
format(self.url, request['domain']))

labstack/email.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import requests
2+
3+
4+
class EmailService():
5+
def __init__(self, client):
6+
self.client = client
7+
self.url = 'https://email.labstack.com/api/v1'
8+
9+
def verify(self, request):
10+
return self.client._request('GET', '{}/verify/{}'.
11+
format(self.url, request['email']))

labstack/ip.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import requests
2+
3+
4+
class IPService():
5+
def __init__(self, client):
6+
self.client = client
7+
self.url = 'https://ip.labstack.com/api/v1'
8+
9+
def lookup(self, request):
10+
return self.client._request('GET', '{}/{}'.format(self.url, request['ip']))

labstack/test_currency.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
import unittest
3+
from .client import Client
4+
5+
6+
class TestCurrency(unittest.TestCase):
7+
def setUp(self):
8+
self.s = Client(os.getenv('KEY')).currency()
9+
10+
def test_convert(self):
11+
response = self.s.convert({
12+
'amount': 10,
13+
'from': 'USD',
14+
'to': 'INR'
15+
})
16+
self.assertNotEqual(response['amount'], 0)
17+
18+
def test_list(self):
19+
response = self.s.list({})
20+
self.assertNotEqual(len(response['currencies']), 0)

labstack/test_domain.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
import unittest
3+
from .client import Client
4+
5+
6+
class TestDomain(unittest.TestCase):
7+
def setUp(self):
8+
self.s = Client(os.getenv('KEY')).domain()
9+
10+
def test_dns(self):
11+
response = self.s.dns({
12+
'type': 'A',
13+
'domain': 'twilio.com'
14+
})
15+
self.assertNotEqual(len(response['records']), 0)
16+
17+
def test_search(self):
18+
response = self.s.search({
19+
'domain': 'twilio.com'
20+
})
21+
self.assertNotEqual(len(response['results']), 0)
22+
23+
def test_status(self):
24+
response = self.s.status({
25+
'domain': 'twilio.com'
26+
})
27+
self.assertEqual(response['result'], 'unavailable')
28+
29+
def test_whois(self):
30+
response = self.s.whois({
31+
'domain': 'twilio.com'
32+
})
33+
self.assertNotEqual(response['raw'], '')

labstack/test_email.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import unittest
3+
from .client import Client
4+
5+
6+
class TestEmail(unittest.TestCase):
7+
def setUp(self):
8+
self.s = Client(os.getenv('KEY')).email()
9+
10+
def test_verify(self):
11+
response = self.s.verify({
12+
'email': '[email protected]'
13+
})
14+
self.assertEqual(response['result'], 'deliverable')

labstack/test_ip.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import unittest
3+
from .client import Client
4+
5+
6+
class TestIP(unittest.TestCase):
7+
def setUp(self):
8+
self.s = Client(os.getenv('KEY')).ip()
9+
10+
def test_ip(self):
11+
response = self.s.lookup({
12+
'ip': '96.45.83.67'
13+
})
14+
self.assertNotEqual(response['country'], '')

labstack/test_webpage.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
import unittest
3+
from .client import Client
4+
5+
6+
class TestWebpage(unittest.TestCase):
7+
def setUp(self):
8+
self.s = Client(os.getenv('KEY')).webpage()
9+
10+
def test_image(self):
11+
response = self.s.image({
12+
'url': 'http://amazon.com'
13+
})
14+
self.assertNotEqual(response['image'], '')
15+
16+
def test_pdf(self):
17+
response = self.s.pdf({
18+
'url': 'http://amazon.com'
19+
})
20+
self.assertNotEqual(response['pdf'], '')

labstack/util.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def strip_port(host):
2+
colon = host.find(':')
3+
if colon == -1:
4+
return host
5+
i = host.find(']')
6+
if i != -1:
7+
return host[host.find('(')+1:i]
8+
return host[:colon]

labstack/webpage.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import requests
2+
3+
4+
class WebpageService():
5+
def __init__(self, client):
6+
self.client = client
7+
self.url = 'https://webpage.labstack.com/api/v1'
8+
9+
def image(self, request):
10+
return self.client._request('GET', '{}/image'
11+
.format(self.url), params=request)
12+
13+
def pdf(self, request):
14+
return self.client._request('GET', '{}/pdf'
15+
.format(self.url), params=request)

pyvenv.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
home = /usr/local/opt/python/libexec/bin
2+
include-system-site-packages = false
3+
version = 3.7.4

0 commit comments

Comments
 (0)