예제 #1
0
 public boolean vote(Issue issue) throws ServiceException {
   try {
     HttpPost post = new HttpPost(rootURL + "/issue/" + issue.getIssueId() + "/vote.json");
     HttpResponse response = execute(post);
     if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) {
       issue.setVoted(true);
       issue.setVotes(issue.getVotes() + 1);
       return true;
     } else return false;
   } catch (IOException e) {
     throw new ServiceException(MSG_CONNECT_ERROR, e);
   }
 }
예제 #2
0
  public int postIssueComment(Issue issue, Comment comment) throws ServiceException {
    try {
      HttpPost post = new HttpPost(rootURL + "/issue/" + issue.getIssueId() + "/comments.json");
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(12);
      nameValuePairs.add(new BasicNameValuePair("app_name", issue.getAppName()));
      nameValuePairs.add(new BasicNameValuePair("body", comment.getBody()));

      if (issue.getStacktrace() != null) {
        nameValuePairs.add(new BasicNameValuePair("phone_model", Build.MODEL));
        nameValuePairs.add(new BasicNameValuePair("phone_device", Build.DEVICE));
        nameValuePairs.add(
            new BasicNameValuePair("phone_version", String.valueOf(Build.VERSION.SDK_INT)));
      }

      if (Config.LOGD) Log.d(TAG, "post params:  " + nameValuePairs.toString());
      post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

      // Execute HTTP Post Request
      HttpResponse response = execute(post);
      int responseCode = response.getStatusLine().getStatusCode();
      if (HttpStatus.SC_OK == responseCode || HttpStatus.SC_CREATED == responseCode) {
        JSONObject obj = readJSON(response);
        if (Config.LOGV) Log.v(TAG, "postIssueComment response:  \n" + obj.toString(4));
        // TODO pull dates from response
        Comment newComment = new Comment(obj);
        comment.copy(newComment);
      } else throw new ServiceException(MSG_REMOTE_ERROR + responseCode);

      if (Config.LOGD) Log.d(TAG, "postIssueComment code " + responseCode);

      return responseCode;
    } catch (UnsupportedEncodingException e) {
      throw new ServiceException("Encoding error occurred parsing JIRA response", e);
    } catch (IOException e) {
      throw new ServiceException(MSG_CONNECT_ERROR, e);
    } catch (JSONException e) {
      throw new ServiceException(MSG_PARSE_ERROR, e);
    }
  }