Skip to content

Commit a984d80

Browse files
committed
Use serviceName and version from build()
1 parent f2772a6 commit a984d80

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

googleapiclient/discovery.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ def build(
275275
requested_url,
276276
discovery_http,
277277
cache_discovery,
278+
serviceName,
279+
version,
278280
cache,
279281
developerKey,
280282
num_retries=num_retries,
@@ -338,6 +340,8 @@ def _retrieve_discovery_doc(
338340
url,
339341
http,
340342
cache_discovery,
343+
serviceName,
344+
version,
341345
cache=None,
342346
developerKey=None,
343347
num_retries=1,
@@ -350,6 +354,8 @@ def _retrieve_discovery_doc(
350354
http: httplib2.Http, An instance of httplib2.Http or something that acts
351355
like it through which HTTP requests will be made.
352356
cache_discovery: Boolean, whether or not to cache the discovery doc.
357+
serviceName: string, name of the service.
358+
version: string, the version of the service.
353359
cache: googleapiclient.discovery_cache.base.Cache, an optional cache
354360
object for the discovery documents.
355361
developerKey: string, Key for controlling API usage, generated
@@ -378,7 +384,7 @@ def _retrieve_discovery_doc(
378384
# At this point, the discovery document was not found in the cache so
379385
# we can attempt to retreive the static discovery document from the library.
380386
if static_discovery:
381-
content = discovery_cache.get_static_doc(url)
387+
content = discovery_cache.get_static_doc(serviceName, version)
382388

383389
# If the content is None, retrieve the discovery doc from the internet
384390
# because it is not in the cache or the static doc directory.

googleapiclient/discovery_cache/__init__.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,35 +50,28 @@ def autodetect():
5050
exc_info=False)
5151
return None
5252

53-
def get_static_doc(uri):
53+
def get_static_doc(serviceName, version):
5454
"""Retrieves the discovery document from the directory defined in
5555
DISCOVERY_DOC_STATIC_DIR corresponding to the uri provided.
5656
5757
Args:
58-
uri: string, The URI of the discovery document in the format
59-
https://{domain}/discovery/{discoveryVer}/apis/{api}/{apiVersion}/rest
58+
serviceName: string, name of the service.
59+
version: string, the version of the service.
6060
6161
Returns:
6262
A string containing the contents of the JSON discovery document,
6363
otherwise None if the JSON discovery document was not found.
6464
"""
6565

66-
doc_name = None
6766
content = None
67+
doc_name = "{}.{}.json".format(serviceName, version)
6868

69-
# Extract the {apiVersion} and {api} from the uri which are the 2nd and 3rd
70-
# last parts of the uri respectively.
71-
# https://www.googleapis.com/discovery/v1/apis/{api}/{apiVersion}/rest
72-
uri_parts = uri.split('/')
73-
if len(uri_parts) > 3:
74-
doc_name = "{}.{}.json".format(uri_parts[-3], uri_parts[-2])
75-
76-
try:
77-
with open(os.path.join(DISCOVERY_DOC_DIR, doc_name), 'r') as f:
78-
content = f.read()
79-
except FileNotFoundError:
80-
# File does not exist. Nothing to do here.
81-
pass
69+
try:
70+
with open(os.path.join(DISCOVERY_DOC_DIR, doc_name), 'r') as f:
71+
content = f.read()
72+
except FileNotFoundError:
73+
# File does not exist. Nothing to do here.
74+
pass
8275

8376
return content
8477

0 commit comments

Comments
 (0)