1414
1515"""Create / interact with gcloud pubsub connections."""
1616
17+ import os
18+
1719from gcloud import connection as base_connection
20+ from gcloud .environment_vars import PUBSUB_EMULATOR
1821
1922
2023class Connection (base_connection .JSONConnection ):
@@ -26,6 +29,10 @@ class Connection(base_connection.JSONConnection):
2629
2730 :type http: :class:`httplib2.Http` or class that defines ``request()``.
2831 :param http: (Optional) HTTP object to make requests.
32+
33+ :type api_base_url: string
34+ :param api_base_url: The base of the API call URL. Defaults to the value
35+ :attr:`Connection.API_BASE_URL`.
2936 """
3037
3138 API_BASE_URL = 'https://pubsub.googleapis.com'
@@ -40,3 +47,41 @@ class Connection(base_connection.JSONConnection):
4047 SCOPE = ('https://www.googleapis.com/auth/pubsub' ,
4148 'https://www.googleapis.com/auth/cloud-platform' )
4249 """The scopes required for authenticating as a Cloud Pub/Sub consumer."""
50+
51+ def __init__ (self , credentials = None , http = None , api_base_url = None ):
52+ super (Connection , self ).__init__ (credentials = credentials , http = http )
53+ if api_base_url is None :
54+ api_base_url = os .getenv (PUBSUB_EMULATOR ,
55+ self .__class__ .API_BASE_URL )
56+ self .api_base_url = api_base_url
57+
58+ def build_api_url (self , path , query_params = None ,
59+ api_base_url = None , api_version = None ):
60+ """Construct an API url given a few components, some optional.
61+
62+ Typically, you shouldn't need to use this method.
63+
64+ :type path: string
65+ :param path: The path to the resource.
66+
67+ :type query_params: dict
68+ :param query_params: A dictionary of keys and values to insert into
69+ the query string of the URL.
70+
71+ :type api_base_url: string
72+ :param api_base_url: The base URL for the API endpoint.
73+ Typically you won't have to provide this.
74+
75+ :type api_version: string
76+ :param api_version: The version of the API to call.
77+ Typically you shouldn't provide this and instead
78+ use the default for the library.
79+
80+ :rtype: string
81+ :returns: The URL assembled from the pieces provided.
82+ """
83+ if api_base_url is None :
84+ api_base_url = self .api_base_url
85+ return super (Connection , self .__class__ ).build_api_url (
86+ path , query_params = query_params ,
87+ api_base_url = api_base_url , api_version = api_version )
0 commit comments