/** * Destroys the direct message specified in the required ID parameter. The authenticating user must be the recipient of the specified direct message. * <br>This method calls http://twitter.com/direct_messages/destroy * * @param id the ID of the direct message to destroy * @return the deleted direct message * @throws TwitterException when Twitter service or network is unavailable * @see <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-direct_messages%C2%A0destroy">Twitter API Wiki / Twitter REST API Method: direct_messages destroy</a> * @since Twitter4J 2.0.1 */ public DirectMessage destroyDirectMessage(int id) throws TwitterException { return new DirectMessage(http.post(getBaseURL() + "direct_messages/destroy/" + id + ".xml", new PostParameter[0], true), this); }
static List<DirectMessage> constructDirectMessages(Response res, Twitter twitter) throws TwitterException { Document doc = res.asDocument(); if (isRootNodeNilClasses(doc)) { return new ArrayList<DirectMessage>(0); } else { try { ensureRootNodeNameIs("direct-messages", doc); NodeList list = doc.getDocumentElement().getElementsByTagName( "direct_message"); int size = list.getLength(); List<DirectMessage> messages = new ArrayList<DirectMessage>(size); for (int i = 0; i < size; i++) { Element status = (Element) list.item(i); messages.add(new DirectMessage(res, status, twitter)); } return messages; } catch (TwitterException te) { if (isRootNodeNilClasses(doc)) { return new ArrayList<DirectMessage>(0); } else { throw te; } } } }
/** * Sends a new direct message to the specified user from the authenticating user. Requires both the user and text parameters below. * The text will be trimed if the length of the text is exceeding 140 characters. * <br>This method calls http://twitter.com/direct_messages/new * * @param id the ID or screen name of the user to whom send the direct message * @param text String * @return DirectMessage * @throws TwitterException when Twitter service or network is unavailable @see <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-direct_messages%C2%A0new">Twitter API Wiki / Twitter REST API Method: direct_messages new</a> */ public DirectMessage sendDirectMessage(String id, String text) throws TwitterException { return new DirectMessage(http.post(getBaseURL() + "direct_messages/new.xml", new PostParameter[]{new PostParameter("user", id), new PostParameter("text", text)}, true), this); }