Project

General

Profile

Rest api with java » History » Version 3

Alex Last, 2010-12-28 05:42
added 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 3 Alex Last
"Javadoc":http://www.taskadapter.com/javadoc/index.html
7
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
import org.alskor.redmine.RedmineManager;
17
import org.alskor.redmine.beans.Issue;
18
19
public class Simple {
20
	private static String redmineHost = "https://www.hostedredmine.com";
21
	private static String apiAccessKey = "a3221bfcef5750219bd0a2df69519416dba17fc9";
22
	private static String projectKey = "taskconnector-test";
23
	private static String queryId = null; // any
24
25
	public static void main(String[] args) {
26
		RedmineManager mgr = new RedmineManager(redmineHost, apiAccessKey);
27
		try {
28
			tryGetIssues(mgr);
29
		} catch (Exception e) {
30
			e.printStackTrace();
31
		}
32
	}
33
34
	private static void tryGetIssues(RedmineManager mgr) throws IOException, AuthenticationException {
35
		List<Issue> issues = mgr.getIssues(projectKey, queryId);
36
		for (Issue issue : issues) {
37
			System.out.println(issue.toString());
38
		}
39
	}
40
}
41
</pre>
42
43
Create Issue:
44
45
<pre>
46
	Issue issueToCreate = new Issue();
47
	issueToCreate.setSubject("This is the summary line 123");
48
	Issue newIssue = mgr.createIssue(PROJECT_KEY, issueToCreate);
49
</pre>
50
51
Get issue by ID:
52
53
<pre>
54
	Issue issue = mgr.getIssueById(123);
55
</pre>