Changeset 13171
- Timestamp:
- 06/04/08 02:28:29 (5 years ago)
- Location:
- lang/java/misc/twittercui/src
- Files:
-
- 3 added
- 5 modified
- 1 moved
-
main/java/twitter/TwitterAPIWrapper.java (modified) (1 diff)
-
main/java/twitter/WebAgent.java (modified) (3 diffs)
-
main/java/twittercui/ConsoleMain.java (modified) (1 diff)
-
main/java/twittercui/commands/Command.java (modified) (2 diffs)
-
main/java/twittercui/commands/GetMyTimelineCommand.java (modified) (2 diffs)
-
test/java/twitter/WebAgent_createAuthentication_Test.java (added)
-
test/java/twitter/WebAgent_get_Test.java (moved) (moved from lang/java/misc/twittercui/src/test/java/twitter/WebAgentTest.java) (2 diffs)
-
test/java/twittercui/commands (added)
-
test/java/twittercui/commands/GetMyTimelineCommandTest.java (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/java/misc/twittercui/src/main/java/twitter/TwitterAPIWrapper.java
r13007 r13171 26 26 public Timeline getTimeline() throws IOException, ParserConfigurationException, SAXException, TransformerException { 27 27 String uri = getBaseURI() + "/status/friends_timeline/" + this.id + this.getResponseFormat(); 28 Response response = this.webAgent.get(uri );28 Response response = this.webAgent.get(uri, this.id, this.pw); 29 29 return new Timeline(response); 30 30 } -
lang/java/misc/twittercui/src/main/java/twitter/WebAgent.java
r13007 r13171 4 4 import java.io.IOException; 5 5 import java.io.InputStreamReader; 6 import java.net.Authenticator; 6 7 import java.net.HttpURLConnection; 8 import java.net.PasswordAuthentication; 7 9 import java.net.URL; 10 11 import sun.misc.BASE64Encoder; 8 12 9 13 /** … … 31 35 * 32 36 * @param path 37 * @param id 38 * @param pw 33 39 * @return 34 40 * @throws IOException 35 41 */ 36 public synchronized Response get(String path ) throws IOException {42 public synchronized Response get(String path, String id, String pw) throws IOException { 37 43 URL url = new URL(path); 38 44 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 39 conn.setRequestMethod("POST"); // (�E�́E) 45 HttpAuthenticator http_authenticator = new HttpAuthenticator(id, pw); 46 Authenticator.setDefault(http_authenticator); 47 conn.setRequestMethod("GET"); // (�E�́E) 40 48 conn.setInstanceFollowRedirects(false); 41 49 conn.setRequestProperty("Accept-Language", "ja;q=0.7,en;q=0.3"); 50 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 51 conn.setDoOutput(true); 42 52 conn.connect(); 43 53 StringBuffer buf = new StringBuffer(); … … 53 63 return new Response(statusCode ,buf.toString()); 54 64 } 65 66 /** 67 * 68 * @param id 69 * @param pw 70 * @return 71 */ 72 protected String createAuthentication(String id, String pw) { 73 String s = "Basic" + (new BASE64Encoder().encode((id + ":" + pw).getBytes())); 74 return s; 75 } 76 77 /** 78 * 79 * @author fumi 80 * 81 */ 82 class HttpAuthenticator extends Authenticator { 83 private String username; 84 private String password; 85 86 /** 87 * 88 * @param username 89 * @param password 90 */ 91 public HttpAuthenticator(String username, String password){ 92 this.username = username; 93 this.password = password; 94 } 95 96 /** 97 * 98 */ 99 protected PasswordAuthentication getPasswordAuthentication(){ 100 return new 101 PasswordAuthentication(username, password.toCharArray()); 102 } 103 104 /** 105 * 106 * @return 107 */ 108 public String myGetRequestingPrompt(){ 109 return super.getRequestingPrompt(); 110 } 111 } 55 112 } -
lang/java/misc/twittercui/src/main/java/twittercui/ConsoleMain.java
r12581 r13171 88 88 e.printStackTrace(); 89 89 return; 90 } catch (Exception e) { 91 e.printStackTrace(); 90 92 } 91 93 } -
lang/java/misc/twittercui/src/main/java/twittercui/commands/Command.java
r12581 r13171 33 33 if ("showme".equals(commandCode)) { 34 34 command = new ShowMeCommand(id, pw); 35 } else if ("ls".equals(commandCode)) { 36 command = new GetMyTimelineCommand(id, pw); 35 37 } 36 38 return command; … … 39 41 * ��ۂ̃A���B 40 42 * @return 43 * @throws Exception 41 44 */ 42 abstract public String execute() ;45 abstract public String execute() throws Exception; 43 46 } -
lang/java/misc/twittercui/src/main/java/twittercui/commands/GetMyTimelineCommand.java
r12581 r13171 1 1 package twittercui.commands; 2 3 import java.util.List; 4 5 import twitter.Status; 6 import twitter.TwitterAPIWrapper; 2 7 3 8 public class GetMyTimelineCommand extends Command { … … 8 13 9 14 @Override 10 public String execute() { 11 return null; 15 public String execute() throws Exception { 16 TwitterAPIWrapper twitter = new TwitterAPIWrapper(this.id, this.pw); 17 List<Status> list = twitter.getTimeline().getTimeline(); 18 StringBuffer sb = new StringBuffer(); 19 for (Status s: list) { 20 sb.append(s.getStatusId()); 21 sb.append(":"); 22 sb.append(s.getStatusText()); 23 sb.append("\n"); 24 } 25 return sb.toString(); 12 26 } 13 27 -
lang/java/misc/twittercui/src/test/java/twitter/WebAgent_get_Test.java
r13007 r13171 18 18 import com.sun.org.apache.xpath.internal.XPathAPI; 19 19 20 public class WebAgent Test {20 public class WebAgent_get_Test { 21 21 22 22 @Test … … 24 24 WebAgent agent = new WebAgent(); 25 25 try { 26 String s = agent.get("http://twitter.com/statuses/friends_timeline/itengineer.xml" ).getContents();26 String s = agent.get("http://twitter.com/statuses/friends_timeline/itengineer.xml", "", "").getContents(); 27 27 outputTest(new ByteArrayInputStream(s.getBytes())); 28 28 } catch (IOException e) {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)