Exemple #1
0
 public t GetObject <t>(LpResponse response)
 {
     if (null != response.error)
     {
         throw response.error;
     }
     return(JsonConvert.DeserializeObject <t>(response.response));
 }
Exemple #2
0
        private LpResponse request(String verb, String url, Object data)
        {
            HttpWebRequest request;
            String         uri;
            LpResponse     lp_response;

            uri = "https://app.liquidplanner.com/api" + url;

            request                        = WebRequest.Create(uri) as HttpWebRequest;
            request.Credentials            = CredentialCache.DefaultCredentials;
            request.Method                 = verb;
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            request.Headers.Set("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(this.Username + ":" + this._password)));

            if (null != data)
            {
                request.ContentType = "application/json";
                String jsonPayload = JsonConvert.SerializeObject(data);
                Console.WriteLine(jsonPayload);
                byte[] jsonPayloadByteArray = Encoding.ASCII.GetBytes(jsonPayload.ToCharArray());
                using (Stream stream = request.GetRequestStream()) {
                    stream.Write(jsonPayloadByteArray, 0, jsonPayloadByteArray.Length);
                }
            }


            lp_response = new LpResponse();
            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    using (Stream stream = response.GetResponseStream()) {
                        using (StreamReader reader = new StreamReader(stream)) {
                            lp_response.response = reader.ReadToEnd();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                lp_response.error = e;
            }
            return(lp_response);
        }