Added functionallity for appending querystring params once the request is created
This commit is contained in:
1 parent
f6c3cb9bdb
commit
7e92db3413
2 files changed
+25
-1
No files matched your search
@@ -19,6 +19,7 @@ class Request
|
||||
|
||||
private String url;
|
||||
private Verb verb;
|
||||
private Map<String, String> querystringParams;
|
||||
private Map<String, String> bodyParams;
|
||||
private Map<String, String> headers;
|
||||
private String payload = null;
|
||||
@@ -34,6 +35,7 @@ class Request
|
||||
{
|
||||
this.verb = verb;
|
||||
this.url = url;
|
||||
this.querystringParams = new HashMap<String, String>();
|
||||
this.bodyParams = new HashMap<String, String>();
|
||||
this.headers = new HashMap<String, String>();
|
||||
}
|
||||
@@ -111,6 +113,17 @@ class Request
|
||||
this.bodyParams.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a QueryString parameter
|
||||
*
|
||||
* @param key the parameter name
|
||||
* @param value the parameter value
|
||||
*/
|
||||
public void addQuerystringParam(String key, String value)
|
||||
{
|
||||
this.querystringParams.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add body payload.
|
||||
*
|
||||
@@ -145,8 +158,10 @@ class Request
|
||||
params.put(pair[0], pair[1]);
|
||||
}
|
||||
}
|
||||
params.putAll(querystringParams);
|
||||
return params;
|
||||
} catch (MalformedURLException mue)
|
||||
}
|
||||
catch (MalformedURLException mue)
|
||||
{
|
||||
throw new OAuthException("Malformed URL", mue);
|
||||
}
|
||||
|
||||
@@ -65,4 +65,13 @@ public class RequestTest
|
||||
assertTrue(connection.getHeaders().containsKey("Content-Length"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllowAddingQuerystringParametersAfterCreation()
|
||||
{
|
||||
Request request = new Request(Verb.GET, "http://example.com?one=val");
|
||||
request.addQuerystringParam("two", "other val");
|
||||
request.addQuerystringParam("more", "params");
|
||||
assertEquals(3, request.getQueryStringParams().size());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user