internal static Session StartNewSession(ClientInfo clientInfo, JsonHttpClient jsonHttp) { var response = jsonHttp.Get(string.Format("v2/auth/{0}/{1}/{2}/{3}", clientInfo.Username, clientInfo.AccountKey.Format, clientInfo.AccountKey.Uuid, clientInfo.Uuid)); var status = response.StringAt("status"); switch (status) { case "ok": var session = Session.Parse(response); if (session.KeyUuid != clientInfo.AccountKey.Uuid) { throw new ClientException(ClientException.FailureReason.IncorrectCredentials, "The account key is incorrect"); } return(session); case "device-not-registered": RegisterDevice(clientInfo, MakeJsonClient(jsonHttp, response.StringAt("sessionID"))); break; case "device-deleted": ReauthorizeDevice(clientInfo, MakeJsonClient(jsonHttp, response.StringAt("sessionID"))); break; default: throw new ClientException( ClientException.FailureReason.InvalidResponse, string.Format( "Failed to start a new session, unsupported response status '{0}'", status)); } return(StartNewSession(clientInfo, jsonHttp)); }
// // HTTP // internal static JObject GetEncryptedJson(string endpoint, AesKey sessionKey, JsonHttpClient jsonHttp) { return(Decrypt(jsonHttp.Get(endpoint), sessionKey)); }