示例#1
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);
}
static gboolean
_prepare (RestProxyCall *call, GError **error)
{
  OAuthProxy *proxy = NULL;
  OAuthProxyPrivate *priv;
  char *s;
  GHashTable *oauth_params;

  g_object_get (call, "proxy", &proxy, NULL);
  priv = PROXY_GET_PRIVATE (proxy);

  /* We have to make this hash free the strings and thus duplicate when we put
   * them in since when we call call steal_oauth_params that has to duplicate
   * the param names since it removes them from the main hash
   */
  oauth_params = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);

  /* First, steal any OAuth properties in the regular params */
  steal_oauth_params (call, oauth_params);

  g_hash_table_insert (oauth_params, g_strdup ("oauth_version"), g_strdup ("1.0"));

  s = g_strdup_printf ("%"G_GINT64_FORMAT , (gint64) time (NULL));
  g_hash_table_insert (oauth_params, g_strdup ("oauth_timestamp"), s);

  s = g_strdup_printf ("%u", g_random_int ());
  g_hash_table_insert (oauth_params, g_strdup ("oauth_nonce"), s);

  g_hash_table_insert (oauth_params, g_strdup ("oauth_consumer_key"),
                       g_strdup (priv->consumer_key));

  if (priv->token)
    g_hash_table_insert (oauth_params, g_strdup ("oauth_token"), g_strdup (priv->token));

  switch (priv->method) {
  case PLAINTEXT:
    g_hash_table_insert (oauth_params, g_strdup ("oauth_signature_method"), g_strdup ("PLAINTEXT"));
    s = sign_plaintext (priv);
    break;
  case HMAC_SHA1:
    g_hash_table_insert (oauth_params, g_strdup ("oauth_signature_method"), g_strdup ("HMAC-SHA1"));
    s = sign_hmac (proxy, call, oauth_params);
    break;
  }
  g_hash_table_insert (oauth_params, g_strdup ("oauth_signature"), s);

  s = make_authorized_header (oauth_params);
  if (priv->oauth_echo) {
    rest_proxy_call_add_header (call, "X-Verify-Credentials-Authorization", s);
    rest_proxy_call_add_param (call, "X-Auth-Service-Provider", priv->service_url);
  } else {
    rest_proxy_call_add_header (call, "Authorization", s);
  }
  g_free (s);
  g_hash_table_destroy (oauth_params);

  g_object_unref (proxy);

  return TRUE;
}
示例#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));
}
void
gfbgraph_simple_authorizer_process_call (GFBGraphAuthorizer *iface, RestProxyCall *call)
{
        GFBGraphSimpleAuthorizerPrivate *priv;

        priv = GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE (GFBGRAPH_SIMPLE_AUTHORIZER (iface));

        g_mutex_lock (&priv->mutex);
        rest_proxy_call_add_param (call, "access_token", priv->access_token);
        g_mutex_unlock (&priv->mutex);
}
void
gfbgraph_goa_authorizer_process_call (GFBGraphAuthorizer *iface, RestProxyCall *call)
{
        GFBGraphGoaAuthorizerPrivate *priv = GFBGRAPH_GOA_AUTHORIZER_GET_PRIVATE (GFBGRAPH_GOA_AUTHORIZER (iface));

        g_mutex_lock (&priv->mutex);

        if (priv->access_token != NULL)
                rest_proxy_call_add_param (call, "access_token", priv->access_token);

        g_mutex_unlock (&priv->mutex);
}
示例#6
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);
}
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;
}