mirror of
git://git.psyced.org/git/psyced
synced 2024-08-15 03:25:10 +00:00
added identi.ca support (uses twitter api); spare a json enc/dec when surfing locally
This commit is contained in:
parent
bcbf2785d8
commit
9421149ffd
9 changed files with 88 additions and 18 deletions
|
@ -15,12 +15,18 @@
|
|||
|
||||
inherit NET_PATH "http/oauth";
|
||||
|
||||
string name = "twitter";
|
||||
string display_name = "twitter";
|
||||
string api_base_url = "http://api.twitter.com/1";
|
||||
|
||||
int status_max_len = 140;
|
||||
|
||||
object load(object usr, string key, string secret, string request, string access, string authorize) {
|
||||
consumer_key = TWITTER_KEY;
|
||||
consumer_secret = TWITTER_SECRET;
|
||||
request_token_url = "http://twitter.com/oauth/request_token";
|
||||
access_token_url = "http://twitter.com/oauth/access_token";
|
||||
authorize_url = "http://twitter.com/oauth/authorize";
|
||||
unless (consumer_key) consumer_key = TWITTER_KEY;
|
||||
unless (consumer_secret) consumer_secret = TWITTER_SECRET;
|
||||
unless (request_token_url) request_token_url = "http://twitter.com/oauth/request_token";
|
||||
unless (access_token_url) access_token_url = "http://twitter.com/oauth/access_token";
|
||||
unless (authorize_url) authorize_url = "http://twitter.com/oauth/authorize";
|
||||
|
||||
return ::load(usr, key, secret, request, access, authorize);
|
||||
}
|
||||
|
@ -28,18 +34,19 @@ object load(object usr, string key, string secret, string request, string access
|
|||
void parse_status_update(string body, string headers, int http_status) {
|
||||
P3(("twitter/client:parse_status_update(%O, %O, %O)\n", body, headers, http_status))
|
||||
if (http_status != R_OK)
|
||||
sendmsg(user, "_error_twitter_status_update", "Error: failed to post status update on twitter.");
|
||||
sendmsg(user, "_error_"+name+"_status_update", "Error: failed to post status update on [_name].", (["_name": display_name]));
|
||||
}
|
||||
|
||||
void status_update(string text) {
|
||||
P3(("twitter/client:status_update()\n"))
|
||||
if (strlen(text) > 140) text = text[0..136] + "...";
|
||||
if (status_max_len && strlen(text) > status_max_len) text = text[0..status_max_len-4] + "...";
|
||||
|
||||
object ua = clone_object(NET_PATH "http/fetch");
|
||||
ua->content(#'parse_status_update, 1, 1); //');
|
||||
fetch(ua, "http://api.twitter.com/1/statuses/update.json", "POST", (["status": text]));
|
||||
fetch(ua, api_base_url + "/statuses/update.json", "POST", (["status": text]));
|
||||
}
|
||||
|
||||
#if 1 //not used, just an example
|
||||
void parse_home_timeline(string body, string headers, int http_status) {
|
||||
P3(("twitter/client:parse_home_timeline(%O, %O, %O)\n", body, headers, http_status))
|
||||
}
|
||||
|
@ -48,5 +55,6 @@ void home_timeline() {
|
|||
P3(("twitter/client:home_timeline()\n"))
|
||||
object ua = clone_object(NET_PATH "http/fetch");
|
||||
ua->content(#'parse_home_timeline, 1, 1); //');
|
||||
fetch(ua, "http://api.twitter.com/1/statuses/home_timeline.json");
|
||||
fetch(ua, api_base_url + "/statuses/home_timeline.json");
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue