Permalink
Browse files

Essai d'envoi d'un tweet en cas d'ajout de fichier

  • Loading branch information...
1 parent bd616b3 commit 3da7c51220a47485ad88d770fec7687a18a4c2d8 @nicogiard committed Mar 10, 2012
Showing with 48 additions and 0 deletions.
  1. +8 −0 app/controllers/Application.java
  2. +40 −0 app/utils/Twitter.java
@@ -13,6 +13,7 @@
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.With;
+import utils.Twitter;
import java.io.File;
import java.io.FileNotFoundException;
@@ -111,6 +112,13 @@ public static void save(@Required @Valid Torrent torrent, File file, String tags
}
torrent.tags = extractTags(tags);
torrent.save();
+
+ try {
+ Twitter.init().setStatus("New : " + torrent.filename);
+ } catch (Exception e) {
+ Logger.error(e.getMessage(), e);
+ }
+
index();
}
View
@@ -0,0 +1,40 @@
+package utils;
+
+import play.Logger;
+import play.libs.OAuth;
+import play.libs.WS;
+
+import java.net.URLEncoder;
+
+public class Twitter {
+
+ private String username = "pisteurNAS";
+ private String token = "520216648-fTEy2CSiboeezJ9aNmkp6ki4wJpQNmloUdzeCJsf";
+ private String secret = "TTgIa1EDeaeehiYwDJrtR62qZlvyG5DA9luBzScr4Ic";
+
+ public static Twitter instance;
+
+ private static final OAuth.ServiceInfo TWITTER = new OAuth.ServiceInfo(
+ "http://twitter.com/oauth/request_token",
+ "http://twitter.com/oauth/access_token",
+ "http://twitter.com/oauth/authorize",
+ "gjovZSZw9nlg7MMwRIUQ",
+ "GEtcK2zAkGcGhTqPItYCxJuMVc74LopODpIppOYAf8"
+ );
+
+ private Twitter() {
+ }
+
+ public static Twitter init() {
+ if (instance == null) {
+ instance = new Twitter();
+ }
+ return instance;
+ }
+
+ public String setStatus(String status) throws Exception {
+ String url = "http://twitter.com/statuses/update.json?status=" + URLEncoder.encode(status, "utf-8");
+ String response = WS.url(url).oauth(TWITTER, token, secret).post().getString();
+ return response;
+ }
+}

0 comments on commit 3da7c51

Please sign in to comment.