/* (non-Javadoc) * @see net.heroicefforts.viable.android.Repository#postIssue(net.heroicefforts.viable.android.Issue) */ public int postIssue(Issue issue) throws ServiceException { try { HttpPost post = new HttpPost(rootURL + "/issue.json"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(12); nameValuePairs.add(new BasicNameValuePair("issue_type", issue.getType())); nameValuePairs.add(new BasicNameValuePair("priority", issue.getPriority())); nameValuePairs.add(new BasicNameValuePair("app_name", issue.getAppName())); nameValuePairs.add(new BasicNameValuePair("summary", issue.getSummary())); nameValuePairs.add(new BasicNameValuePair("description", issue.getDescription())); for (String version : issue.getAffectedVersions()) nameValuePairs.add(new BasicNameValuePair("app_version_name", version)); if (issue.getStacktrace() != null) nameValuePairs.add(new BasicNameValuePair("stacktrace", issue.getStacktrace())); if (issue instanceof BugContext) { 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, "postIssue response: \n" + obj.toString(4)); // TODO pull dates from response Issue newIssue = new Issue(obj.getJSONObject("issue").toString(4)); issue.copy(newIssue); } else throw new ServiceException(MSG_REMOTE_ERROR + responseCode); if (Config.LOGD) Log.d(TAG, "postIssue 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); } }