Skip to content

Commit

Permalink
Adding basic connection for Cloud Language API.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Aug 23, 2016
1 parent 0a3b42e commit 8d39893
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
:caption: Natural Language

language-usage
Client <language-client>

.. toctree::
:maxdepth: 0
Expand Down
6 changes: 6 additions & 0 deletions docs/language-client.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Connection
~~~~~~~~~~

.. automodule:: gcloud.language.connection
:members:
:show-inheritance:
15 changes: 15 additions & 0 deletions gcloud/language/__init__.py
Original file line number Diff line number Diff line change
@@ -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."""
33 changes: 33 additions & 0 deletions gcloud/language/connection.py
Original file line number Diff line number Diff line change
@@ -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."""
36 changes: 36 additions & 0 deletions gcloud/language/test_connection.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions scripts/verify_included_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__',
Expand Down

0 comments on commit 8d39893

Please sign in to comment.