Created
December 10, 2019 14:01
-
-
Save ayaysir/efad25b1b3cd43c80b3964d24fae2bef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class UrlBuilder { | |
private List<String> keyValuePairs = new ArrayList<>(); | |
private String baseUrl, makeupUrl; | |
public UrlBuilder(String baseUrl) { | |
this.baseUrl = baseUrl; | |
} | |
public UrlBuilder add(String key, String value) { | |
keyValuePairs.add(key + "=" + value); | |
return this; | |
} | |
public String getBaseUrl() { | |
return baseUrl; | |
} | |
public void setBaseUrl(String baseUrl) { | |
this.baseUrl = baseUrl; | |
} | |
@Override | |
public String toString() { | |
// String apiURL; | |
// apiURL = "https://nid.naver.com/oauth2.0/token?grant_type=authorization_code&"; | |
// apiURL += "client_id=" + CLIENT_ID; | |
// apiURL += "&client_secret=" + CLI_SECRET; | |
// apiURL += "&redirect_uri=" + redirectURI; | |
// apiURL += "&code=" + code; | |
// apiURL += "&state=" + state; | |
if(keyValuePairs.size() >= 1) { | |
makeupUrl = baseUrl + "?"; | |
for(String aPair : keyValuePairs) { | |
makeupUrl += aPair + "&"; | |
} | |
if(makeupUrl.charAt(makeupUrl.length() - 1) == '&') { | |
makeupUrl = makeupUrl.substring(0, makeupUrl.length() - 2); | |
} | |
System.out.println(makeupUrl); | |
} else { | |
makeupUrl = baseUrl; | |
} | |
return makeupUrl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment