Project

General

Profile

Rest api with java » History » Version 12

Chris Maiden, 2012-10-01 18:57
Updated package, see https://github.com/taskadapter/redmine-java-api/issues/41

1 1 Jean-Philippe Lang
h1. Using the REST API with Java
2 2 Alex Last
3 11 Etienne Massip
"Redmine Java API library":https://github.com/taskadapter/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 12 Chris Maiden
import com.taskadapter.redmineapi.RedmineManager;
12
import com.taskadapter.redmineapi.bean.Issue;
13 2 Alex Last
14 1 Jean-Philippe Lang
public class Simple {
15 2 Alex Last
	private static String redmineHost = "https://www.hostedredmine.com";
16
	private static String apiAccessKey = "a3221bfcef5750219bd0a2df69519416dba17fc9";
17 1 Jean-Philippe Lang
	private static String projectKey = "taskconnector-test";
18 9 Alex Last
	private static Integer queryId = null; // any
19 2 Alex Last
20
	public static void main(String[] args) {
21
		RedmineManager mgr = new RedmineManager(redmineHost, apiAccessKey);
22
		try {
23 1 Jean-Philippe Lang
			tryGetIssues(mgr);
24 2 Alex Last
		} catch (Exception e) {
25 1 Jean-Philippe Lang
			e.printStackTrace();
26
		}
27
	}
28 9 Alex Last
29 10 Alex Last
	private static void tryGetIssues(RedmineManager mgr) throws Exception {
30 2 Alex Last
		List<Issue> issues = mgr.getIssues(projectKey, queryId);
31
		for (Issue issue : issues) {
32
			System.out.println(issue.toString());
33
		}
34
	}
35
}
36
</pre>
37
38
Create Issue:
39
40
<pre>
41
	Issue issueToCreate = new Issue();
42
	issueToCreate.setSubject("This is the summary line 123");
43
	Issue newIssue = mgr.createIssue(PROJECT_KEY, issueToCreate);
44
</pre>
45
46
Get issue by ID:
47
48
<pre>
49 5 Alex Last
	Issue issue = mgr.getIssueById(123);
50
</pre>