public void receive() throws Exception { Object root = this.request("http://twitter.com/statuses/friends_timeline.json", false, null, true, true); if (!(root instanceof Vector)) throw new Exception("Timeline is not an array"); Hashtable names = new Hashtable(); Enumeration en = ((Vector) root).elements(); while (en.hasMoreElements()) { Object status = en.nextElement(); if (!(status instanceof Hashtable)) throw new Exception("Timeline status is not an object"); Hashtable statusht = (Hashtable) status; Object text = statusht.get("text"); String textstr = (String) text; if (!textstr.startsWith(MESSAGE_PREFIX)) continue; textstr = textstr.substring(MESSAGE_PREFIX.length()); if (!(text instanceof String)) throw new Exception("Status text is not a string"); Object user = statusht.get("user"); if (!(user instanceof Hashtable)) throw new Exception("Status user is not an object"); Object name = ((Hashtable) user).get("name"); if (!(name instanceof String)) throw new Exception("Status user name is not a string"); String namestr = (String) name; if (names.containsKey(namestr)) continue; names.put(namestr, Boolean.TRUE); String where = strip(textstr, '|', 0); String time = strip(textstr, '|', 1); String latlon = strip(textstr, '|', 2); if ((where == null) || (time == null) || (latlon == null)) continue; int colon = latlon.indexOf(':'); if (colon < 0) continue; double lat, lon; try { lat = Double.parseDouble(latlon.substring(0, colon)); lon = Double.parseDouble(latlon.substring(colon + 1)); } catch (Exception e) { continue; } this.main.updateSignPosition(namestr, lat, lon, where, time); } }
public void send(String message) throws Exception { Hashtable params = new Hashtable(); params.put("status", MESSAGE_PREFIX + message); this.request("http://twitter.com/statuses/update.json", true, params, true, false); }