Example #1
0
        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);
            }
        }
Example #2
0
        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));
        }
Example #3
0
        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);
        }