public async Task <Boolean> Login(User user) { if (user.Username == null || user.Password == null) { return(false); } IHttpSetter httpSetter = Setter(SFResources.Connect); httpSetter.SetBody(user?.ToJson()); httpSetter.SetMethod(HttpMethod.Put); HttpRequestResponse hrr = await RunRequestFromSetter(httpSetter); if (hrr.Body == "true") { String cookieName = "PHPSESSID="; String s = hrr.Headers.Get("Set-Cookie"); if (s != null) { String sessionId = s.Substring(s.IndexOf(cookieName)); sessionId = sessionId.Substring(0, sessionId.IndexOf(";") + 1); Headers.Add("Cookie", sessionId); } return(true); } else { return(false); } }
public async Task <HttpRequestResponse> Delete(Resource resource, IJsonable body, params String[] urlSegments) { IHttpSetter hs = Setter(resource, urlSegments); hs.SetMethod(HttpMethod.Delete) .SetBody(FormatJson(body?.ToJson())); return(await RunRequestFromSetter(hs)); }
public async Task <T> Get <T>(Resource resource, params String[] urlSegments) { IHttpSetter hs = Setter(resource, urlSegments); hs.SetMethod(HttpMethod.Get); HttpRequestResponse rr = await RunRequestFromSetter(hs); T result; try { if (rr.Body == "") { rr.Body = "[]"; } result = JsonConvert.DeserializeObject <T>(rr.Body); } catch (Exception e) { result = default(T); } return(result); }