Exemplo n.º 1
0
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 */);
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
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));
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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));
  }
}
Exemplo n.º 6
0
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);
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
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);
}
Exemplo n.º 9
0
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"
}
Exemplo n.º 10
0
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);
}
Exemplo n.º 11
0
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));
  }
}
Exemplo n.º 12
0
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);
  }
}
Exemplo n.º 13
0
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);
  }
}
Exemplo n.º 14
0
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);
}
Exemplo n.º 15
0
Arquivo: twitter.c Projeto: lcp/mojito
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);
}
Exemplo n.º 16
0
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);
}
Exemplo n.º 17
0
Arquivo: twitter.c Projeto: lcp/mojito
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);
  }
}
Exemplo n.º 18
0
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);
}
Exemplo n.º 19
0
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;
}
Exemplo n.º 20
0
Arquivo: twitter.c Projeto: lcp/mojito
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);
}
Exemplo n.º 21
0
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"
}
Exemplo n.º 22
0
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);
}
Exemplo n.º 23
0
Arquivo: twitter.c Projeto: lcp/mojito
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);
}
Exemplo n.º 24
0
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));
  }
}
Exemplo n.º 25
0
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);
}
Exemplo n.º 26
0
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;
}
Exemplo n.º 27
0
static void
_twitpic_upload_photo (SwPhotoUploadIface    *self,
                       const gchar           *filename,
                       GHashTable            *params,
                       DBusGMethodInvocation *context)
{
  SwServiceTwitter *twitter = SW_SERVICE_TWITTER (self);
  SwServiceTwitterPrivate *priv = twitter->priv;
  GError *error = NULL;
  RestProxyCall *call;
  RestParam *param;
  GMappedFile *map;
  char *title, *content_type;
  int opid;

  map = g_mapped_file_new (filename, FALSE, &error);
  if (error) {
    dbus_g_method_return_error (context, error);
    return;
  }

  /* Use the title as the tweet, and if the title isn't specified use the
     filename */
  title = g_hash_table_lookup (params, "title");
  if (title == NULL) {
    title = g_path_get_basename (filename);
  }

  call = rest_proxy_new_call (priv->twitpic_proxy);
  rest_proxy_call_set_function (call, "upload.xml");

  rest_proxy_call_add_params (call,
                              "key", sw_keystore_get_key ("twitpic"),
                              "message", title,
                              NULL);
  g_free (title);

  content_type = g_content_type_guess (filename,
                                       (const guchar*) g_mapped_file_get_contents (map),
                                       g_mapped_file_get_length (map),
                                       NULL);

  param = rest_param_new_with_owner ("media",
                                     g_mapped_file_get_contents (map),
                                     g_mapped_file_get_length (map),
                                     content_type,
                                     filename,
                                     map,
                                     (GDestroyNotify)g_mapped_file_unref);
  rest_proxy_call_add_param_full (call, param);

  g_free (content_type);

  opid = sw_next_opid ();

  rest_proxy_call_upload (call,
                          on_upload_cb,
                          (GObject *)self,
                          GINT_TO_POINTER (opid),
                          NULL);
  sw_photo_upload_iface_return_from_upload_photo (context, opid);
}