|
82 | 82 | VARNAME = re.compile('[a-zA-Z0-9_-]+') |
83 | 83 | DISCOVERY_URI = ('https://www.googleapis.com/discovery/v1/apis/' |
84 | 84 | '{api}/{apiVersion}/rest') |
| 85 | +V1_DISCOVERY_URI = DISCOVERY_URI |
| 86 | +V2_DISCOVERY_URI = ('https://{api}.googleapis.com/$discovery/rest?' |
| 87 | + 'version={apiVersion}') |
85 | 88 | DEFAULT_METHOD_DOC = 'A description of how to use this function' |
86 | 89 | HTTP_PAYLOAD_METHODS = frozenset(['PUT', 'POST', 'PATCH']) |
87 | 90 | _MEDIA_SIZE_BIT_SHIFTS = {'KB': 10, 'MB': 20, 'GB': 30, 'TB': 40} |
@@ -196,21 +199,23 @@ def build(serviceName, |
196 | 199 | if http is None: |
197 | 200 | http = httplib2.Http() |
198 | 201 |
|
199 | | - requested_url = uritemplate.expand(discoveryServiceUrl, params) |
200 | | - |
201 | | - try: |
202 | | - content = _retrieve_discovery_doc(requested_url, http, cache_discovery, |
203 | | - cache) |
204 | | - except HttpError as e: |
205 | | - if e.resp.status == http_client.NOT_FOUND: |
206 | | - raise UnknownApiNameOrVersion("name: %s version: %s" % (serviceName, |
207 | | - version)) |
208 | | - else: |
209 | | - raise e |
| 202 | + for discovery_url in (discoveryServiceUrl, V2_DISCOVERY_URI,): |
| 203 | + requested_url = uritemplate.expand(discovery_url, params) |
| 204 | + |
| 205 | + try: |
| 206 | + content = _retrieve_discovery_doc(requested_url, http, cache_discovery, |
| 207 | + cache) |
| 208 | + return build_from_document(content, base=discovery_url, http=http, |
| 209 | + developerKey=developerKey, model=model, requestBuilder=requestBuilder, |
| 210 | + credentials=credentials) |
| 211 | + except HttpError as e: |
| 212 | + if e.resp.status == http_client.NOT_FOUND: |
| 213 | + continue |
| 214 | + else: |
| 215 | + raise e |
210 | 216 |
|
211 | | - return build_from_document(content, base=discoveryServiceUrl, http=http, |
212 | | - developerKey=developerKey, model=model, requestBuilder=requestBuilder, |
213 | | - credentials=credentials) |
| 217 | + raise UnknownApiNameOrVersion( |
| 218 | + "name: %s version: %s" % (serviceName, version)) |
214 | 219 |
|
215 | 220 |
|
216 | 221 | def _retrieve_discovery_doc(url, http, cache_discovery, cache=None): |
|
0 commit comments