static void got_tokens_cb (RestProxy *proxy, gboolean got_tokens, gpointer user_data) { SwServiceVimeo *self = (SwServiceVimeo *) user_data; SwService *service = SW_SERVICE (self); SwServiceVimeoPrivate *priv = self->priv; priv->configured = got_tokens; SW_DEBUG (VIMEO, "Got tokens: %s", got_tokens ? "yes" : "no"); if (got_tokens) { RestProxyCall *call; call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_function(call, "api/rest/v2"); rest_proxy_call_add_param (call, "method", "vimeo.test.login"); rest_proxy_call_async (call, _check_access_token_cb, G_OBJECT (self), NULL, NULL); g_object_unref (call); } sw_service_emit_capabilities_changed (service, get_dynamic_caps (service)); }
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 char * get_author_icon_url (SwYoutubeItemView *youtube, const char *author) { SwYoutubeItemViewPrivate *priv = GET_PRIVATE (youtube); RestProxyCall *call; RestXmlNode *root, *node; char *function, *url; url = g_hash_table_lookup (priv->thumb_map, author); if (url) return g_strdup (url); call = rest_proxy_new_call (priv->proxy); function = g_strdup_printf ("users/%s", author); rest_proxy_call_set_function (call, function); rest_proxy_call_sync (call, NULL); root = xml_node_from_call (call, "Youtube"); if (!root) return NULL; node = rest_xml_node_find (root, "media:thumbnail"); if (!node) return NULL; url = g_strdup (rest_xml_node_get_attr (node, "url")); g_free (function); if (url) g_hash_table_insert(priv->thumb_map, (gpointer)author, (gpointer)g_strdup (url)); return url; }
static void _get_status_updates (SwVimeoItemView *item_view) { SwVimeoItemViewPrivate *priv = GET_PRIVATE (item_view); RestProxyCall *call; sw_call_list_cancel_all (priv->calls); sw_set_empty (priv->set); SW_DEBUG (VIMEO, "Fetching videos"); call = rest_proxy_new_call (priv->proxy); sw_call_list_add (priv->calls, call); if (g_str_equal (priv->query, "feed")) rest_proxy_call_set_function (call, "subscriptions.xml"); else if (g_str_equal (priv->query, "own")) rest_proxy_call_set_function (call, "videos.xml"); else g_assert_not_reached (); rest_proxy_call_async (call, _got_videos_cb, (GObject *)item_view, NULL, NULL); }
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); }
static void stream_test (RestProxy *proxy) { RestProxyCall *call; GError *error; client_count = 1; call = rest_proxy_new_call (proxy); rest_proxy_call_set_function (call, "stream"); if (!rest_proxy_call_continuous (call, _call_continuous_cb, (GObject *)proxy, NULL, &error)) { g_printerr ("Making stream failed: %s", error->message); g_error_free (error); errors++; return; } g_object_unref (call); }
static void online_notify (gboolean online, gpointer user_data) { SwServicePlurk *plurk = (SwServicePlurk *)user_data; SwServicePlurkPrivate *priv = GET_PRIVATE (plurk); priv->credentials = OFFLINE; if (online) { if (priv->username && priv->password) { RestProxyCall *call; call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_function (call, "Users/login"); rest_proxy_call_add_params (call, "api_key", priv->api_key, "username", priv->username, "password", priv->password, NULL); rest_proxy_call_async (call, _got_login_data, (GObject*)plurk, NULL, NULL); } } else { g_free (priv->user_id); priv->user_id = NULL; sw_service_emit_capabilities_changed ((SwService *)plurk, get_dynamic_caps ((SwService *)plurk)); } }
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 _get_updates (SwLastfmContactView *contact_view) { SwLastfmContactViewPrivate *priv = GET_PRIVATE (contact_view); SwService *service; RestProxyCall *call; const gchar *user_id; sw_call_list_cancel_all (priv->calls); sw_set_empty (priv->set); SW_DEBUG (LASTFM, "Making getFriends call"); call = rest_proxy_new_call (priv->proxy); sw_call_list_add (priv->calls, call); service = sw_contact_view_get_service (SW_CONTACT_VIEW (contact_view)); user_id = sw_service_lastfm_get_user_id (SW_SERVICE_LASTFM (service)); if (!user_id) { /* Not yet configured */ return; } rest_proxy_call_add_params (call, "api_key", sw_keystore_get_key ("lastfm"), "user", user_id, "method", "user.getFriends", NULL); rest_proxy_call_async (call, _get_friends_cb, (GObject *)contact_view, NULL, NULL); }
static RestProxyCall* ease_flickr_service_real_create_call (EasePluginImportService* base, RestProxy* proxy, const char* search) { #line 184 "ease-import-flickr-service.c" EaseFlickrService * self; RestProxyCall* result = NULL; char* licenses; RestProxyCall* call; char* _tmp4_; self = (EaseFlickrService*) base; #line 40 "ease-import-flickr-service.vala" g_return_val_if_fail (proxy != NULL, NULL); #line 40 "ease-import-flickr-service.vala" g_return_val_if_fail (search != NULL, NULL); #line 195 "ease-import-flickr-service.c" licenses = NULL; #line 44 "ease-import-flickr-service.vala" if (gtk_toggle_button_get_active ((GtkToggleButton*) self->priv->share_alike)) { #line 199 "ease-import-flickr-service.c" char* _tmp0_; #line 46 "ease-import-flickr-service.vala" licenses = (_tmp0_ = g_strdup (EASE_FLICKR_SERVICE_CC_BY_SA), _g_free0 (licenses), _tmp0_); #line 47 "ease-import-flickr-service.vala" if (!gtk_toggle_button_get_active ((GtkToggleButton*) self->priv->for_commercial)) { #line 205 "ease-import-flickr-service.c" char* _tmp1_; #line 47 "ease-import-flickr-service.vala" licenses = (_tmp1_ = g_strconcat (licenses, EASE_FLICKR_SERVICE_CC_BY_NC_SA, NULL), _g_free0 (licenses), _tmp1_); #line 209 "ease-import-flickr-service.c" } } else { char* _tmp2_; #line 51 "ease-import-flickr-service.vala" licenses = (_tmp2_ = g_strdup (EASE_FLICKR_SERVICE_CC_BY), _g_free0 (licenses), _tmp2_); #line 52 "ease-import-flickr-service.vala" if (!gtk_toggle_button_get_active ((GtkToggleButton*) self->priv->for_commercial)) { #line 217 "ease-import-flickr-service.c" char* _tmp3_; #line 52 "ease-import-flickr-service.vala" licenses = (_tmp3_ = g_strconcat (licenses, EASE_FLICKR_SERVICE_CC_BY_NC, NULL), _g_free0 (licenses), _tmp3_); #line 221 "ease-import-flickr-service.c" } } #line 55 "ease-import-flickr-service.vala" call = rest_proxy_new_call (proxy); #line 56 "ease-import-flickr-service.vala" rest_proxy_call_set_function (call, "flickr.photos.search"); #line 57 "ease-import-flickr-service.vala" rest_proxy_call_add_params (call, "tags", search, "tag_mode", "all", "per_page", "10", "format", "json", "sort", "relevance", "nojsoncallback", "1", "license", _tmp4_ = string_substring (licenses, (glong) 0, string_get_length (licenses) - 1), "extras", "description,license", NULL, NULL); #line 230 "ease-import-flickr-service.c" _g_free0 (_tmp4_); result = call; _g_free0 (licenses); #line 71 "ease-import-flickr-service.vala" return result; #line 236 "ease-import-flickr-service.c" }
static void online_notify (gboolean online, gpointer user_data) { SwServiceTwitter *twitter = (SwServiceTwitter *)user_data; SwServiceTwitterPrivate *priv = twitter->priv; SW_DEBUG (TWITTER, "Online: %s", online ? "yes" : "no"); /* Clear the token and token secret stored inside the proxy */ oauth_proxy_set_token (OAUTH_PROXY (priv->proxy), NULL); oauth_proxy_set_token_secret (OAUTH_PROXY (priv->proxy), NULL); if (online) { if (priv->username && priv->password) { RestProxyCall *call; SW_DEBUG (TWITTER, "Getting token"); /* * Here we use xAuth to transform a username and password into a OAuth * access token. * * http://apiwiki.twitter.com/Twitter-REST-API-Method:-oauth-access_token-for-xAuth */ call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_function (call, "oauth/access_token"); rest_proxy_call_add_params (call, "x_auth_mode", "client_auth", "x_auth_username", priv->username, "x_auth_password", priv->password, NULL); rest_proxy_call_async (call, _oauth_access_token_cb, (GObject*)twitter, NULL, NULL); /* Set offline for now and wait for access_token_cb to return */ priv->credentials = OFFLINE; } else { priv->credentials = OFFLINE; } } else { g_free (priv->user_id); if (priv->twitpic_proxy) { g_object_unref (priv->twitpic_proxy); priv->twitpic_proxy = NULL; } priv->user_id = NULL; priv->credentials = OFFLINE; sw_service_emit_capabilities_changed ((SwService *)twitter, get_dynamic_caps ((SwService *)twitter)); } }
static void got_tokens_cb (RestProxy *proxy, gboolean authorised, gpointer user_data) { SwServiceSina *sina = SW_SERVICE_SINA (user_data); SwServiceSinaPrivate *priv = GET_PRIVATE (sina); RestProxyCall *call; if (authorised) { call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_function (call, "account/verify_credentials.xml"); rest_proxy_call_async (call, got_user_cb, (GObject*)sina, NULL, NULL); } }
static void got_tokens_cb (RestProxy *proxy, gboolean authorised, gpointer user_data) { SwServiceMySpace *myspace = SW_SERVICE_MYSPACE (user_data); SwServiceMySpacePrivate *priv = GET_PRIVATE (myspace); RestProxyCall *call; if (authorised) { call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_function (call, "1.0/people/@me/@self"); rest_proxy_call_async (call, got_user_cb, (GObject*)myspace, NULL, NULL); } }
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 got_tokens_cb (RestProxy *proxy, gboolean authorised, gpointer user_data) { MojitoServiceTwitter *twitter = MOJITO_SERVICE_TWITTER (user_data); MojitoServiceTwitterPrivate *priv = twitter->priv; RestProxyCall *call; if (authorised) { MOJITO_DEBUG (TWITTER, "Authorised"); call = rest_proxy_new_call (priv->proxy); rest_proxy_call_set_function (call, "account/verify_credentials.xml"); rest_proxy_call_async (call, verify_cb, (GObject*)twitter, NULL, NULL); } else { mojito_service_emit_refreshed ((MojitoService *)twitter, NULL); } }
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); }
/** * gfbgraph_new_rest_call: * @authorizer: a #GFBGraphAuthorizer. * * Create a new #RestProxyCall pointing to the Facebook Graph API url (https://graph.facebook.com) * and processed by the authorizer to allow queries. * * Returns: (transfer full): a new #RestProxyCall or %NULL in case of error. **/ RestProxyCall* gfbgraph_new_rest_call (GFBGraphAuthorizer *authorizer) { RestProxy *proxy; RestProxyCall *rest_call; g_return_val_if_fail (GFBGRAPH_IS_AUTHORIZER (authorizer), NULL); proxy = rest_proxy_new (FACEBOOK_ENDPOINT, FALSE); rest_call = rest_proxy_new_call (proxy); gfbgraph_authorizer_process_call (authorizer, rest_call); g_object_unref (proxy); return rest_call; }
static int hello_getattr(const char *path, struct stat *stbuf) { RestProxy *proxy = NULL; RestProxyCall *call = NULL; GError *error = NULL; gchar *url = "http://localhost:3000"; int res = 0; proxy = rest_proxy_new (url, FALSE); call = rest_proxy_new_call (proxy); rest_proxy_call_set_function (call, "s3/info"); rest_proxy_call_add_params (call, "format", "json", "url", path, NULL); if (!rest_proxy_call_sync (call, &error)) { snprintf (buf, 1024, "echo '%s' | tee -a /tmp/dl_fuse", error->message); system (buf); g_error_free (error); res = -ENOENT; return res; } else { snprintf (buf, 1024, "echo '%s' | tee -a /tmp/dl_fuse", rest_proxy_call_get_payload (call)); system (buf); } return res = -ENOENT; memset(stbuf, 0, sizeof(struct stat)); if (strcmp(path, "/") == 0) { stbuf->st_mode = S_IFDIR | 0755; stbuf->st_nlink = 2; } else if (strcmp(path, hello_path) == 0) { stbuf->st_mode = S_IFREG | 0444; stbuf->st_nlink = 1; stbuf->st_size = strlen(hello_str); } else if (strcmp(path, "/dliang") == 0) { stbuf->st_mode = S_IFREG | 0444; stbuf->st_nlink = 1; } else res = -ENOENT; return res; }
static void _get_status_updates (SwYoutubeItemView *item_view) { SwYoutubeItemViewPrivate *priv = GET_PRIVATE (item_view); SwService *service = sw_item_view_get_service ((SwItemView *)item_view); RestProxyCall *call; char *user_auth_header = NULL, *devkey_header = NULL; const char *user_auth = NULL; user_auth = sw_service_youtube_get_user_auth (SW_SERVICE_YOUTUBE (service)); if (user_auth == NULL) return; sw_set_empty (priv->set); call = rest_proxy_new_call (priv->proxy); user_auth_header = g_strdup_printf ("GoogleLogin auth=%s", user_auth); rest_proxy_call_add_header (call, "Authorization", user_auth_header); devkey_header = g_strdup_printf ("key=%s", priv->developer_key); rest_proxy_call_add_header (call, "X-GData-Key", devkey_header); if (g_str_equal (priv->query, "feed")) rest_proxy_call_set_function (call, "users/default/newsubscriptionvideos"); else if (g_str_equal (priv->query, "own")) rest_proxy_call_set_function (call, "users/default/uploads"); else g_assert_not_reached (); rest_proxy_call_add_params (call, "max-results", "10", "alt", "rss", NULL); rest_proxy_call_async (call, _got_videos_cb, (GObject *)item_view, NULL, NULL); g_free (user_auth_header); g_free (devkey_header); }
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 RestProxyCall* ease_oca_service_real_create_call (EasePluginImportService* base, RestProxy* proxy, const char* search) { #line 116 "ease-import-oca-service.c" EaseOCAService * self; RestProxyCall* result = NULL; RestProxyCall* call; self = (EaseOCAService*) base; #line 28 "ease-import-oca-service.vala" g_return_val_if_fail (proxy != NULL, NULL); #line 28 "ease-import-oca-service.vala" g_return_val_if_fail (search != NULL, NULL); #line 31 "ease-import-oca-service.vala" call = rest_proxy_new_call (proxy); #line 32 "ease-import-oca-service.vala" rest_proxy_call_set_function (call, search); #line 129 "ease-import-oca-service.c" result = call; #line 33 "ease-import-oca-service.vala" return result; #line 133 "ease-import-oca-service.c" }
static void _oauth_access_token_cb (RestProxyCall *call, const GError *error, GObject *weak_object, gpointer userdata) { SwService *service = SW_SERVICE (weak_object); SwServiceTwitter *twitter = SW_SERVICE_TWITTER (service); if (error) { sanity_check_date (call); g_message ("Error: %s", error->message); twitter->priv->credentials = CREDS_INVALID; sw_service_emit_capabilities_changed (service, get_dynamic_caps (service)); return; } oauth_proxy_call_parse_token_reponse (OAUTH_PROXY_CALL (call)); SW_DEBUG (TWITTER, "Got OAuth access tokens"); g_object_unref (call); /* Create a TwitPic proxy using OAuth Echo */ twitter->priv->twitpic_proxy = oauth_proxy_new_echo_proxy (OAUTH_PROXY (twitter->priv->proxy), "https://api.twitter.com/1/account/verify_credentials.json", "http://api.twitpic.com/2/", FALSE); /* * Despite the fact we know the credentials are fine, we check them again to * get the user ID and avatar. * * http://apiwiki.twitter.com/Twitter-REST-API-Method:-account verify_credentials */ call = rest_proxy_new_call (twitter->priv->proxy); rest_proxy_call_set_function (call, "1/account/verify_credentials.xml"); rest_proxy_call_async (call, verify_cb, (GObject*)twitter, NULL, NULL); }
static void verify_user (SwService *service) { SwServiceLastfm *lastfm = SW_SERVICE_LASTFM (service); SwServiceLastfmPrivate *priv = lastfm->priv; char *hash_pw, *user_pass, *auth_token; RestProxyCall *call; RestParams *params; GHashTable *params_t; char *api_sig; hash_pw = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->password, -1); user_pass = g_strconcat(priv->username, hash_pw, NULL); auth_token = g_compute_checksum_for_string (G_CHECKSUM_MD5, user_pass, -1); call = rest_proxy_new_call (priv->proxy); rest_proxy_call_add_params (call, "api_key", priv->api_key, "username", priv->username, "authToken", auth_token, "method", "auth.getMobileSession", NULL); params = rest_proxy_call_get_params (call); params_t = rest_params_as_string_hash_table (params); api_sig = build_call_sig (params_t, priv->api_secret); rest_proxy_call_add_params (call, "api_sig", api_sig, NULL); rest_proxy_call_async (call, _mobile_session_cb, (GObject*)lastfm, NULL, NULL); g_hash_table_unref (params_t); g_free (api_sig); g_free (hash_pw); g_free (user_pass); g_free (auth_token); }
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 _get_status_updates (SwTwitterItemView *item_view) { SwTwitterItemViewPrivate *priv = GET_PRIVATE (item_view); RestProxyCall *call; call = rest_proxy_new_call (priv->proxy); if (g_str_equal (priv->query, "own")) rest_proxy_call_set_function (call, "statuses/user_timeline.xml"); else if (g_str_equal (priv->query, "x-twitter-mentions")) rest_proxy_call_set_function (call, "statuses/mentions.xml"); else if (g_str_equal (priv->query, "feed") || g_str_equal (priv->query, "friends-only")) rest_proxy_call_set_function (call, "statuses/friends_timeline.xml"); else if (g_str_equal (priv->query, "x-twitter-trending-topics")) rest_proxy_call_set_function (call, "1/trends/current.json"); else g_error (G_STRLOC ": Unexpected query '%s'", priv->query); if (g_str_equal (priv->query, "x-twitter-trending-topics")) { rest_proxy_call_async (call, _got_trending_topic_updates_cb, (GObject*)item_view, NULL, NULL); } else { rest_proxy_call_async (call, _got_status_updates_cb, (GObject*)item_view, NULL, NULL); } g_object_unref (call); }
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 void get_status_updates (MojitoServiceTwitter *twitter) { MojitoServiceTwitterPrivate *priv = twitter->priv; RestProxyCall *call; if (!priv->user_id || !priv->running) return; MOJITO_DEBUG (TWITTER, "Got status updates"); call = rest_proxy_new_call (priv->proxy); switch (priv->type) { case OWN: rest_proxy_call_set_function (call, "statuses/user_timeline.xml"); break; case FRIENDS: case BOTH: rest_proxy_call_set_function (call, "statuses/friends_timeline.xml"); break; } rest_proxy_call_async (call, tweets_cb, (GObject*)twitter, NULL, NULL); }
int main (int argc, char **argv) { RestProxy *proxy; RestProxyCall *call; GError *error = NULL; char pin[256]; RestXmlParser *parser; RestXmlNode *root, *node; g_type_init (); /* Create the proxy */ proxy = oauth_proxy_new (/* Consumer Key */ "NmUm6hxQ9a4u", /* Consumer Secret */ "t4FM7LiUeD4RBwKSPa6ichKPDh5Jx4kt", /* FireEagle endpoint */ "https://fireeagle.yahooapis.com/", FALSE); /* First stage authentication, this gets a request token. */ if (!oauth_proxy_request_token (OAUTH_PROXY (proxy), "oauth/request_token", "oob", &error)) g_error ("Cannot request token: %s", error->message); /* From the token construct a URL for the user to visit */ g_print ("Go to https://fireeagle.yahoo.net/oauth/authorize?oauth_token=%s then enter the verification code\n", oauth_proxy_get_token (OAUTH_PROXY (proxy))); /* Read the PIN */ fgets (pin, sizeof (pin), stdin); g_strchomp (pin); /* Second stage authentication, this gets an access token. */ if (!oauth_proxy_access_token (OAUTH_PROXY (proxy), "oauth/access_token", pin, &error)) g_error ("Cannot request token: %s", error->message); /* Get the user's current location */ call = rest_proxy_new_call (proxy); rest_proxy_call_set_function (call, "api/0.1/user"); if (!rest_proxy_call_run (call, NULL, &error)) g_error ("Cannot make call: %s", error->message); parser = rest_xml_parser_new (); root = rest_xml_parser_parse_from_data (parser, rest_proxy_call_get_payload (call), rest_proxy_call_get_payload_length (call)); g_object_unref (parser); g_object_unref (call); g_object_unref (proxy); node = rest_xml_node_find (root, "location"); node = rest_xml_node_find (node, "name"); g_print ("%s\n", node->content); return 0; }
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; }