OLD | NEW |
1 # Copyright 2014 Google Inc. All Rights Reserved. | 1 # Copyright 2014 Google Inc. All Rights Reserved. |
2 # | 2 # |
3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
6 # | 6 # |
7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
8 # | 8 # |
9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 # See the License for the specific language governing permissions and | 12 # See the License for the specific language governing permissions and |
13 # limitations under the License. | 13 # limitations under the License. |
14 | 14 |
15 """Utilities for making samples. | 15 """Utilities for making samples. |
16 | 16 |
17 Consolidates a lot of code commonly repeated in sample applications. | 17 Consolidates a lot of code commonly repeated in sample applications. |
18 """ | 18 """ |
19 | 19 |
20 __author__ = 'jcgregorio@google.com (Joe Gregorio)' | 20 __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
21 __all__ = ['init'] | 21 __all__ = ['init'] |
22 | 22 |
23 | 23 |
24 import argparse | 24 import argparse |
25 import httplib2 | |
26 import os | 25 import os |
27 | 26 |
28 from googleapiclient import discovery | 27 from googleapiclient import discovery |
29 from ...oauth2client import client | 28 from third_party import httplib2 |
30 from ...oauth2client import file | 29 from third_party.oauth2client import client |
31 from ...oauth2client import tools | 30 from third_party.oauth2client import file |
| 31 from third_party.oauth2client import tools |
32 | 32 |
33 | 33 |
34 def init(argv, name, version, doc, filename, scope=None, parents=[], discovery_f
ilename=None): | 34 def init(argv, name, version, doc, filename, scope=None, parents=[], discovery_f
ilename=None): |
35 """A common initialization routine for samples. | 35 """A common initialization routine for samples. |
36 | 36 |
37 Many of the sample applications do the same initialization, which has now | 37 Many of the sample applications do the same initialization, which has now |
38 been consolidated into this function. This function uses common idioms found | 38 been consolidated into this function. This function uses common idioms found |
39 in almost all the samples, i.e. for an API with name 'apiname', the | 39 in almost all the samples, i.e. for an API with name 'apiname', the |
40 credentials are stored in a file named apiname.dat, and the | 40 credentials are stored in a file named apiname.dat, and the |
41 client_secrets.json file is stored in the same directory as the application | 41 client_secrets.json file is stored in the same directory as the application |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 # Construct a service object via the discovery service. | 93 # Construct a service object via the discovery service. |
94 service = discovery.build(name, version, http=http) | 94 service = discovery.build(name, version, http=http) |
95 else: | 95 else: |
96 # Construct a service object using a local discovery document file. | 96 # Construct a service object using a local discovery document file. |
97 with open(discovery_filename) as discovery_file: | 97 with open(discovery_filename) as discovery_file: |
98 service = discovery.build_from_document( | 98 service = discovery.build_from_document( |
99 discovery_file.read(), | 99 discovery_file.read(), |
100 base='https://www.googleapis.com/', | 100 base='https://www.googleapis.com/', |
101 http=http) | 101 http=http) |
102 return (service, flags) | 102 return (service, flags) |
OLD | NEW |