public WebUntisResponse <TResponse> Send <TResponse>(WebUntisServiceUrl serviceUrl) { if (serviceUrl == null) { throw new ArgumentNullException(nameof(serviceUrl)); } var client = new RestClient(serviceUrl.ToString()); var request = new RestRequest(RestSharp.Method.POST); request.AddHeader("user-agent", "foo"); request.AddHeader("content-type", "application/json"); var jsonSettings = new JsonSerializerSettings() { DateFormatString = "yyyyMMdd", }; var x = JsonConvert.SerializeObject(this, jsonSettings); request.AddParameter("application/json", x, ParameterType.RequestBody); if (!string.IsNullOrEmpty(SessionId)) { request.AddParameter("JSESSIONID", SessionId, ParameterType.Cookie); } IRestResponse response = client.Execute(request); return(JsonConvert.DeserializeObject <WebUntisResponse <TResponse> >(response.Content, jsonSettings)); }
static void Main(string[] args) { var credentials = new WebUntisCredentials() { Password = "******", Username = "******", }; var serviceUrl = new WebUntisServiceUrl() { School = "SCHOOL", Server = "SERVER", }; var webUntis = new WebUntis(serviceUrl); // TODO make it work webUntis.Authenticate(new Requests.AuthenticationParams() { Client = "foo", Password = credentials.Password, User = credentials.Username, }); try { webUntis.Authenticate(new Requests.AuthenticationParams() { Client = "foo", Password = credentials.Password, User = credentials.Username, }); webUntis.GetTimeTable(new Requests.GetTimetableParams() { Id = 140, Type = Types.PersonType.Teacher, EndDate = new DateTime(2018, 1, 1), StartDate = new DateTime(2018, 12, 31), }); } finally { webUntis.Logout(new Requests.LogoutParams()); } }
public WebUntis(WebUntisServiceUrl serviceUrl, WebUntisRequestFactory factory) { this.serviceUrl = serviceUrl; this.factory = factory; }