diff options
author | dequis <dx@dxzone.com.ar> | 2015-06-08 00:42:11 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-06-08 00:42:11 -0300 |
commit | 1201fcb6272cdba734594f9358ba2d08db1afec9 (patch) | |
tree | fafd01c3ca58fd33f4bb0ad0c1439931456748cf /protocols/twitter/twitter_lib.c | |
parent | 61e7e02096c7910addba32a9060a5e0cba68284b (diff) |
twitter: show full url in the url command, with username
By asking the server for the username.
Storing the username somewhere would have made sense, but this command
isn't going to be used very often, so, whatever.
Diffstat (limited to 'protocols/twitter/twitter_lib.c')
-rw-r--r-- | protocols/twitter/twitter_lib.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index 17bceb9f..40adb992 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -1572,3 +1572,42 @@ void twitter_favourite_tweet(struct im_connection *ic, guint64 id) ic, 1, args, 2, TWITTER_HTTP_USER_ACK); g_free(args[1]); } + +static void twitter_http_status_show_url(struct http_request *req) +{ + struct im_connection *ic = req->data; + json_value *parsed, *id; + const char *name; + + // Check if the connection is still active. + if (!g_slist_find(twitter_connections, ic)) { + return; + } + + if (!(parsed = twitter_parse_response(ic, req))) { + return; + } + + /* for the parson branch: + name = json_object_dotget_string(json_object(parsed), "user.screen_name"); + id = json_object_get_integer(json_object(parsed), "id"); + */ + + name = json_o_str(json_o_get(parsed, "user"), "screen_name"); + id = json_o_get(parsed, "id"); + + if (name && id && id->type == json_integer) { + twitter_log(ic, "https://twitter.com/%s/status/%" G_GUINT64_FORMAT, name, id->u.integer); + } else { + twitter_log(ic, "Error: could not fetch tweet url."); + } + + json_value_free(parsed); +} + +void twitter_status_show_url(struct im_connection *ic, guint64 id) +{ + char *url = g_strdup_printf("%s%" G_GUINT64_FORMAT "%s", TWITTER_STATUS_SHOW_URL, id, ".json"); + twitter_http(ic, url, twitter_http_status_show_url, ic, 0, NULL, 0); + g_free(url); +} |