Created
November 19, 2016 06:52
-
-
Save railsstudent/024bc245ff3b6b55850a9f8c27f9c405 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class UriBuilder | |
constructor: (@url) -> | |
@params = {} | |
idx = @url.indexOf('?') | |
if idx >= 0 | |
lstParams = @url.substring(idx + 1) | |
@url = @url.substring(0, idx) | |
paramPairs = lstParams.split('&') | |
for paramPair in paramPairs | |
param = paramPair.split('=') | |
@params[param[0]] = param[1] | |
build: () -> | |
strParams = '' | |
for k, v of @params | |
strParams += '&' if strParams isnt '' | |
strParams += k + '=' + encodeURIComponent(v) | |
@url + ('?' + strParams if strParams isnt '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment