Permalink
Browse files

Made dataset and table args object attributes instead of passing them…

… around.
  • Loading branch information...
1 parent 489d3cc commit c626bfaa32d46fc2aa1126af51ea45762d317b10 @mattdeboard committed Jul 23, 2011
Showing with 9 additions and 9 deletions.
  1. +9 −9 python_usdol.py
View
@@ -45,23 +45,21 @@ def _get_timestamp(self):
return (t, t.isoformat()+'Z')
def _get_message(self):
+ baseurl = '/%s/%s/' % (API_VER, self.dataset)
+ if self.table != '$metadata':
+ baseurl += self.table
date_time, timestamp = self._get_timestamp()
header_dict = {"Timestamp": timestamp, "ApiKey": self.token}
- return (header_dict, '%s&%s' % (self.baseurl,
- self._urlencode(header_dict)))
+ return (header_dict, '%s&%s' % (.baseurl, self._urlencode(header_dict)))
def _get_header(self):
d, message = self._get_message()
h = hmac.new(self.secret, message, hashlib.sha1)
d['Signature'] = h.hexdigest()
return self._urlencode(d)
- def _get_request(self, ds, table, fmt='json'):
- url_args = [USDOL_URL, API_VER, d]
- t = '$metadata'
- if t:
- t = table
- url_args.append(t)
+ def _get_request(self, fmt='json'):
+ url_args = [USDOL_URL, API_VER, self.dataset, self.table]
header = self._get_header()
qs = url_args.join('/')
# url = urlparse.urljoin(USDOL_URL, qs)
@@ -76,13 +74,15 @@ def fetch_data(self, dataset, table='$metadata', fmt='json'):
'fmt' is json by default. Valid choices are 'xml' and 'json'.
'''
+ self.dataset = dataset
+ self.table = table
enc_opts = ['json', 'xml']
if fmt not in enc_opts:
raise AttributeError("Valid format choices are: json, xml")
if table == '$metadata' and fmt != 'xml':
fmt = 'xml'
- urlstr = self._get_request(dataset, table, fmt)
+ urlstr = self._get_request(fmt)
data = urllib2.urlopen(urlstr)
if fmt == 'json':
ret = json.loads(data.read())

0 comments on commit c626bfa

Please sign in to comment.