public IEnumerable<Tweet> GetTweets(Session session) { if (session == null) throw new ArgumentNullException("session"); var response = _restClient.Execute(Request("/tweet/user/" + session.User.Login, new[] {"token"}, new[] {session.Token}, Method.GET)); var tweetTypeLoader = new { tweets = new Tweet[] {} }; switch (response.StatusCode) { case HttpStatusCode.OK: return _jsonSerializer.DeserializeAnonymous(response.Content, tweetTypeLoader).tweets.Reverse(); case HttpStatusCode.Unauthorized: throw new AuthenticationException("You are not authorized"); default: throw new AuthenticationException("Server error. Retry in a few seconds"); } }
public void SendTweet(Session session, string tweetText) { if (session == null) throw new ArgumentNullException("session"); if (tweetText == null) throw new ArgumentNullException("tweetText"); if (tweetText.Length == 0 || tweetText.Length > 140) throw new ArgumentException("Wrong size of the tweet"); var request = Request("/tweet/add", new[] {"token"}, new[] {session.Token}, Method.POST). AddParameter("text/plain", tweetText, ParameterType.RequestBody); var response = _restClient.Execute(request); switch (response.StatusCode) { case HttpStatusCode.OK: break; case HttpStatusCode.Unauthorized: throw new AuthenticationException("You are not authorized"); case HttpStatusCode.BadRequest: throw new AuthenticationException("Bad request from server"); default: throw new AuthenticationException("Server error. Retry in a few seconds"); } }
private void OnLogin() { try { Session = _userManager.Login(_login, _password); Session.User = new User(_login); _messenger.Send((object)Session); } catch (AuthenticationException ex) { ErrorMessage = ex.Message; } catch (ArgumentNullException) { ErrorMessage = "Incorrect login password pair"; } }