Mercurial > pidgin-twitter
changeset 345:2e37e715e4a6
add preliminary support for quotetweet and official retweet.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 12 Dec 2009 00:18:27 +0900 |
parents | 3d2657ce4dba |
children | dbebabe99035 |
files | Makefile.in configure.ac main.c pidgin-twitter.h twitter_api.c twitter_api.h util.c |
diffstat | 7 files changed, 75 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.in Mon Oct 19 00:48:25 2009 +0900 +++ b/Makefile.in Sat Dec 12 00:18:27 2009 +0900 @@ -9,7 +9,7 @@ PIDGIN_CFLAGS = @PIDGIN_CFLAGS@ GLIB_CFLAGS = @GLIB_CFLAGS@ XML_CFLAGS = @XML_CFLAGS@ -CFLAGS = -fPIC -shared -Wall -g $(PIDGIN_CFLAGS) $(GLIB_CFLAGS) $(XML_CFLAGS) -DDATADIR=\"$(PIDGIN_DATA_DIR)\" +CFLAGS = -fPIC -shared -Wall -Werror -g $(PIDGIN_CFLAGS) $(GLIB_CFLAGS) $(XML_CFLAGS) -DDATADIR=\"$(PIDGIN_DATA_DIR)\" GLIB_LIBS = @GLIB_LIBS@ XML_LIBS = @XML_LIBS@
--- a/configure.ac Mon Oct 19 00:48:25 2009 +0900 +++ b/configure.ac Sat Dec 12 00:18:27 2009 +0900 @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT(pidgin-twitter, 0.9.0, yaz@honeyplanet.jp) +AC_INIT(pidgin-twitter, 0.9.1, yaz@honeyplanet.jp) AC_CONFIG_SRCDIR([main.c]) # Checks for programs.
--- a/main.c Mon Oct 19 00:48:25 2009 +0900 +++ b/main.c Sat Dec 12 00:18:27 2009 +0900 @@ -1420,7 +1420,7 @@ PURPLE_PRIORITY_DEFAULT, /**< priority */ PLUGIN_ID, /**< id */ "Pidgin-Twitter", /**< name */ - "0.9.0", /**< version */ + "0.9.1", /**< version */ "provides useful features for twitter", /** summary */ "provides useful features for twitter", /** desc */ "Yoshiki Yazawa, mikanbako, \nKonosuke Watanabe, IWATA Ray, \nmojin, umq, \nthe pidging-twitter team", /**< author */
--- a/pidgin-twitter.h Mon Oct 19 00:48:25 2009 +0900 +++ b/pidgin-twitter.h Sat Dec 12 00:18:27 2009 +0900 @@ -172,7 +172,7 @@ #define TAG_FORMAT_TWITTER "%s<a href='http://twitter.com/search?q=%%23%s'>#%s</a>" #define TAG_FORMAT_IDENTICA "#<a href='http://identi.ca/tag/%s'>%s</a>" #define GROUP_FORMAT_IDENTICA "!<a href='http://identi.ca/group/%s'>%s</a>" -#define LINK_FORMAT_TWITTER " <a href='PT://reply-twitter/?id=%s&user=%s'>R</a> <a href='PT://fav-twitter/?id=%s'>F</a> <a href='PT://retweet-twitter/?id=%s&user=%s&msg=%s'>RT</a>" +#define LINK_FORMAT_TWITTER " <a href='PT://reply-twitter/?id=%s&user=%s'>RE</a> <a href='PT://fav-twitter/?id=%s'>FV</a> <a href='PT://retweet-twitter/?id=%s'>RT</a> <a href='PT://quotetweet-twitter/?id=%s&user=%s&msg=%s'>QT</a>" #define DEFAULT_LIST "(list of users: separated with ' ,:;')" #define OOPS_MESSAGE "<body>Oops! Your update was over 140 characters. We sent the short version to your friends (they can view the entire update on the web).<BR></body>" @@ -201,10 +201,17 @@ /* twitter API specific macros */ #define TWITTER_BASE_URL "http://twitter.com" +#define TWITTER_API_BASE_URL "http://api.twitter.com" +#if 0 #define TWITTER_STATUS_GET "GET /statuses/friends_timeline.xml?count=%d HTTP/1.1\r\n" \ "Host: twitter.com\r\n" \ "User-Agent: pidgin-twitter\r\n" \ "Authorization: Basic %s\r\n" +#endif +#define TWITTER_STATUS_GET "GET /1/statuses/home_timeline.xml?count=%d HTTP/1.1\r\n" \ + "Host: api.twitter.com\r\n" \ + "User-Agent: pidgin-twitter\r\n" \ + "Authorization: Basic %s\r\n" #define TWITTER_STATUS_POST "POST /statuses/update.xml HTTP/1.1\r\n" \ "Host: twitter.com\r\n" \ "User-Agent: pidgin-twitter\r\n" \ @@ -214,6 +221,10 @@ "Host: twitter.com\r\n" \ "User-Agent: pidgin-twitter\r\n" \ "Authorization: Basic %s\r\n" +#define TWITTER_RETWEET_POST "POST /1/statuses/retweet/%llu.xml HTTP/1.1\r\n" \ + "Host: api.twitter.com\r\n" \ + "User-Agent: pidgin-twitter\r\n" \ + "Authorization: Basic %s\r\n" #define TWITTER_STATUS_FORMAT "status=%s&source=pidgintwitter" #define TWITTER_REPLY_FORMAT "status=%s&in_reply_to_status_id=%llu&source=pidgintwitter"
--- a/twitter_api.c Mon Oct 19 00:48:25 2009 +0900 +++ b/twitter_api.c Sat Dec 12 00:18:27 2009 +0900 @@ -332,7 +332,7 @@ request = g_strconcat(header, "\r\n", NULL); /* invoke fetch */ - purple_util_fetch_url_request(TWITTER_BASE_URL, FALSE, + purple_util_fetch_url_request(TWITTER_API_BASE_URL, FALSE, NULL, TRUE, request, TRUE, get_status_with_api_cb, data); @@ -598,6 +598,55 @@ g_free(request); } +static void +retweet_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, + const gchar *url_text, size_t len, + const gchar *error_message) +{ + /* dummy */ +} + +void +retweet_with_api(guint64 id) +{ + char *header, *request; + char *basic_auth, *basic_auth_encoded; + + const char *screen_name = + purple_prefs_get_string(OPT_SCREEN_NAME_TWITTER); + const char *password = purple_prefs_get_string(OPT_PASSWORD_TWITTER); + + if(id == 0) { + twitter_debug("invalid message id\n"); + return; + } + + if (!screen_name || !password || !screen_name[0] || !password[0]) { + twitter_debug("screen_name or password is empty\n"); + return; + } + + basic_auth = g_strdup_printf("%s:%s", screen_name, password); + basic_auth_encoded = purple_base64_encode((unsigned char *)basic_auth, + strlen(basic_auth)); + g_free(basic_auth); + + + header = g_strdup_printf(TWITTER_RETWEET_POST, + (long long unsigned int)id, + basic_auth_encoded); + request = g_strconcat(header, "\r\n", NULL); + + purple_util_fetch_url_request(TWITTER_API_BASE_URL, FALSE, + NULL, TRUE, request, TRUE, + retweet_with_api_cb, NULL); + twitter_debug("request = %s\n", request); + + g_free(header); + g_free(basic_auth_encoded); + g_free(request); +} + void signed_on_cb(PurpleConnection *gc) {
--- a/twitter_api.h Mon Oct 19 00:48:25 2009 +0900 +++ b/twitter_api.h Sat Dec 12 00:18:27 2009 +0900 @@ -3,6 +3,8 @@ void post_status_with_api(PurpleAccount *account, char **buffer); gboolean get_status_with_api(gpointer data); +void fav_with_api(guint64 id); +void retweet_with_api(guint64 id); void signed_on_cb(PurpleConnection *gc); #endif
--- a/util.c Mon Oct 19 00:48:25 2009 +0900 +++ b/util.c Sat Dec 12 00:18:27 2009 +0900 @@ -6,7 +6,6 @@ /* prototypes */ static gchar *twitter_memrchr(const gchar *s, int c, size_t n); -void fav_with_api(guint64 id); /* functions */ @@ -485,6 +484,11 @@ return TRUE; } else if(strstr(cmd, "retweet-twitter")) { + idstr = g_hash_table_lookup(params, "id"); + retweet_with_api(strtoull(idstr, NULL, 10)); + return TRUE; + } + else if(strstr(cmd, "quotetweet-twitter")) { gchar *msg0; sender = g_hash_table_lookup(params, "user"); idstr = g_hash_table_lookup(params, "id"); @@ -503,7 +507,7 @@ twitter_debug("sender = %s, id = %llu\n", sender, (unsigned long long)msgid); - recipient = g_strdup_printf("RT @%s: %s", sender, msg); + recipient = g_strdup_printf("QT @%s: %s", sender, msg); g_free(msg); gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, recipient, -1); @@ -559,7 +563,8 @@ linkstr = g_strdup_printf(LINK_FORMAT_TWITTER, idstr, user, /* Reply */ idstr, /* Favorite */ - idstr, user, boddy); /* Retweet */ + idstr, /* Retweet */ + idstr, user, boddy); /* Quotetweet */ twitter_debug("linkstr = %s\n", linkstr);