Exemplo n.º 1
0
static void
cb_user_stream_init (CbUserStream *self)
{
  self->receivers = g_ptr_array_new ();
  self->data = g_string_new (NULL);
  self->restarting = FALSE;
  self->state = STATE_STOPPED;

  if (self->stresstest)
    {
      self->proxy = oauth_proxy_new ("0rvHLdbzRULZd5dz6X1TUA",
                                     "oGrvd6654nWLhzLcJywSW3pltUfkhP4BnraPPVNhHtY",
                                     "https://stream.twitter.com/",
                                     FALSE);
    }
  else
    {
      /* TODO: We should be getting these from the settings */
      self->proxy = oauth_proxy_new ("0rvHLdbzRULZd5dz6X1TUA",
                                     "oGrvd6654nWLhzLcJywSW3pltUfkhP4BnraPPVNhHtY",
                                     "https://userstream.twitter.com/",
                                     FALSE);
    }
  self->proxy_data_set = FALSE;

  self->network_monitor = g_network_monitor_get_default ();
  self->network_available = g_network_monitor_get_network_available (self->network_monitor);
  self->network_changed_id = g_signal_connect (self->network_monitor,
                                               "network-changed",
                                               G_CALLBACK (network_changed_cb), self);

  if (!self->network_available)
    start_network_timeout (self);
}
Exemplo n.º 2
0
static gboolean
sw_service_myspace_initable (GInitable     *initable,
                             GCancellable  *cancellable,
                             GError       **error)
{
  SwServiceMySpace *myspace = SW_SERVICE_MYSPACE (initable);
  SwServiceMySpacePrivate *priv = myspace->priv;
  const char *key = NULL, *secret = NULL;

  if (priv->inited)
    return TRUE;

  sw_keystore_get_key_secret ("myspace", &key, &secret);
  if (key == NULL || secret == NULL) {
    g_set_error_literal (error,
                         SW_SERVICE_ERROR,
                         SW_SERVICE_ERROR_NO_KEYS,
                         "No API key configured");
    return FALSE;
  }
  priv->proxy = oauth_proxy_new (key, secret, "http://api.myspace.com/", FALSE);

  sw_online_add_notify (online_notify, myspace);

  refresh_credentials (myspace);

  priv->inited = TRUE;

  return TRUE;
}
Exemplo n.º 3
0
static gboolean
sw_service_sina_initable (GInitable    *initable,
                          GCancellable *cancellable,
                          GError      **error)
{
  /* Initialize the service and return TRUE if everything is OK.
     Otherwise, return FALSE */
  SwServiceSina *sina = SW_SERVICE_SINA (initable);
  SwServiceSinaPrivate *priv = GET_PRIVATE (sina);
  const char *key = NULL, *secret = NULL;

  if (priv->inited)
    return TRUE;

  sw_keystore_get_key_secret ("sina", &key, &secret);
  if (key == NULL || secret == NULL) {
    g_set_error_literal (error,
                         SW_SERVICE_ERROR,
                         SW_SERVICE_ERROR_NO_KEYS,
                         "No API key configured");
    return FALSE;
  }
  priv->proxy = oauth_proxy_new (key, secret, "http://api.t.sina.com.cn/", FALSE);

  sw_online_add_notify (online_notify, sina);

  refresh_credentials (sina);

  priv->inited = TRUE;

  return TRUE;
}
Exemplo n.º 4
0
static gboolean
sw_service_twitter_initable (GInitable    *initable,
                             GCancellable *cancellable,
                             GError      **error)
{
  SwServiceTwitter *twitter = SW_SERVICE_TWITTER (initable);
  SwServiceTwitterPrivate *priv = twitter->priv;
  const char *key = NULL, *secret = NULL;

  if (priv->inited)
    return TRUE;

  sw_keystore_get_key_secret ("twitter", &key, &secret);

  if (key == NULL || secret == NULL) {
    g_set_error_literal (error,
                         SW_SERVICE_ERROR,
                         SW_SERVICE_ERROR_NO_KEYS,
                         "No API key configured");
    return FALSE;
  }

  priv->credentials = OFFLINE;

  sw_keystore_get_key_secret ("twitter", &key, &secret);
  priv->proxy = oauth_proxy_new (key, secret, "https://api.twitter.com/", FALSE);

  sw_online_add_notify (online_notify, twitter);

  refresh_credentials (twitter);

  priv->inited = TRUE;

  return TRUE;
}
Exemplo n.º 5
0
static gboolean
sw_service_vimeo_initable (GInitable     *initable,
                             GCancellable  *cancellable,
                             GError       **error)
{
  SwServiceVimeo *self = SW_SERVICE_VIMEO (initable);
  SwServiceVimeoPrivate *priv = self->priv;
  const gchar *api_key;
  const gchar *api_secret;

  if (priv->inited)
    return TRUE;

  sw_keystore_get_key_secret ("vimeo", &api_key, &api_secret);

  if (api_key == NULL || api_secret == NULL) {
    g_set_error_literal (error,
                         SW_SERVICE_ERROR,
                         SW_SERVICE_ERROR_NO_KEYS,
                         "No API or secret key configured");
    return FALSE;
  }

  priv->inited = TRUE;

  priv->proxy = oauth_proxy_new (api_key, api_secret, "http://vimeo.com/", FALSE);
  priv->simple_proxy = rest_proxy_new ("http://vimeo.com/api/v2/%s/", TRUE);

  sw_online_add_notify (online_notify, self);
  refresh_credentials (self);

  return TRUE;
}
Exemplo n.º 6
0
Arquivo: twitter.c Projeto: lcp/mojito
static void
online_notify (gboolean online, gpointer user_data)
{
  MojitoServiceTwitter *twitter = (MojitoServiceTwitter *)user_data;
  MojitoServiceTwitterPrivate *priv = twitter->priv;

  MOJITO_DEBUG (TWITTER, "Online: %s", online ? "yes" : "no");

  if (online) {
#if TWITTER_USE_OAUTH
    const char *key = NULL, *secret = NULL;

    mojito_keystore_get_key_secret ("twitter", &key, &secret);
    priv->proxy = oauth_proxy_new (key, secret, "http://twitter.com/", FALSE);
    mojito_keyfob_oauth ((OAuthProxy *)priv->proxy, got_tokens_cb, twitter);
#else
    if (priv->username && priv->password) {
      char *url;
      char *escaped_user;
      char *escaped_password;

      escaped_user = g_uri_escape_string (priv->username,
                                          NULL,
                                          FALSE);
      escaped_password = g_uri_escape_string (priv->password,
                                          NULL,
                                          FALSE);

      url = g_strdup_printf ("https://%s:%[email protected]/",
                             escaped_user, escaped_password);

      g_free (escaped_user);
      g_free (escaped_password);

      priv->proxy = rest_proxy_new (url, FALSE);
      g_free (url);

      got_tokens_cb (priv->proxy, TRUE, twitter);
    } else {
      mojito_service_emit_refreshed ((MojitoService *)twitter, NULL);
    }
#endif
  } else {
    if (priv->proxy) {
      g_object_unref (priv->proxy);
      priv->proxy = NULL;
    }
    g_free (priv->user_id);
    priv->user_id = NULL;

    mojito_service_emit_capabilities_changed ((MojitoService *)twitter, NULL);
  }
}
Exemplo n.º 7
0
static gboolean
account_is_configured ()
{
  RestProxy *proxy;
  gboolean configured = FALSE;
  const char *key = NULL, *secret = NULL;

  sw_keystore_get_key_secret ("myspace", &key, &secret);
  proxy = oauth_proxy_new (key, secret, "http://api.myspace.com/", FALSE);

  configured = sw_keyfob_oauth_sync ((OAuthProxy *)proxy);

  g_object_unref (proxy);

  return configured;
}
Exemplo n.º 8
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;
}