|
14 | 14 |
|
15 | 15 | """GCloud Pubsub API wrapper. |
16 | 16 |
|
17 | | -
|
18 | 17 | The main concepts with this API are: |
19 | 18 |
|
20 | 19 | - :class:`gcloud.pubsub.topic.Topic` represents an endpoint to which messages |
|
24 | 23 | subscription (either pull or push) to a topic. |
25 | 24 | """ |
26 | 25 |
|
27 | | -from gcloud._helpers import get_default_project |
28 | | -from gcloud._helpers import set_default_project |
29 | | -from gcloud.pubsub import _implicit_environ |
30 | | -from gcloud.pubsub._implicit_environ import get_default_connection |
31 | 26 | from gcloud.pubsub.connection import SCOPE |
32 | | -from gcloud.pubsub.connection import Connection |
33 | 27 | from gcloud.pubsub.subscription import Subscription |
34 | 28 | from gcloud.pubsub.topic import Topic |
35 | | - |
36 | | - |
37 | | -def set_default_connection(connection=None): |
38 | | - """Set default connection either explicitly or implicitly as fall-back. |
39 | | -
|
40 | | - :type connection: :class:`gcloud.pubsub.connection.Connection` |
41 | | - :param connection: A connection provided to be the default. |
42 | | - """ |
43 | | - _implicit_environ._DEFAULTS.connection = connection or get_connection() |
44 | | - |
45 | | - |
46 | | -def set_defaults(project=None, connection=None): |
47 | | - """Set defaults either explicitly or implicitly as fall-back. |
48 | | -
|
49 | | - Uses the arguments to call the individual default methods. |
50 | | -
|
51 | | - :type project: string |
52 | | - :param project: Optional. The name of the project to connect to. |
53 | | -
|
54 | | - :type connection: :class:`gcloud.pubsub.connection.Connection` |
55 | | - :param connection: Optional. A connection provided to be the default. |
56 | | - """ |
57 | | - set_default_project(project=project) |
58 | | - set_default_connection(connection=connection) |
59 | | - |
60 | | - |
61 | | -def get_connection(): |
62 | | - """Shortcut method to establish a connection to Cloud Storage. |
63 | | -
|
64 | | - Use this if you are going to access several buckets with the same |
65 | | - set of credentials: |
66 | | -
|
67 | | - >>> from gcloud import pubsub |
68 | | - >>> connection = pubsub.get_connection() |
69 | | - >>> bucket1 = pubsub.get_bucket('bucket1', connection=connection) |
70 | | - >>> bucket2 = pubsub.get_bucket('bucket2', connection=connection) |
71 | | -
|
72 | | - :rtype: :class:`gcloud.pubsub.connection.Connection` |
73 | | - :returns: A connection defined with the proper credentials. |
74 | | - """ |
75 | | - return Connection.from_environment() |
0 commit comments