Skip to content

Commit c9c5394

Browse files
committed
added language v1 endpoint
1 parent c7ab55f commit c9c5394

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

language/api/analyze.py

Lines 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)