/// <summary> /// Try to list all users /// </summary> public ResponseEx TryGetUser(string keyUser, out UserV2 user) { ResponseEx result = null; user = null; // build the url string messageError; var url = LtbUrl.TryBuild(out messageError, LtbResource.UserByKey, keyUser); // if succeeded if(string.IsNullOrEmpty(messageError)) { // create the request and send it result = RequestFluent.Create(url) .ContentType(LtbConstants.Json) .BasicAuthentication(LtbConstants.KeyBusiness, LtbConstants.KeyApi) .Send(); // if we have a response if((result != null) // with a body && (result.HasBody)) { // get the content from the response body user = result.GetBodyAsJson<UserV2>(); } } // if url building failed else result = ResponseEx.Failure(url, messageError); return result; }
/// <summary> /// Post a user /// </summary> public static ResponseEx TryPostUser(string keyUser, string nameUser, int? lcid, out UserV2 user) { return Current.TryPostUser(keyUser, nameUser, lcid, out user); }
/// <summary> /// Try to list all users /// </summary> public static ResponseEx TryGetUser(string keyUser, out UserV2 user) { return Current.TryGetUser(keyUser, out user); }
/// <summary> /// Post a user /// </summary> public static UserV2 PostUser(string keyUser, string nameUser, int? lcid = null) { UserV2 result = null; // build the url var url = LtbUrl.Build(LtbResource.UserByKey, keyUser); // build the user to send var userToSend = new UserV2 { KeyUser = keyUser, NameUser = nameUser, Lcid = (lcid ?? LtbConstants.LcidDefault) }; // create the request and send it var response = RequestFluent.Create(url) .Method(HttpVerbs.Post) .SendJson(userToSend); // if succeeded if(response.HasBody) // return that content result = response.GetBodyAsJson<UserV2>(); // manage failures ManageFailures(response); return result; }
/// <summary> /// Post a user /// </summary> public ResponseEx TryPostUser(string keyUser, string nameUser, int? lcid, out UserV2 user) { ResponseEx result = null; user = null; // build the url string messageError; var url = LtbUrl.TryBuild(out messageError, LtbResource.UserByKey, keyUser); // if succeeded if(string.IsNullOrEmpty(messageError)) { // build the user to send var userToSend = new UserV2 { KeyUser = keyUser, NameUser = nameUser, LcidUser = (lcid ?? LtbConstants.LcidDefault) }; // create the request and send it result = RequestFluent.Create(url) .ContentType(LtbConstants.Json) .BasicAuthentication(LtbConstants.KeyBusiness, LtbConstants.KeyApi) .Method(HttpVerbs.Post) .SendJson(userToSend); // if we have a response if((result != null) // with a body && (result.HasBody)) { // get the content from the response body user = result.GetBodyAsJson<UserV2>(); } } // if url building failed else result = ResponseEx.Failure(url, messageError); return result; }