示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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));
        }
示例#4
0
 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);
     }
 }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
 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));
 }
示例#8
0
 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));
 }
示例#9
0
 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));
 }
示例#10
0
 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));
 }