Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 additions & 0 deletions docs/language-client.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Natural Language Client
=======================

.. automodule:: gcloud.language.client
:members:
:show-inheritance:

Connection
~~~~~~~~~~

.. automodule:: gcloud.language.connection
:members:
:show-inheritance:
17 changes: 17 additions & 0 deletions gcloud/language/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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."""

from gcloud.language.client import Client
42 changes: 42 additions & 0 deletions gcloud/language/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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 client for Google Cloud Natural Language API."""


from gcloud.client import JSONClient
from gcloud.language.connection import Connection


class Client(JSONClient):
"""Client to bundle configuration needed for API requests.

:type project: str
:param project: the project which the client acts on behalf of. If not
passed, falls back to the default inferred from the
environment.

:type credentials: :class:`~oauth2client.client.OAuth2Credentials`
:param credentials: (Optional) The OAuth2 Credentials to use for the
connection owned by this client. If not passed (and
if no ``http`` object is passed), falls back to the
default inferred from the environment.

:type http: :class:`httplib2.Http` or class that defines ``request()``.
:param http: An optional HTTP object to make requests. If not passed, an
``http`` object is created that is bound to the
``credentials`` for the current object.
"""

_connection_class = Connection
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."""
48 changes: 48 additions & 0 deletions gcloud/language/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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 TestClient(unittest.TestCase):

def _getTargetClass(self):
from gcloud.language.client import Client
return Client

def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)

def test_ctor(self):
from gcloud.language.connection import Connection
project = 'PROJECT'
creds = _Credentials()
http = object()
client = self._makeOne(project=project, credentials=creds, http=http)
self.assertTrue(isinstance(client.connection, Connection))
self.assertTrue(client.connection.credentials is creds)
self.assertTrue(client.connection.http is http)


class _Credentials(object):

_scopes = None

@staticmethod
def create_scoped_required():
return True

def create_scoped(self, scope):
self._scopes = scope
return self
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)
3 changes: 2 additions & 1 deletion scripts/generate_json_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,14 @@ def main():
'error_reporting': [],
'exceptions': [],
'iterator': [],
'language': [],
'logging': [],
'monitoring': [],
'pubsub': [],
'resource_manager': [],
'storage': [],
'streaming': [],
'translate': []
'translate': [],
}
}

Expand Down
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