1
0
Fork 0

Maintain convention by overloading the method post. Slight refactor to avoid ambiguous method compile-time error. Voting/Issue Creation/comments/attachments were retested.

master
Kyle Chaplin 2013-08-24 18:47:20 -05:00
parent b7d6164610
commit 3a65c6f61a
2 changed files with 8 additions and 6 deletions

View File

@ -433,7 +433,7 @@ public final class Issue extends Resource {
*/
public void addAttachment(File file) throws JiraException {
try {
restclient.postFile(getRestUri(key) + "/attachments", file);
restclient.post(getRestUri(key) + "/attachments", file);
} catch (Exception ex) {
throw new JiraException("Failed add attachment to issue " + key, ex);
}
@ -717,7 +717,7 @@ public final class Issue extends Resource {
public void vote() throws JiraException {
try {
restclient.post(getRestUri(key) + "/votes", null);
restclient.post(getRestUri(key) + "/votes", new JSONObject());
} catch (Exception ex) {
throw new JiraException("Failed to vote on issue " + key, ex);
}

View File

@ -29,6 +29,7 @@ import java.net.URISyntaxException;
import java.util.Map;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import org.apache.http.HttpEntity;
@ -269,9 +270,10 @@ public class RestClient {
* @throws IOException when an error reading the response occurs
*/
public JSON post(URI uri, String payload) throws RestException, IOException {
String quoted = payload != null ?
String.format("\"%s\"", payload) :
null;
String quoted = null;
if(payload != null && !payload.equals(new JSONObject())){
quoted = String.format("\"%s\"", payload);
}
return request(new HttpPost(uri), quoted);
}
@ -303,7 +305,7 @@ public class RestClient {
* @throws IOException
* @throws RestException
*/
public JSON postFile(String path, File file) throws RestException, IOException, URISyntaxException{
public JSON post(String path, File file) throws RestException, IOException, URISyntaxException{
return request(new HttpPost(buildURI(path)), file);
}