diff --git a/agithub/BingMaps.py b/agithub/BingMaps.py new file mode 100644 index 0000000..308cbee --- /dev/null +++ b/agithub/BingMaps.py @@ -0,0 +1,19 @@ +# Copyright 2012-2016 Jonathan Paugh and contributors +# See COPYING for license details +from agithub.base import API, ConnectionProperties, Client + +class BingMaps(API): + ''' + Bing REST API + ''' + def __init__(self, *args, **kwargs): + props = ConnectionProperties( + api_url = 'spatial.virtualearth.net' + , url_prefix = '/REST/v1' + , secure_http = True + , default_url_parameters = { + 'key' : kwargs.pop('queryKey', None) + } + ) + self.setClient(Client(*args, **kwargs)) + self.setConnectionProperties(props) diff --git a/agithub/base.py b/agithub/base.py index 8e2b12e..a2ae668 100644 --- a/agithub/base.py +++ b/agithub/base.py @@ -213,9 +213,28 @@ def _fix_headers(self, headers): headers[k] = v return headers - def urlencode(self, params): - if not params: - return '' + def urlencode(self, userParams): + ''' + URL Encode the parameters for the request + + If the api specifies default parameters, these can be overridden + explicitly; or, they can be disabled by setting param=None on a + given request + ''' + if self.prop.default_url_parameters is None: + if userParams is None: + return '' + else: + params = userParams + else: + params = self.prop.default_url_parameters.copy(); + for k,v in userParams.items(): + params[k] = v + + # user can pass None to un-set a default param for one + # request + params = dict((k, v) for k, v in params.items() if v is not None) + return '?' + urllib.parse.urlencode(params) def get_connection(self): @@ -381,7 +400,9 @@ def application_json(self): # Insert new Request media-type handlers here class ConnectionProperties(object): - __slots__ = ['api_url', 'url_prefix', 'secure_http', 'extra_headers'] + __slots__ = [ + 'api_url', 'url_prefix', 'secure_http', 'extra_headers' + , 'default_url_parameters' ] def __init__(self, **props): # Initialize attribute slots