/// <summary> /// Send a message created from the application /// </summary> /// <param name="token">Token used to do the operation</param> /// <param name="receiver">User receiving the message</param> public bool Send(IToken token = null, IUser receiver = null) { token = GetQueryToken(token); if (token == null) { return(false); } IUser messageReceiver = receiver ?? _receiver; if (messageReceiver == null) { throw new ArgumentException("Receiver cannot be null"); } if (messageReceiver.Id == null && messageReceiver.ScreenName == null) { throw new ArgumentException("Receiver is invalid"); } // Sending the message if (messageReceiver.Id != null) { token.ExecutePOSTQuery(String.Format(Resources.Messages_SendToUserId, _text, messageReceiver.Id)); } else { token.ExecutePOSTQuery(String.Format(Resources.Messages_SendToUserScreenName, _text, messageReceiver.ScreenName)); } return(true); }
public bool Destroy(IToken token = null, bool getUserInfo = false) { token = GetQueryToken(token); // We cannot destroy a tweet that has not been published // We cannot destroy a tweet that has already been destroyed if (!_isTweetPublished || _isTweetDestroyed || _id == null || token == null) { return(false); } bool result = true; // If a WebException occurs, the deletion has not been performed WebExceptionHandlingDelegate wex = delegate { result = false; }; string destroyQuery = String.Format(Resources.Tweet_Destroy, _id); token.ExecutePOSTQuery(destroyQuery, null, wex); _isTweetDestroyed = result; return(result); }
protected bool Publish(IToken token, string query) { token = GetQueryToken(token); // If id exists it means that the tweet already exist on twitter // We cannot republish this tweet if (_id != null || _isTweetPublished || _isTweetDestroyed || String.IsNullOrEmpty(_text) || token == null) { return(false); } bool result = true; WebExceptionHandlingDelegate wexHandler = delegate(WebException wex) { int indexOfStatus = wex.Response.Headers.AllKeys.ToList().IndexOf("status"); if (indexOfStatus >= 0) { string statusValue = wex.Response.Headers.Get(indexOfStatus); switch (statusValue) { case "403 Forbidden": // You are trying to post the same Tweet another time! result = false; break; default: throw wex; } } else { throw wex; } }; ObjectResponseDelegate objectDelegate = Populate; token.ExecutePOSTQuery(query, objectDelegate, wexHandler); return(result); }
public void SetFavourite(bool?isFavourite, IToken token = null) { token = GetQueryToken(token); if (token == null || isFavourite == _favourited || isFavourite == null || !_isTweetPublished || _isTweetDestroyed || _id == null) { return; } string query = (bool)isFavourite ? String.Format(Resources.Tweet_CreateFavourite, _id) : String.Format(Resources.Tweet_DestroyFavourite, _id); ObjectResponseDelegate responseDelegate = delegate(Dictionary <string, object> responseObject) { _favourited = responseObject.GetProp("favorited") as bool?; }; token.ExecutePOSTQuery(query, responseDelegate, null); }