using System; using System.Collections.Generic; using Kreta.Client.KozpontiKreta.Model; using Kreta.Core.KozpontiModels.MdszModels; using Newtonsoft.Json; using RestSharp; namespace Kreta.Client.KozpontiKreta { public class KozpontiClient { private readonly string baseUrl; private readonly string apiKey; public KozpontiClient(string baseUrl, string apiKey) { this.baseUrl = baseUrl; this.apiKey = apiKey; } private IRestResponse Http(Method method, string relativeUri, Dictionary parameters = null, Object body = null) { var restRequest = new RestRequest(relativeUri, method); restRequest.AddHeader("ApiKey", apiKey); if (parameters != null && parameters.Count > 0) { foreach (var parameter in parameters) { restRequest.AddParameter(parameter.Key, parameter.Value); } } if (method == Method.POST && body != null) { restRequest.AddJsonBody(body); } var result = new RestClient(string.Format(baseUrl)).Execute(restRequest); return result; } private TResponse Http(Method method, string relativeUri, Dictionary parameters = null, Object body = null) { var result = Http(method, relativeUri, parameters, body); var response = JsonConvert.DeserializeObject(result.Content); return response; } private TResponse GetAsync(string relativeUri, Dictionary parameters = null) { return Http(Method.GET, relativeUri, parameters); } private TResponse PostAsync(string relativeUri, Dictionary parameters = null, Object body = null) { return Http(Method.POST, relativeUri, parameters, body); } private void Post(string relativeUri, Dictionary parameters = null, Object body = null) { Http(Method.POST, relativeUri, parameters, body); } public List GetDiakOlimpiaList(MdszRequestModel model) { var response = PostAsync>("/api/Mdsz/external/get", null, model); return response; } public KozpontiNebuloResponseModel NebuloJelenlet(KozpontiNebuloRequestModel model) { var response = PostAsync("/api/nebulo/external/megjelent", null, model); return response; } public KozpontiNebuloEngedelyezettResponseModel GetBeiratkozasLetszamList(KozpontiNebuloEngedelyezettRequestModel model) { var response = PostAsync("/api/Approves/external/engedelyezett", null, model); return response; } } }