Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions agithub/BingMaps.py
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 25 additions & 4 deletions agithub/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down