Rest api with java » History » Version 10
Alex Last, 2011-02-10 22:18
updated link to the project location. the project is now hosted at "Google project hosting". updated the sample code.
1 | 1 | Jean-Philippe Lang | h1. Using the REST API with Java |
---|---|---|---|
2 | 2 | Alex Last | |
3 | 10 | Alex Last | "Redmine Java API library":https://code.google.com/p/redmine-java-api is a FREE third-party Java library that can be used to access the Redmine API. It is released under Apache 2 open-source license. |
4 | 2 | Alex Last | |
5 | Sample usage: |
||
6 | 6 | Jean-Philippe Lang | |
7 | 2 | Alex Last | <pre> |
8 | 1 | Jean-Philippe Lang | import java.io.IOException; |
9 | 9 | Alex Last | import java.net.URISyntaxException; |
10 | 1 | Jean-Philippe Lang | import java.util.List; |
11 | 10 | Alex Last | import org.redmine.ta.beans.Issue; |
12 | 2 | Alex Last | |
13 | 1 | Jean-Philippe Lang | public class Simple { |
14 | 2 | Alex Last | private static String redmineHost = "https://www.hostedredmine.com"; |
15 | private static String apiAccessKey = "a3221bfcef5750219bd0a2df69519416dba17fc9"; |
||
16 | 1 | Jean-Philippe Lang | private static String projectKey = "taskconnector-test"; |
17 | 9 | Alex Last | private static Integer queryId = null; // any |
18 | 2 | Alex Last | |
19 | public static void main(String[] args) { |
||
20 | RedmineManager mgr = new RedmineManager(redmineHost, apiAccessKey); |
||
21 | try { |
||
22 | 1 | Jean-Philippe Lang | tryGetIssues(mgr); |
23 | 2 | Alex Last | } catch (Exception e) { |
24 | 1 | Jean-Philippe Lang | e.printStackTrace(); |
25 | } |
||
26 | } |
||
27 | 9 | Alex Last | |
28 | 10 | Alex Last | private static void tryGetIssues(RedmineManager mgr) throws Exception { |
29 | 2 | Alex Last | List<Issue> issues = mgr.getIssues(projectKey, queryId); |
30 | for (Issue issue : issues) { |
||
31 | System.out.println(issue.toString()); |
||
32 | } |
||
33 | } |
||
34 | } |
||
35 | </pre> |
||
36 | |||
37 | Create Issue: |
||
38 | |||
39 | <pre> |
||
40 | Issue issueToCreate = new Issue(); |
||
41 | issueToCreate.setSubject("This is the summary line 123"); |
||
42 | Issue newIssue = mgr.createIssue(PROJECT_KEY, issueToCreate); |
||
43 | </pre> |
||
44 | |||
45 | Get issue by ID: |
||
46 | |||
47 | <pre> |
||
48 | 5 | Alex Last | Issue issue = mgr.getIssueById(123); |
49 | </pre> |