com.gocardless.http.UrlFormatter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gocardless-pro Show documentation
Show all versions of gocardless-pro Show documentation
Client library for accessing the GoCardless Pro API
package com.gocardless.http;
import static com.google.common.net.UrlEscapers.urlPathSegmentEscaper;
import java.util.Map;
import okhttp3.HttpUrl;
final class UrlFormatter {
private final HttpUrl baseUrl;
UrlFormatter(String baseUrl) {
this.baseUrl = HttpUrl.parse(baseUrl);
}
HttpUrl formatUrl(String template, Map pathParams,
Map queryParams) {
String path = template;
for (Map.Entry entry : pathParams.entrySet()) {
path = path.replace(":" + entry.getKey(),
urlPathSegmentEscaper().escape(entry.getValue()));
}
HttpUrl.Builder builder = baseUrl.resolve(path).newBuilder();
for (Map.Entry param : queryParams.entrySet()) {
builder.addQueryParameter(param.getKey(), param.getValue().toString());
}
return builder.build();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy