-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzipcode.py
More file actions
33 lines (24 loc) · 813 Bytes
/
Copy pathzipcode.py
File metadata and controls
33 lines (24 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import json
from nameko.rpc import rpc, RpcProxy
import requests
default_baseurl = "https://service-homolog.digipix.com.br/v0b"
baseurl = os.getenv('BASEURL', default_baseurl)
headers = {"Authorization": "Bearer {}".format(os.getenv('JWT'))}
def getResponse(qstring):
resp = requests.request('GET', qstring, headers=headers)
return resp.json()
class ZipCodeService:
name = "zipcode"
zipcode_rpc = RpcProxy('zipcodeservice')
@rpc
def getZipcode(self, zipcode):
endpoint = '/shipments/zipcode/'
try:
if zipcode is None:
raise ValueError("Missing ZipCode")
qstring = (baseurl + endpoint + zipcode)
return getResponse(qstring)
except ValueError:
print ValueError
sys.exit()