Rest api with java » 履歴 » バージョン 1
Mitsuyoshi Yoshida, 2011/11/13 12:45
1 | 1 | Mitsuyoshi Yoshida | redmine.org の "Rest_api_with_java":http://www.redmine.org/projects/redmine/wiki/Rest_api_with_java の日本語訳です。 |
---|---|---|---|
2 | |||
3 | h1. Java での REST API の使用法 |
||
4 | |||
5 | Redmine REST API でのアクセスに使える Java のライブラリには "Redmine Java API library":https://code.google.com/p/redmine-java-api があります。これはサードパーティ製のフリー(Apache 2 オープンソースライセンス)なライブラリです。 |
||
6 | |||
7 | 使用例: |
||
8 | |||
9 | <pre><code class="java"> |
||
10 | import java.io.IOException; |
||
11 | import java.net.URISyntaxException; |
||
12 | import java.util.List; |
||
13 | import org.redmine.ta.beans.Issue; |
||
14 | |||
15 | public class Simple { |
||
16 | private static String redmineHost = "https://www.hostedredmine.com"; |
||
17 | private static String apiAccessKey = "a3221bfcef5750219bd0a2df69519416dba17fc9"; |
||
18 | private static String projectKey = "taskconnector-test"; |
||
19 | private static Integer queryId = null; // any |
||
20 | |||
21 | public static void main(String[] args) { |
||
22 | RedmineManager mgr = new RedmineManager(redmineHost, apiAccessKey); |
||
23 | try { |
||
24 | tryGetIssues(mgr); |
||
25 | } catch (Exception e) { |
||
26 | e.printStackTrace(); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | private static void tryGetIssues(RedmineManager mgr) throws Exception { |
||
31 | List<Issue> issues = mgr.getIssues(projectKey, queryId); |
||
32 | for (Issue issue : issues) { |
||
33 | System.out.println(issue.toString()); |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 | </code></pre> |
||
38 | |||
39 | |||
40 | チケットの作成 |
||
41 | |||
42 | <pre><code class="java"> |
||
43 | Issue issueToCreate = new Issue(); |
||
44 | issueToCreate.setSubject("This is the summary line 123"); |
||
45 | Issue newIssue = mgr.createIssue(PROJECT_KEY, issueToCreate); |
||
46 | </code></pre> |
||
47 | |||
48 | |||
49 | ID を指定したチケットの取得 |
||
50 | |||
51 | <pre><code class="java"> |
||
52 | Issue issue = mgr.getIssueById(123); |
||
53 | </code></pre> |