Line data Source code
1 : part of 'stream_http_client.dart'; 2 : 3 : /// Client options to modify [StreamHttpClient] 4 : class StreamHttpClientOptions { 5 : /// Instantiates a new [StreamHttpClientOptions] 6 23 : const StreamHttpClientOptions({ 7 : this.location, 8 : this.version = 'v1.0', 9 : this.protocol = 'https', 10 : this.group = 'unspecified', 11 : this.urlOverride = const <String, String>{}, 12 : this.connectTimeout = const Duration(seconds: 10), 13 : this.receiveTimeout = const Duration(seconds: 10), 14 : }); 15 : 16 : /// data center to use with client 17 : final Location? location; 18 : 19 : /// protocol to use with the api calls 20 : final String protocol; 21 : 22 : /// track a source name for the api calls 23 : final String group; 24 : 25 : /// connect timeout, default to 10s 26 : final Duration connectTimeout; 27 : 28 : /// received timeout, default to 10s 29 : final Duration receiveTimeout; 30 : 31 : /// map of url's to possibly override baseUrl 32 : final Map<String, String> urlOverride; 33 : 34 : /// version to use with client 35 : final String version; 36 : 37 : /// Get the current user agent 38 3 : String get _userAgent => 'stream-feed-dart-client-${CurrentPlatform.name}-' 39 2 : '${packageVersion.split('+')[0]}'; 40 : 41 : /// generates a baseUrl using the provided [serviceName] 42 1 : String _getBaseUrl(String serviceName) { 43 2 : if (urlOverride.containsKey(serviceName)) { 44 0 : return urlOverride[serviceName]!; 45 : } 46 : const baseDomainName = 'stream-io-api.com'; 47 1 : var hostname = '$serviceName.$baseDomainName'; 48 1 : if (location != null) hostname = '${location!.name}-$hostname'; 49 : 50 1 : final uri = Uri( 51 1 : scheme: protocol, 52 : host: hostname, 53 2 : pathSegments: [serviceName, version], 54 : ); 55 : 56 1 : return uri.toString(); 57 : } 58 : }