コード例 #1
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;
}
コード例 #2
0
ファイル: test.c プロジェクト: initlove/fuse-ocs
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;
}
コード例 #3
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;
}