/// <summary>
        /// Posts request to specified LG URL
        /// </summary>
        /// <param name="url">URI to post to</param>
        /// <param name="data">Data to send</param>
        /// <param name="accessToken">User accesss token if available</param>
        /// <param name="sessionId">Session ID if available</param>
        /// <returns>Returns result data for request</returns>
        public async static Task <LgedmRoot> Post(string url, LgedmRoot data, string accessToken = null, string sessionId = null)
        {
            HttpClient communicationClient = new HttpClient();

            communicationClient.DefaultRequestHeaders.Add("x-thinq-application-key", "wideq");
            communicationClient.DefaultRequestHeaders.Add("x-thinq-security-key", "nuts_securitykey");
            communicationClient.DefaultRequestHeaders.Add("Accept", "application/json");
            if (accessToken != null)
            {
                communicationClient.DefaultRequestHeaders.Add("x-thinq-token", accessToken);
            }
            if (sessionId != null)
            {
                communicationClient.DefaultRequestHeaders.Add("x-thinq-jsessionId", sessionId);
            }

            string serialized = JsonConvert.SerializeObject(new LGReturnRoot()
            {
                LgedmRoot = data
            }, Newtonsoft.Json.Formatting.None,
                                                            new JsonSerializerSettings
            {
                NullValueHandling    = NullValueHandling.Ignore,
                DefaultValueHandling = DefaultValueHandling.Ignore
            });
            HttpContent content = new StringContent(serialized, Encoding.UTF8, "application/json");

            var response = await communicationClient.PostAsync(url, content);

            var textResponse = await response.Content.ReadAsStringAsync();

            var dataReturn = JsonConvert.DeserializeObject <LGReturnRoot>(textResponse).LgedmRoot;

            if (dataReturn.ReturnCd != "0000")
            {
                switch (dataReturn.ReturnCd)
                {
                case "0102":
                    if (await LGGateway.LGOAuth.RefreshToken())
                    {
                        await Post(url, data, accessToken, sessionId);
                    }
                    else
                    {
                        throw new LGExceptions.NotLoggedInException();
                    }
                    break;

                case "0106":
                    throw new LGExceptions.NotConnectedException();

                default:
                    throw new LGExceptions.ApiException(dataReturn.ReturnMsg);
                }
            }
            communicationClient.DefaultRequestHeaders.Clear();
            return(dataReturn);
        }
 /// <summary>
 /// Parse and login refresh and access tokens based on last known access token
 /// </summary>
 public async static Task Login()
 {
     LgedmRoot.LoginType = "EMP";
     LgedmRoot.Token     = AuthorizationData.AccessToken;
     LgedmRoot.ReplaceWithNewData(await Post(Path.Combine(LgedmRoot.ThinqUri.ToString(), "member/login"), LgedmRoot));
 }
 /// <summary>
 /// Dispose all known data and stop all communication
 /// </summary>
 public static void CloseConnection()
 {
     LgedmRoot = new LgedmRoot();
 }