buildRequestUrl function
String
buildRequestUrl(
- String baseUrl,
- String endpointUrl,
- AuthObject authObject, {
- Map<
String, dynamic> args = const {},
Implementation
String buildRequestUrl(
String baseUrl,
String endpointUrl,
AuthObject authObject, {
Map<String, dynamic> args = const {},
}) {
final concatenated = '$baseUrl/$endpointUrl';
final withoutDoubleSlashes = replaceDoubleSlashes(concatenated);
String withArgs = withoutDoubleSlashes;
// `z` and `y` are expected query params from the RA API.
// Authentication is handled purely by query params.
final queryParamValues = {
'z': authObject.userName,
'y': authObject.webApiKey,
};
for (final entry in args.entries) {
final argKey = entry.key;
final argValue = entry.value;
// "abc.com/some-route/:foo/some-path" & {"foo": 4} --> "abc.com/some-route/4/some-path"
if (withArgs.contains(':$argKey')) {
withArgs = withArgs.replaceFirst(':$argKey', argValue.toString());
} else if (argValue != null) {
queryParamValues[argKey] = argValue.toString();
}
}
final queryString = MapToQueryString(queryParamValues).toString();
return '$withArgs?$queryString';
}