Skip to content

Commit

Permalink
base url is now configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Fields committed Apr 11, 2012
1 parent 54bb10d commit d69d239
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/entity.py
Expand Up @@ -7,11 +7,21 @@
from ConfigParser import SafeConfigParser
from os.path import exists as pexists, join as pjoin, expanduser

#cascading config vars
config_path = pjoin(expanduser('~'), '.semetric')
cfg = SafeConfigParser()
try:
BASE_URL = os.environ['BASE_URL']
except KeyError:
try:
cfg.read(pjoin(config_path, 'config'))
BASE_URL = cfg.get('semetric','api.key')
except:
BASE_URL = "http://api.semetric.com/"

try:
API_KEY = os.environ['SEMETRIC_KEY']
except KeyError:
config_path = pjoin(expanduser('~'), '.semetric')
cfg = SafeConfigParser()
cfg.read(pjoin(config_path, 'config'))
API_KEY = cfg.get('semetric','api.key')

Expand Down Expand Up @@ -70,8 +80,8 @@ def response_from(self, ext_endpoint=None, params = {}):
a
"""
params['token'] = API_KEY
base_endpoint="http://api.semetric.com/{entity}/{entityID}"
uri = base_endpoint.format(entity=self.entity_type,entityID=self.entity_id)
base_endpoint="{base_url}/{entity}/{entityID}"
uri = base_endpoint.format(base_url=BASE_URL, entity=self.entity_type, entityID=self.entity_id)
if ext_endpoint:
if ext_endpoint[0] != '/':
ext_endpoint = '/' + ext_endpoint
Expand Down

0 comments on commit d69d239

Please sign in to comment.