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