Changeset 13007
- Timestamp:
- 06/01/08 22:37:21 (6 months ago)
- Location:
- lang/java/misc/twittercui/src
- Files:
-
- 7 added
- 4 modified
-
main/java/twitter/Response.java (added)
-
main/java/twitter/Status.java (modified) (1 diff)
-
main/java/twitter/Timeline.java (added)
-
main/java/twitter/TwitterAPIWrapper.java (modified) (1 diff)
-
main/java/twitter/WebAgent.java (modified) (3 diffs)
-
test/java/twitter/StatusTest.java (added)
-
test/java/twitter/TimelineTest.java (added)
-
test/java/twitter/WebAgentTest.java (modified) (2 diffs)
-
test/resources (added)
-
test/resources/test.html (added)
-
test/resources/test.xml (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/java/misc/twittercui/src/main/java/twitter/Status.java
r12581 r13007 1 1 package twitter; 2 2 3 import org.w3c.dom.Node; 4 3 5 public class Status { 4 public Status(String contents) { 5 6 7 private String postedDate; 8 private String statusId; 9 private String statusText; 10 11 public Status(Node node) { 12 this.postedDate = node.getChildNodes().item(1).getTextContent(); 13 this.statusId = node.getChildNodes().item(3).getTextContent(); 14 this.statusText = node.getChildNodes().item(5).getTextContent(); 15 } 16 17 public String getPostedDate() { 18 return postedDate; 19 } 20 public void setPostedDate(String postedDate) { 21 this.postedDate = postedDate; 22 } 23 public String getStatusId() { 24 return statusId; 25 } 26 public void setStatusId(String statusId) { 27 this.statusId = statusId; 28 } 29 public String getStatusText() { 30 return statusText; 31 } 32 public void setStatusText(String statusText) { 33 this.statusText = statusText; 6 34 } 7 35 } -
lang/java/misc/twittercui/src/main/java/twitter/TwitterAPIWrapper.java
r12581 r13007 1 1 package twitter; 2 2 3 import java.util.List; 3 import java.io.IOException; 4 5 import javax.xml.parsers.ParserConfigurationException; 6 import javax.xml.transform.TransformerException; 7 8 import org.xml.sax.SAXException; 4 9 5 10 public class TwitterAPIWrapper { 6 public List<Status> getTimeline(String id) { 7 return null; 11 12 private WebAgent webAgent; 13 private String id; 14 private String pw; 15 16 public TwitterAPIWrapper(String id) { 17 this(id, null); 8 18 } 9 protected boolean isStatus(String contents) { 19 20 public TwitterAPIWrapper(String id, String pw) { 21 this.webAgent = WebAgent.getInstance(); 22 this.id = id; 23 this.pw = pw; 24 } 25 26 public Timeline getTimeline() throws IOException, ParserConfigurationException, SAXException, TransformerException { 27 String uri = getBaseURI() + "/status/friends_timeline/" + this.id + this.getResponseFormat(); 28 Response response = this.webAgent.get(uri); 29 return new Timeline(response); 30 } 31 32 protected boolean isStatus(String contents) throws SAXException, IOException, ParserConfigurationException { 33 // TODO: 10 34 return true; 11 35 } 36 protected String getBaseURI() { 37 return "http://twitter.com/"; 38 } 39 protected String getResponseFormat() { 40 return ".xml"; 41 } 42 43 public String getId() { 44 return id; 45 } 46 public void setId(String id) { 47 this.id = id; 48 } 49 public String getPw() { 50 return pw; 51 } 52 public void setPw(String pw) { 53 this.pw = pw; 54 } 12 55 } -
lang/java/misc/twittercui/src/main/java/twitter/WebAgent.java
r12581 r13007 13 13 */ 14 14 public class WebAgent { 15 public synchronized String get(String path) throws IOException { 15 16 private static WebAgent _instance; 17 18 /** 19 * 20 * @return 21 */ 22 public synchronized static WebAgent getInstance() { 23 WebAgent obj = _instance; 24 if (obj == null) { 25 obj = new WebAgent(); 26 } 27 return obj; 28 } 29 30 /** 31 * 32 * @param path 33 * @return 34 * @throws IOException 35 */ 36 public synchronized Response get(String path) throws IOException { 16 37 URL url = new URL(path); 17 38 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); … … 21 42 conn.connect(); 22 43 StringBuffer buf = new StringBuffer(); 44 int statusCode = conn.getResponseCode(); 23 45 BufferedReader br = new BufferedReader( 24 46 new InputStreamReader(conn.getInputStream(), "UTF-8")); … … 29 51 conn.disconnect(); 30 52 31 return buf.toString();53 return new Response(statusCode ,buf.toString()); 32 54 } 33 55 } -
lang/java/misc/twittercui/src/test/java/twitter/WebAgentTest.java
r12581 r13007 10 10 import javax.xml.transform.TransformerException; 11 11 12 import org.junit.Test; 12 13 import org.w3c.dom.Document; 13 14 import org.w3c.dom.Node; … … 17 18 import com.sun.org.apache.xpath.internal.XPathAPI; 18 19 19 import junit.framework.TestCase; 20 public class WebAgentTest { 20 21 21 public class WebAgentTest extends TestCase { 22 @Test 22 23 public void testGet() { 23 24 WebAgent agent = new WebAgent(); 24 25 try { 25 String s = agent.get("http://twitter.com/statuses/friends_timeline/itengineer.xml") ;26 String s = agent.get("http://twitter.com/statuses/friends_timeline/itengineer.xml").getContents(); 26 27 outputTest(new ByteArrayInputStream(s.getBytes())); 27 28 } catch (IOException e) {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)