Rest api with java » History » Version 2
Alex Last, 2010-12-27 22:59
| 1 | 1 | Jean-Philippe Lang | h1. Using the REST API with Java |
|---|---|---|---|
| 2 | 2 | Alex Last | |
| 3 | "Redmine Java API library":http://www.taskadapter.com/redmine_java_api (commercial software) |
||
| 4 | _The Redmine Java API distributive has Javadoc and more samples._ |
||
| 5 | |||
| 6 | (*page under construction*) |
||
| 7 | |||
| 8 | Sample usage: |
||
| 9 | <pre> |
||
| 10 | import java.io.IOException; |
||
| 11 | import java.util.List; |
||
| 12 | |||
| 13 | import org.alskor.httputils.AuthenticationException; |
||
| 14 | import org.alskor.redmine.RedmineManager; |
||
| 15 | import org.alskor.redmine.beans.Issue; |
||
| 16 | |||
| 17 | public class Simple { |
||
| 18 | private static String redmineHost = "https://www.hostedredmine.com"; |
||
| 19 | private static String apiAccessKey = "a3221bfcef5750219bd0a2df69519416dba17fc9"; |
||
| 20 | private static String projectKey = "taskconnector-test"; |
||
| 21 | private static String queryId = null; // any |
||
| 22 | |||
| 23 | public static void main(String[] args) { |
||
| 24 | RedmineManager mgr = new RedmineManager(redmineHost, apiAccessKey); |
||
| 25 | try { |
||
| 26 | tryGetIssues(mgr); |
||
| 27 | } catch (Exception e) { |
||
| 28 | e.printStackTrace(); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | private static void tryGetIssues(RedmineManager mgr) throws IOException, AuthenticationException { |
||
| 33 | List<Issue> issues = mgr.getIssues(projectKey, queryId); |
||
| 34 | for (Issue issue : issues) { |
||
| 35 | System.out.println(issue.toString()); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | </pre> |
||
| 40 | |||
| 41 | Create Issue: |
||
| 42 | |||
| 43 | <pre> |
||
| 44 | Issue issueToCreate = new Issue(); |
||
| 45 | issueToCreate.setSubject("This is the summary line 123"); |
||
| 46 | Issue newIssue = mgr.createIssue(PROJECT_KEY, issueToCreate); |
||
| 47 | </pre> |
||
| 48 | |||
| 49 | Get issue by ID: |
||
| 50 | |||
| 51 | <pre> |
||
| 52 | Issue issue = mgr.getIssueById(123); |
||
| 53 | </pre> |