Skip to content

Commit 2cf3a90

Browse files
committed
Add Vision API connection.
Add RST and ignore vision.__init__. Add API URL example. Add vision to TOCs. Add trailing comma. Add vision/connection to toc.json.
1 parent fee2e67 commit 2cf3a90

File tree

8 files changed

+129
-1
lines changed

8 files changed

+129
-1
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
:caption: Vision
148148

149149
vision-usage
150+
vision-client
150151

151152
.. toctree::
152153
:maxdepth: 0

docs/json/json/master/toc.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,15 @@
465465
"title": "Util"
466466
}
467467
]
468-
}
468+
}, {
469+
"title": "Vision",
470+
"type": "gcloud/vision",
471+
"nav": [
472+
{
473+
"type": "gcloud/vision/connection/connection",
474+
"title": "Connection"
475+
}
476+
]
477+
}
469478
]
470479
}

docs/vision-client.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Vision Client
2+
================
3+
4+
Connection
5+
~~~~~~~~~~
6+
7+
.. automodule:: gcloud.vision.connection
8+
:members:
9+
:undoc-members:
10+
:show-inheritance:

gcloud/vision/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Google Cloud Vision API package."""

gcloud/vision/connection.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
"""Create / interact with gcloud Vision connections."""
17+
18+
19+
from gcloud import connection as base_connection
20+
21+
22+
class Connection(base_connection.JSONConnection):
23+
"""A connection to Google Cloud Vision via the JSON REST API.
24+
25+
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
26+
:param credentials: (Optional) The OAuth2 Credentials to use for this
27+
connection.
28+
29+
:type http: :class:`httplib2.Http` or class that defines ``request()``.
30+
:param http: (Optional) HTTP object to make requests.
31+
32+
:type api_base_url: string
33+
:param api_base_url: The base of the API call URL. Defaults to the value
34+
:attr:`Connection.API_BASE_URL`.
35+
"""
36+
37+
API_BASE_URL = 'https://vision.googleapis.com'
38+
"""The base of the API call URL."""
39+
40+
API_VERSION = 'v1'
41+
"""The version of the API, used in building the API call's URL."""
42+
43+
API_URL_TEMPLATE = '{api_base_url}/{api_version}{path}'
44+
"""A template for the URL of a particular API call."""
45+
46+
SCOPE = ('https://www.googleapis.com/auth/cloud-platform',)
47+
"""The scopes required for authenticating as a Cloud Vision consumer."""

gcloud/vision/test_connection.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
18+
class TestConnection(unittest.TestCase):
19+
20+
def _getTargetClass(self):
21+
from gcloud.vision.connection import Connection
22+
return Connection
23+
24+
def _makeOne(self, *args, **kw):
25+
return self._getTargetClass()(*args, **kw)
26+
27+
def test_default_url(self):
28+
creds = _Credentials()
29+
conn = self._makeOne(creds)
30+
klass = self._getTargetClass()
31+
self.assertEqual(conn.credentials._scopes, klass.SCOPE)
32+
33+
34+
class _Credentials(object):
35+
36+
_scopes = None
37+
38+
@staticmethod
39+
def create_scoped_required():
40+
return True
41+
42+
def create_scoped(self, scope):
43+
self._scopes = scope
44+
return self

scripts/generate_json_docs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ def main():
631631
'storage': [],
632632
'streaming': [],
633633
'translate': [],
634+
'vision': [],
634635
}
635636
}
636637

scripts/verify_included_modules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
'gcloud.streaming.transfer',
5454
'gcloud.streaming.util',
5555
'gcloud.translate.__init__',
56+
'gcloud.vision.__init__',
5657
])
5758

5859

0 commit comments

Comments
 (0)