| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7547de6 commit 63caac0
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,7 @@ | |||
| 31 | 31 | from oauth2client import tools | |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | - def init(argv, name, version, doc, filename, scope=None, parents=[]): | ||
| 34 | + def init(argv, name, version, doc, filename, scope=None, parents=[], discovery_filename=None): | ||
| 35 | 35 | """A common initialization routine for samples. | |
| 36 | 36 | ||
| 37 | 37 | Many of the sample applications do the same initialization, which has now | |
@@ -49,6 +49,7 @@ def init(argv, name, version, doc, filename, scope=None, parents=[]): | |||
| 49 | 49 | file: string, filename of the application. Usually set to __file__. | |
| 50 | 50 | parents: list of argparse.ArgumentParser, additional command-line flags. | |
| 51 | 51 | scope: string, The OAuth scope used. | |
| 52 | + discovery_filename: string, name of local discovery file (JSON). Use when discovery doc not available via URL. | ||
| 52 | 53 | ||
| 53 | 54 | Returns: | |
| 54 | 55 | A tuple of (service, flags), where service is the service object and flags | |
@@ -88,6 +89,14 @@ def init(argv, name, version, doc, filename, scope=None, parents=[]): | |||
| 88 | 89 | credentials = tools.run_flow(flow, storage, flags) | |
| 89 | 90 | http = credentials.authorize(http = httplib2.Http()) | |
| 90 | 91 | ||
| 91 | - # Construct a service object via the discovery service. | ||
| 92 | - service = discovery.build(name, version, http=http) | ||
| 92 | + if discovery_filename is None: | ||
| 93 | + # Construct a service object via the discovery service. | ||
| 94 | + service = discovery.build(name, version, http=http) | ||
| 95 | + else: | ||
| 96 | + # Construct a service object using a local discovery document file. | ||
| 97 | + with open(discovery_filename) as discovery_file: | ||
| 98 | + service = discovery.build_from_document( | ||
| 99 | + discovery_file.read(), | ||
| 100 | + base='https://www.googleapis.com/', | ||
| 101 | + http=http) | ||
| 93 | 102 | return (service, flags) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments