Skip to content

Commit 453b2f2

Browse files
author
Cameron James
committed
Version bump
1 parent 10979a1 commit 453b2f2

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ client = bigdatacloudapi.Client(apiKey)
5858
resultObject,httpResponseCode = client.getIpGeolocationFull({"ip":"8.8.8.8"})
5959

6060
print('HTTP Response Code: ',httpResponseCode)
61-
print('Result: ',resultObject['ip'])
62-
print('Result: ',resultObject['ip'])
61+
print('Lookup IP: ',resultObject['ip'])
62+
print('Result: ',resultObject)
6363
```
6464

6565

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from bigdatacloudapi.client import Client
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import requests
2+
import re
3+
import json
4+
5+
class Client:
6+
def __init__(
7+
self,
8+
apiKey,
9+
nameSpace='data',
10+
server='api.bigdatacloud.net'
11+
):
12+
self.apiKey=apiKey
13+
self.nameSpace=nameSpace
14+
self.server=server
15+
16+
def __getattr__(self,p):
17+
def mm(params):
18+
def conversion(m):
19+
return "-"+m.group(1).lower()
20+
21+
key = re.sub('([A-Z])',conversion,p)
22+
segs = key.split('-')
23+
method = segs.pop(0).upper()
24+
25+
return self.communicate('-'.join(segs),method,params)
26+
return mm
27+
28+
def communicate(self,endpoint,method,payload):
29+
url='https://'+self.server+'/'+self.nameSpace+'/'+endpoint
30+
31+
headers={'X-BDC-Key':self.apiKey}
32+
33+
if (method=='POST' or method=='PUT' or method=='PATCH'):
34+
headers['content-type']='application/x-www-form-urlencoded'
35+
36+
r=getattr(requests,method.lower())(url,headers=headers,params=payload,data=payload)
37+
38+
return [r.json(),r.status_code]

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# This call to setup() does all the work
1212
setup(
1313
name="bigdatacloudapi-client",
14-
version="1.0.0",
14+
version="1.0.1",
1515
description="A Python client for BigDataCloud API connectivity (https://www.bigdatacloud.net)",
1616
long_description=README,
1717
long_description_content_type="text/markdown",
@@ -26,5 +26,5 @@
2626
"Programming Language :: Python :: 3",
2727
],
2828
packages=["bigdatacloudapi"],
29-
install_requires=["requests","re","json"]
29+
install_requires=["requests"]
3030
)

0 commit comments

Comments
 (0)