OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Provides access to an authenticated HTTP client which can be used to access | 5 /// Provides access to an authenticated HTTP client which can be used to access |
6 /// Google APIs. | 6 /// Google APIs. |
7 library gcloud.http; | 7 library gcloud.http; |
8 | 8 |
9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
10 | 10 |
11 import 'service_scope.dart' as ss; | 11 import 'service_scope.dart' as ss; |
12 | 12 |
13 const Symbol _authenticatedClientKey = #_gcloud.http; | 13 const Symbol _authenticatedClientKey = #_gcloud.http; |
14 | 14 |
15 /// Access the [http.Client] object available in the current service scope. | 15 /// Access the [http.Client] object available in the current service scope. |
16 /// | 16 /// |
17 /// The returned object will be the one which was previously registered with | 17 /// The returned object will be the one which was previously registered with |
18 /// [registerAuthClientService] within the current (or a parent) service | 18 /// [registerAuthClientService] within the current (or a parent) service |
19 /// scope. | 19 /// scope. |
20 /// | 20 /// |
21 /// Accessing this getter outside of a service scope will result in an error. | 21 /// Accessing this getter outside of a service scope will result in an error. |
| 22 /// See the `package:gcloud/service_scope.dart` library for more information. |
22 http.Client get authClientService => ss.lookup(_authenticatedClientKey); | 23 http.Client get authClientService => ss.lookup(_authenticatedClientKey); |
23 | 24 |
24 /// Registers the [http.Client] object within the current service scope. | 25 /// Registers the [http.Client] object within the current service scope. |
25 /// | 26 /// |
26 /// The provided `client` object will be avilable via the top-level | 27 /// The provided `client` object will be avilable via the top-level |
27 /// `authenticatedHttp` getter. | 28 /// `authenticatedHttp` getter. |
28 /// | 29 /// |
29 /// Calling this function outside of a service scope will result in an error. | 30 /// Calling this function outside of a service scope will result in an error. |
30 /// Calling this function more than once inside the same service scope is not | 31 /// Calling this function more than once inside the same service scope is not |
31 /// allowed. | 32 /// allowed. |
32 void registerAuthClientService(http.Client client, {bool close: true}) { | 33 void registerAuthClientService(http.Client client, {bool close: true}) { |
33 ss.register(_authenticatedClientKey, client); | 34 ss.register(_authenticatedClientKey, client); |
34 if (close) { | 35 if (close) { |
35 ss.registerScopeExitCallback(() => client.close()); | 36 ss.registerScopeExitCallback(() => client.close()); |
36 } | 37 } |
37 } | 38 } |
OLD | NEW |