|
50 | 50 | import io.gapi.gax.grpc.ServiceApiSettings; |
51 | 51 | import io.gapi.gax.internal.ApiUtils; |
52 | 52 | import io.gapi.gax.protobuf.PathTemplate; |
53 | | -import io.grpc.Channel; |
54 | 53 | import io.grpc.ManagedChannel; |
55 | 54 |
|
56 | 55 | import java.io.IOException; |
@@ -132,14 +131,14 @@ public Iterable<Subscription> extractResources(ListSubscriptionsResponse payload |
132 | 131 | * A PathTemplate representing the fully-qualified path to represent |
133 | 132 | * a project resource. |
134 | 133 | */ |
135 | | - public static final PathTemplate PROJECT_PATH_TEMPLATE = |
| 134 | + private static final PathTemplate PROJECT_PATH_TEMPLATE = |
136 | 135 | PathTemplate.create("/projects/{project}"); |
137 | 136 |
|
138 | 137 | /** |
139 | 138 | * A PathTemplate representing the fully-qualified path to represent |
140 | 139 | * a subscription resource. |
141 | 140 | */ |
142 | | - public static final PathTemplate SUBSCRIPTION_PATH_TEMPLATE = |
| 141 | + private static final PathTemplate SUBSCRIPTION_PATH_TEMPLATE = |
143 | 142 | PathTemplate.create("/projects/{project}/subscriptions/{subscription}"); |
144 | 143 |
|
145 | 144 | // ======== |
@@ -168,7 +167,11 @@ public static SubscriberApi create(ServiceApiSettings settings) throws IOExcepti |
168 | 167 | return new SubscriberApi(settings); |
169 | 168 | } |
170 | 169 |
|
171 | | - private SubscriberApi(ServiceApiSettings settings) throws IOException { |
| 170 | + /** |
| 171 | + * Constructs an instance of SubscriberApi, using the given settings. This is protected so that it |
| 172 | + * easy to make a subclass, but otherwise, the static factory methods should be preferred. |
| 173 | + */ |
| 174 | + protected SubscriberApi(ServiceApiSettings settings) throws IOException { |
172 | 175 | ServiceApiSettings internalSettings = ApiUtils.settingsWithChannels(settings, |
173 | 176 | SERVICE_ADDRESS, DEFAULT_SERVICE_PORT, ALL_SCOPES); |
174 | 177 | this.settings = internalSettings; |
@@ -197,13 +200,28 @@ public static final String createSubscriptionPath(String project, String subscri |
197 | 200 | "project", project,"subscription", subscription); |
198 | 201 | } |
199 | 202 |
|
| 203 | + /** |
| 204 | + * Extracts the project from the given fully-qualified path which |
| 205 | + * represents a project resource. |
| 206 | + */ |
| 207 | + public static final String extractProjectFromProjectPath(String projectPath) { |
| 208 | + return PROJECT_PATH_TEMPLATE.parse(projectPath).get("project"); |
| 209 | + } |
200 | 210 |
|
201 | | - // ======== |
202 | | - // Getters |
203 | | - // ======== |
| 211 | + /** |
| 212 | + * Extracts the project from the given fully-qualified path which |
| 213 | + * represents a subscription resource. |
| 214 | + */ |
| 215 | + public static final String extractProjectFromSubscriptionPath(String subscriptionPath) { |
| 216 | + return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionPath).get("project"); |
| 217 | + } |
204 | 218 |
|
205 | | - public Channel getChannel() { |
206 | | - return channel; |
| 219 | + /** |
| 220 | + * Extracts the subscription from the given fully-qualified path which |
| 221 | + * represents a subscription resource. |
| 222 | + */ |
| 223 | + public static final String extractSubscriptionFromSubscriptionPath(String subscriptionPath) { |
| 224 | + return SUBSCRIPTION_PATH_TEMPLATE.parse(subscriptionPath).get("subscription"); |
207 | 225 | } |
208 | 226 |
|
209 | 227 |
|
|
0 commit comments