Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ac51494

Browse filesBrowse files
committed
added language v1 endpoint
1 parent f16a274 commit ac51494
Copy full SHA for ac51494

File tree

Expand file treeCollapse file tree

1 file changed

+25
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-7
lines changed

‎language/api/analyze.py

Copy file name to clipboardExpand all lines: language/api/analyze.py
+25-7Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,33 @@
2424
import httplib2
2525
from oauth2client.client import GoogleCredentials
2626

27-
27+
# TODO REMOVE - when discovery is public
28+
GOOGLE_API_KEY = "GOOGLE_API_KEY"
29+
30+
# TODO REMOVE - when discovery is public
31+
DISCOVERY_URL = ('https://language.googleapis.com/$discovery/rest?'
32+
'version=v1&labels=GOOGLE_INTERNAL&key={}')
33+
34+
# TODO UNCOMMENT - when discovery is public
35+
# def get_service():
36+
# credentials = GoogleCredentials.get_application_default()
37+
# scoped_credentials = credentials.create_scoped(
38+
# ['https://www.googleapis.com/auth/cloud-platform'])
39+
# http = httplib2.Http()
40+
# scoped_credentials.authorize(http)
41+
# return discovery.build('language', 'v1', http=http)
42+
# TODO END
43+
44+
# TODO REMOVE - when discovery is public
2845
def get_service():
46+
"""Get language service using discovery."""
47+
import os
48+
api_key = os.environ[GOOGLE_API_KEY]
2949
credentials = GoogleCredentials.get_application_default()
30-
scoped_credentials = credentials.create_scoped(
31-
['https://www.googleapis.com/auth/cloud-platform'])
32-
http = httplib2.Http()
33-
scoped_credentials.authorize(http)
34-
return discovery.build('language', 'v1beta1', http=http)
35-
50+
service = discovery.build('language', 'v1', http=httplib2.Http(), credentials=credentials,
51+
discoveryServiceUrl=DISCOVERY_URL.format(api_key))
52+
return service
53+
# TODO END
3654

3755
def get_native_encoding_type():
3856
"""Returns the encoding type that matches Python's native strings."""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.