net.rcarz.jiraclient.JiraClient Maven / Gradle / Ivy
/**
* jira-client - a simple JIRA REST client
* Copyright (c) 2013 Bob Carroll ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.rcarz.jiraclient;
import java.net.URI;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* A simple JIRA REST client.
*/
public class JiraClient {
private RestClient restclient = null;
private String username = null;
/**
* Creates a JIRA client.
*
* @param uri Base URI of the JIRA server
*/
public JiraClient(String uri) {
this(uri, null);
}
/**
* Creates an authenticated JIRA client.
*
* @param uri Base URI of the JIRA server
* @param creds Credentials to authenticate with
*/
public JiraClient(String uri, ICredentials creds) {
DefaultHttpClient httpclient = new DefaultHttpClient();
restclient = new RestClient(httpclient, creds, URI.create(uri));
if (creds != null)
username = creds.getLogonName();
}
/**
* Creates a new issue in the given project.
*
* @param project Key of the project to create in
* @param issueType Name of the issue type to create
*
* @return a fluent create instance
*
* @throws JiraException when something goes wrong
*/
public Issue.FluentCreate createIssue(String project, String issueType)
throws JiraException {
return Issue.create(restclient, project, issueType);
}
/**
* Retreives the issue with the given key.
*
* @param key Issue key (PROJECT-123)
*
* @return an issue instance
*
* @throws JiraException when something goes wrong
*/
public Issue getIssue(String key) throws JiraException {
return Issue.get(restclient, key);
}
/**
* Search for issues with the given query.
*
* @param jql JQL statement
*
* @return a search result structure with results
*
* @throws JiraException when the search fails
*/
public Issue.SearchResult searchIssues(String jql)
throws JiraException {
return Issue.search(restclient, jql);
}
public RestClient getRestClient() {
return restclient;
}
public String getSelf() {
return username;
}
}