private T Execute <T>(JiraObjectEnum objectType, Method method, T obj, Dictionary <string, string> parameters = null, Dictionary <string, string> keys = null) where T : new() { if (!_methods.ContainsKey(objectType)) { throw new NotImplementedException(); } IRestRequest request = GetRequest(_methods[objectType], method, parameters ?? new Dictionary <string, string>(), keys ?? new Dictionary <string, string>()); if (Method.POST == method) { //request.AddBody(obj); string json = JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); request.AddParameter("Application/Json", json, ParameterType.RequestBody); } IRestResponse <T> response = Client.Execute <T>(request); if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { throw new UnauthorizedAccessException(response.Request.Resource); } if (response.ErrorException != null) { throw response.ErrorException; } if (response.ResponseStatus != ResponseStatus.Completed) { throw new Exception(response.ErrorMessage); } return(response.Data); }
public RestRequest GetRequest(JiraObjectEnum objectType, Dictionary <String, String> parameters, Dictionary <String, String> keys) { if (!_methods.ContainsKey(objectType)) { throw new NotImplementedException(); } RestRequest request = new RestRequest(_methods[objectType], Method.GET) { RequestFormat = DataFormat.Json, OnBeforeDeserialization = resp => resp.ContentType = "application/json" }; foreach (KeyValuePair <String, String> key in keys) { request.AddParameter(key.Key, key.Value, ParameterType.UrlSegment); } foreach (KeyValuePair <String, String> parameter in parameters) { request.AddParameter(parameter.Key, parameter.Value); } return(request); }
public RestRequest GetRequest(JiraObjectEnum objectType, Dictionary <String, String> parameters, Dictionary <String, String> keys) { if (!_methods.ContainsKey(objectType)) { throw new NotImplementedException(); } return(GetRequest(_methods[objectType], parameters, keys)); }
public bool DeleteItem(JiraObjectEnum objectType, Dictionary <string, string> parameters = null, Dictionary <string, string> keys = null) { try { Execute(objectType, Method.DELETE, true, parameters, keys); return(true); } catch (Exception ex) { return(false); } }
private T Execute <T>(JiraObjectEnum objectType, Dictionary <String, String> parameters = null, Dictionary <String, String> keys = null) where T : new() { IRestResponse <T> response = Client.Execute <T>(GetRequest(objectType, parameters ?? new Dictionary <String, String>(), keys ?? new Dictionary <String, String>())); if (response.ErrorException != null) { throw response.ErrorException; } if (response.ResponseStatus != ResponseStatus.Completed) { throw new Exception(response.ErrorMessage); } return(response.Data); }
private T Execute <T>(JiraObjectEnum objectType, Dictionary <String, String> parameters = null, Dictionary <String, String> keys = null) where T : new() { IRestRequest request = GetRequest(objectType, parameters ?? new Dictionary <String, String>(), keys ?? new Dictionary <String, String>()); IRestResponse <T> response = Client.Execute <T>(request); if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { throw new UnauthorizedAccessException(response.Request.Resource); } if (response.ErrorException != null) { throw response.ErrorException; } if (response.ResponseStatus != ResponseStatus.Completed) { throw new Exception(response.ErrorMessage); } return(response.Data); }
private List <T> GetList <T>(JiraObjectEnum objectType, Dictionary <String, String> parameters = null, Dictionary <String, String> keys = null) where T : new() { return(Execute <List <T> >(objectType, parameters, keys)); }
public T UpdateItem <T>(JiraObjectEnum objectType, T obj, Dictionary <string, string> parameters = null, Dictionary <string, string> keys = null) where T : new() { return(Execute <T>(objectType, Method.PUT, obj, parameters, keys)); }
public List <T> GetList <T>(JiraObjectEnum objectType, Dictionary <string, string> parameters = null, Dictionary <string, string> keys = null) where T : new() { return(Execute <List <T> >(objectType, Method.GET, null, parameters, keys)); }
public T GetItem <T>(JiraObjectEnum objectType, Dictionary <string, string> parameters = null, Dictionary <string, string> keys = null) where T : new() { return(Execute <T>(objectType, Method.GET, default(T), parameters, keys)); }