Files
2026-11-21 17:07:18 -05:00

152 lines
4.6 KiB
Java

/* */ package kong.unirest.cosmetics;
/* */
/* */ import java.io.UnsupportedEncodingException;
/* */ import java.net.URLEncoder;
/* */ import java.util.Collection;
/* */ import java.util.Map;
/* */ import java.util.Objects;
/* */ import java.util.regex.Matcher;
/* */ import java.util.regex.Pattern;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ class Path
/* */ {
/* */ private String url;
/* */ private String rawPath;
/* */
/* */ Path(String url, String defaultBasePath) {
/* 41 */ if (defaultBasePath != null && url != null && !url.toLowerCase().startsWith("http")) {
/* 42 */ String full = defaultBasePath + defaultBasePath;
/* 43 */ this.url = full;
/* 44 */ this.rawPath = full;
/* */ } else {
/* 46 */ this.url = url;
/* 47 */ this.rawPath = url;
/* */ }
/* */ }
/* */
/* */ public Path(String url) {
/* 52 */ this(url, null);
/* */ }
/* */
/* */ public void param(Map<String, Object> params) {
/* 56 */ params.forEach((key, value) -> param(key, String.valueOf(value)));
/* */ }
/* */
/* */ public void param(String name, String value) {
/* 60 */ Matcher matcher = Pattern.compile("\\{" + name + "\\}").matcher(this.url);
/* 61 */ int count = 0;
/* 62 */ while (matcher.find()) {
/* 63 */ count++;
/* */ }
/* 65 */ if (count == 0) {
/* 66 */ throw new UnirestException("Can't find route parameter name \"" + name + "\"");
/* */ }
/* 68 */ this.url = this.url.replaceAll("\\{" + name + "\\}", encodePath(value));
/* */ }
/* */
/* */ private String encodePath(String value) {
/* 72 */ if (value == null) {
/* 73 */ return "";
/* */ }
/* 75 */ return Util.encode(value).replaceAll("\\+", "%20");
/* */ }
/* */
/* */ public void queryString(String name, Collection<?> value) {
/* 79 */ for (Object cur : value) {
/* 80 */ queryString(name, cur);
/* */ }
/* */ }
/* */
/* */ public void queryString(String name, Object value) {
/* 85 */ StringBuilder queryString = new StringBuilder();
/* 86 */ if (this.url.contains("?")) {
/* 87 */ queryString.append("&");
/* */ } else {
/* 89 */ queryString.append("?");
/* */ }
/* */ try {
/* 92 */ queryString.append(URLEncoder.encode(name, "UTF-8"));
/* 93 */ if (value != null) {
/* 94 */ queryString.append("=").append(URLEncoder.encode(String.valueOf(value), "UTF-8"));
/* */ }
/* 96 */ } catch (UnsupportedEncodingException e) {
/* 97 */ throw new UnirestException(e);
/* */ }
/* 99 */ this.url += this.url;
/* */ }
/* */
/* */ public void queryString(Map<String, Object> parameters) {
/* 103 */ if (parameters != null) {
/* 104 */ for (Map.Entry<String, Object> param : parameters.entrySet()) {
/* 105 */ queryString(param.getKey(), param.getValue());
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */ public String toString() {
/* 112 */ return escape(this.url);
/* */ }
/* */
/* */ private String escape(String string) {
/* 116 */ return string.replaceAll(" ", "%20").replaceAll("\t", "%09");
/* */ }
/* */
/* */ public String rawPath() {
/* 120 */ return this.rawPath;
/* */ }
/* */
/* */ public String baseUrl() {
/* 124 */ if (this.url != null && this.url.contains("?")) {
/* 125 */ return this.url.substring(0, this.url.indexOf("?"));
/* */ }
/* 127 */ return this.url;
/* */ }
/* */
/* */ public String getQueryString() {
/* 131 */ return this.url.substring(this.url.indexOf("?") + 1);
/* */ }
/* */
/* */
/* */ public boolean equals(Object o) {
/* 136 */ if (this == o) return true;
/* 137 */ if (o == null || getClass() != o.getClass()) return false;
/* 138 */ Path path = (Path)o;
/* 139 */ return Objects.equals(this.url, path.url);
/* */ }
/* */
/* */
/* */ public int hashCode() {
/* 144 */ return Objects.hash(new Object[] { this.url });
/* */ }
/* */ }
/* Location: C:\Users\Xiao\Downloads\MinehutCosmetics.jar!\kon\\unirest\cosmetics\Path.class
* Java compiler version: 11 (55.0)
* JD-Core Version: 1.1.3
*/