static void _myspace_status_update_update_status (SwStatusUpdateIface *self, const gchar *msg, GHashTable *fields, DBusGMethodInvocation *context) { SwServiceMySpace *myspace = (SwServiceMySpace *)self; SwServiceMySpacePrivate *priv = myspace->priv; RestProxyCall *call; RestProxyCallClass *call_class; gchar *escaped_msg; if (!priv->user_id) return; call = rest_proxy_new_call (priv->proxy); call_class = REST_PROXY_CALL_GET_CLASS (call); rest_proxy_call_set_method (call, "PUT"); rest_proxy_call_set_function (call, "1.0/statusmood/@me/@self"); escaped_msg = g_markup_escape_text (msg, -1); request_body = g_strdup_printf ("{ \"status\":\"%s\" }", escaped_msg); call_class->serialize_params = _myspace_serialize_params; rest_proxy_call_async (call, _update_status_cb, (GObject *)self, NULL, NULL); call_class->serialize_params = NULL; sw_status_update_iface_return_from_update_status (context); g_free (request_body); g_free (escaped_msg); }
void cb_user_stream_start (CbUserStream *self) { g_debug ("%u Starting stream for %s", self->state, self->account_name); g_assert (self->proxy_data_set); if (self->proxy_call != NULL) rest_proxy_call_cancel (self->proxy_call); self->proxy_call = rest_proxy_new_call (self->proxy); if (self->stresstest) rest_proxy_call_set_function (self->proxy_call, "1.1/statuses/sample.json"); else rest_proxy_call_set_function (self->proxy_call, "1.1/user.json"); rest_proxy_call_set_method (self->proxy_call, "GET"); start_heartbeat_timeout (self); rest_proxy_call_continuous (self->proxy_call, continuous_cb, NULL, self, NULL/* error */); }
static void _plurk_status_update_update_status (SwStatusUpdateIface *self, const gchar *msg, GHashTable *fields, DBusGMethodInvocation *context) { SwServicePlurk *plurk = SW_SERVICE_PLURK (self); SwServicePlurkPrivate *priv = GET_PRIVATE (plurk); RestProxyCall *call; if (!priv->user_id) return; call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_method (call, "POST"); rest_proxy_call_set_function (call, "Timeline/plurkAdd"); rest_proxy_call_add_params (call, "api_key", priv->api_key, "content", msg, "qualifier", ":", NULL); rest_proxy_call_async (call, _update_status_cb, (GObject *)self, NULL, NULL); sw_status_update_iface_return_from_update_status (context); }
static void _twitter_status_update_update_status (SwStatusUpdateIface *self, const gchar *msg, GHashTable *fields, DBusGMethodInvocation *context) { SwServiceTwitter *twitter = SW_SERVICE_TWITTER (self); SwServiceTwitterPrivate *priv = twitter->priv; RestProxyCall *call; if (!priv->user_id) return; /* * http://apiwiki.twitter.com/Twitter-REST-API-Method:-statuses update */ call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_method (call, "POST"); rest_proxy_call_set_function (call, "1/statuses/update.xml"); rest_proxy_call_add_param (call, "status", msg); if (fields) { const gchar *latitude, *longitude, *twitter_reply_to; latitude = g_hash_table_lookup (fields, "latitude"); longitude = g_hash_table_lookup (fields, "longitude"); if (latitude && longitude) { rest_proxy_call_add_params (call, "lat", latitude, "long", longitude, NULL); } twitter_reply_to = g_hash_table_lookup (fields, "x-twitter-reply-to"); if (twitter_reply_to) { rest_proxy_call_add_param (call, "in_reply_to_status_id", twitter_reply_to); } } rest_proxy_call_async (call, _update_status_cb, (GObject *)self, NULL, NULL); sw_status_update_iface_return_from_update_status (context); }
static void on_upload_cb (RestProxyCall *call, gsize total, gsize uploaded, const GError *error, GObject *weak_object, gpointer user_data) { SwServiceTwitter *twitter = SW_SERVICE_TWITTER (weak_object); RestXmlNode *root; char *tweet; int opid = GPOINTER_TO_INT (user_data); gint percent; if (error) { sw_photo_upload_iface_emit_photo_upload_progress (twitter, opid, -1, error->message); return; } /* Now post to Twitter */ root = node_from_call (call); if (root == NULL || g_strcmp0 (root->name, "image") != 0) { sw_photo_upload_iface_emit_photo_upload_progress (twitter, opid, -1, "Unexpected response from Twitpic"); if (root) rest_xml_node_unref (root); return; } /* This format is for tweets announcing twitpic URLs, "[tweet] [url]". */ tweet = g_strdup_printf (_("%s %s"), rest_xml_node_find (root, "text")->content, rest_xml_node_find (root, "url")->content); call = rest_proxy_new_call (twitter->priv->proxy); rest_proxy_call_set_method (call, "POST"); rest_proxy_call_set_function (call, "1/statuses/update.xml"); rest_proxy_call_add_param (call, "status", tweet); rest_proxy_call_async (call, on_upload_tweet_cb, (GObject *)twitter, NULL, NULL); percent = (gdouble) uploaded / (gdouble) total * 100; sw_photo_upload_iface_emit_photo_upload_progress (twitter, opid, percent, ""); rest_xml_node_unref (root); g_free (tweet); }
static void update_status (MojitoService *service, const char *msg) { MojitoServiceTwitter *twitter = MOJITO_SERVICE_TWITTER (service); MojitoServiceTwitterPrivate *priv = twitter->priv; RestProxyCall *call; if (!priv->user_id) return; call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_method (call, "POST"); rest_proxy_call_set_function (call, "statuses/update.xml"); rest_proxy_call_add_params (call, "status", msg, NULL); rest_proxy_call_async (call, _status_updated_cb, (GObject *)service, NULL, NULL); }
static void _twitter_status_update_update_status (MojitoStatusUpdateIface *self, const gchar *msg, DBusGMethodInvocation *context) { MojitoServiceTwitter *twitter = MOJITO_SERVICE_TWITTER (self); MojitoServiceTwitterPrivate *priv = twitter->priv; RestProxyCall *call; if (!priv->user_id) return; call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_method (call, "POST"); rest_proxy_call_set_function (call, "statuses/update.xml"); rest_proxy_call_add_params (call, "status", msg, NULL); rest_proxy_call_async (call, _update_status_cb, (GObject *)self, NULL, NULL); mojito_status_update_iface_return_from_update_status (context); }
static void online_notify (gboolean online, gpointer user_data) { SwServiceYoutube *youtube = (SwServiceYoutube *)user_data; SwServiceYoutubePrivate *priv = GET_PRIVATE (youtube); priv->credentials = OFFLINE; if (online) { if (priv->username && priv->password) { RestProxyCall *call; /* request user_auth */ /* http://code.google.com/intl/zh-TW/apis/youtube/2.0/developers_guide_protocol_clientlogin.html */ call = rest_proxy_new_call (priv->auth_proxy); rest_proxy_call_set_method (call, "POST"); rest_proxy_call_set_function (call, "ClientLogin"); rest_proxy_call_add_params (call, "Email", priv->username, "Passwd", priv->password, "service", "youtube", "source", "SUSE MeeGo", NULL); rest_proxy_call_add_header (call, "Content-Type", "application/x-www-form-urlencoded"); rest_proxy_call_async (call, (RestProxyCallAsyncCallback)_got_user_auth, (GObject*)youtube, NULL, NULL); } } else { sw_service_emit_capabilities_changed ((SwService *)youtube, get_dynamic_caps ((SwService *)youtube)); } }
static void _sina_status_update_update_status (SwStatusUpdateIface *self, const gchar *msg, GHashTable *fields, DBusGMethodInvocation *context) { SwServiceSina *sina = SW_SERVICE_SINA (self); SwServiceSinaPrivate *priv = GET_PRIVATE (sina); RestProxyCall *call; if (!priv->user_id) return; call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_method (call, "POST"); rest_proxy_call_set_function (call, "statuses/update.xml"); rest_proxy_call_add_params (call, "status", msg, NULL); rest_proxy_call_async (call, _update_status_cb, (GObject *)self, NULL, NULL); sw_status_update_iface_return_from_update_status (context); }
static gchar * get_identity_sync (GoaOAuthProvider *provider, const gchar *access_token, const gchar *access_token_secret, gchar **out_presentation_identity, GCancellable *cancellable, GError **error) { RestProxy *proxy; RestProxyCall *call; JsonParser *parser; JsonObject *json_object; gchar *ret; gchar *id; gchar *presentation_identity; ret = NULL; proxy = NULL; call = NULL; parser = NULL; id = NULL; presentation_identity = NULL; /* TODO: cancellable */ proxy = oauth_proxy_new_with_token (goa_oauth_provider_get_consumer_key (provider), goa_oauth_provider_get_consumer_secret (provider), access_token, access_token_secret, "http://api.flickr.com/services/rest", FALSE); call = rest_proxy_new_call (proxy); rest_proxy_call_add_param (call, "method", "flickr.test.login"); rest_proxy_call_add_param (call, "format", "json"); rest_proxy_call_add_param (call, "nojsoncallback", "1"); rest_proxy_call_set_method (call, "GET"); if (!rest_proxy_call_sync (call, error)) goto out; if (rest_proxy_call_get_status_code (call) != 200) { g_set_error (error, GOA_ERROR, GOA_ERROR_FAILED, _("Expected status 200 when requesting user id, instead got status %d (%s)"), rest_proxy_call_get_status_code (call), rest_proxy_call_get_status_message (call)); goto out; } parser = json_parser_new (); if (!json_parser_load_from_data (parser, rest_proxy_call_get_payload (call), rest_proxy_call_get_payload_length (call), error)) { g_prefix_error (error, _("Error parsing response as JSON: ")); goto out; } json_object = json_node_get_object (json_parser_get_root (parser)); json_object = json_object_get_object_member (json_object, "user"); if (json_object == NULL) { g_set_error (error, GOA_ERROR, GOA_ERROR_FAILED, _("Didn't find user member in JSON data")); goto out; } id = g_strdup (json_object_get_string_member (json_object, "id")); if (id == NULL) { g_set_error (error, GOA_ERROR, GOA_ERROR_FAILED, _("Didn't find user.id member in JSON data")); goto out; } json_object = json_object_get_object_member (json_object, "username"); if (json_object == NULL) { g_set_error (error, GOA_ERROR, GOA_ERROR_FAILED, _("Didn't find user.username member in JSON data")); goto out; } presentation_identity = g_strdup (json_object_get_string_member (json_object, "_content")); if (presentation_identity == NULL) { g_set_error (error, GOA_ERROR, GOA_ERROR_FAILED, _("Didn't find user.username._content member in JSON data")); goto out; } ret = id; id = NULL; if (out_presentation_identity != NULL) { *out_presentation_identity = presentation_identity; presentation_identity = NULL; } out: g_free (id); g_free (presentation_identity); if (call != NULL) g_object_unref (call); if (proxy != NULL) g_object_unref (proxy); return ret; }