diff --git a/docs/index.rst b/docs/index.rst index ec1ea380c7e8..fc81fbfdee35 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -154,6 +154,7 @@ :caption: Natural Language language-usage + Client .. toctree:: :maxdepth: 0 diff --git a/docs/language-client.rst b/docs/language-client.rst new file mode 100644 index 000000000000..2ef8384af042 --- /dev/null +++ b/docs/language-client.rst @@ -0,0 +1,6 @@ +Connection +~~~~~~~~~~ + +.. automodule:: gcloud.language.connection + :members: + :show-inheritance: diff --git a/gcloud/language/__init__.py b/gcloud/language/__init__.py new file mode 100644 index 000000000000..5d9eeda58f49 --- /dev/null +++ b/gcloud/language/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Client library for Google Cloud Natural Language API.""" diff --git a/gcloud/language/connection.py b/gcloud/language/connection.py new file mode 100644 index 000000000000..ac9ceaba6098 --- /dev/null +++ b/gcloud/language/connection.py @@ -0,0 +1,33 @@ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Basic connection for Google Cloud Natural Language API.""" + +from gcloud import connection as base_connection + + +class Connection(base_connection.JSONConnection): + """A connection to Google Cloud Natural Language JSON REST API.""" + + API_BASE_URL = 'https://language.googleapis.com' + """The base of the API call URL.""" + + API_VERSION = 'v1beta1' + """The version of the API, used in building the API call's URL.""" + + API_URL_TEMPLATE = '{api_base_url}/{api_version}/documents:{path}' + """A template for the URL of a particular API call.""" + + SCOPE = ('https://www.googleapis.com/auth/cloud-platform',) + """The scopes required for authenticating as an API consumer.""" diff --git a/gcloud/language/test_connection.py b/gcloud/language/test_connection.py new file mode 100644 index 000000000000..5ba49c2bd849 --- /dev/null +++ b/gcloud/language/test_connection.py @@ -0,0 +1,36 @@ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + + +class TestConnection(unittest.TestCase): + + def _getTargetClass(self): + from gcloud.language.connection import Connection + return Connection + + def _makeOne(self, *args, **kw): + return self._getTargetClass()(*args, **kw) + + def test_build_api_url(self): + conn = self._makeOne() + uri = '/'.join([ + conn.API_BASE_URL, + conn.API_VERSION, + 'documents', + ]) + method = 'annotateText' + uri += ':' + method + self.assertEqual(conn.build_api_url(method), uri) diff --git a/scripts/verify_included_modules.py b/scripts/verify_included_modules.py index d351592ad9cf..84d6d1df1179 100644 --- a/scripts/verify_included_modules.py +++ b/scripts/verify_included_modules.py @@ -37,6 +37,7 @@ 'gcloud.dns.__init__', 'gcloud.error_reporting.__init__', 'gcloud.iterator', + 'gcloud.language.__init__', 'gcloud.logging.__init__', 'gcloud.logging.handlers.__init__', 'gcloud.logging.handlers.transports.__init__',