anchor.diff:          Error ->
               Error
       end.
  -
  -%% @doc stream an ibrowse request
  -request_stream(Pid, Method, Url) ->
  -    request_stream(Pid, Method, Url, []).
  -request_stream(Pid, Method, Url, Headers) ->
  -    request_stream(Pid, Method, Url, Headers, []).
  -request_stream(Pid, Method, Url, Headers, Body) ->
  -    case ibrowse:send_req(Url, Headers, Method, Body,
  -                          [{stream_to, Pid},
  -                           {response_format, binary}]) of
  -        {ibrowse_req_id, ReqId} ->
  -            {ok, ReqId};
  -        Error ->
  -            Error
  -    end.
  -
  -%% @doc Convert a stats-resource response to an erlang-term server
  -%%      information proplist.
  -erlify_server_info(Props) ->
  -    lists:flatten([ erlify_server_info(K, V) || {K, V} <- Props ]).
  -erlify_server_info(<<"nodename">>, Name) -> {node, Name};
  -erlify_server_info(<<"riak_kv_version">>, Vsn) -> {server_version, Vsn};
  -erlify_server_info(_Ignore, _) -> [].
  
positive.code: 
  -module(bbc).
  
  -include("bbc.hrl").
  
  -export([create/0,
           create/3,
           ip/1,
           port/1,
           ping/1,
           create_bucket/3,
           delete_bucket/3,
           list_buckets/1,
           list_buckets/2
          ]).
  
  %% ===================================================================
  %% Public API
  %% ===================================================================
  
  %% @doc Create a client for connecting to `bucket_bouncer' on the
  %% default port on localhost.
  -spec create() -> bbc().
  create() ->
      create("127.0.0.1", 8090, false).
  
  %% @doc Create a client for connecting to a `bucket_bouncer' node.
  %%
  %%      Connections are made to:
  %%      ```http://IP:Port/[buckets[/<bucket>]])'''
  %%      or
  %%      ```https://IP:Port/[buckets[/<bucket>]])'''
  -spec create(string(), pos_integer(), boolean()) -> bbc().
  create(IP, Port, Ssl) when is_list(IP),
                             is_integer(Port),
                             is_atom(Ssl) ->
      #bbc{ip=IP, port=Port, ssl=Ssl}.
  
  %% @doc Get the IP this client will connect to.
  -spec ip(bbc()) -> string().
  ip(#bbc{ip=IP}) -> IP.
  
  %% @doc Get the Port this client will connect to.
  -spec port(bbc()) -> integer().
  port(#bbc{port=Port}) -> Port.
  
  %% @doc Ping the server by requesting the "/ping" resource.
  -spec ping(bbc()) -> ok | {error, term()}.
  ping(BBC) ->
      Url = ping_url(BBC),
      lager:debug("Ping URL: ~p~n", [Url]),
      case request(get, Url, ["200","204"]) of
          {ok, _Status, _Headers, _Body} ->
  
negative.code:             {error, Error}
      end.
  
  %% ===================================================================
  %% Internal functions
  %% ===================================================================
  
  %% @doc Assemble the root URL for the given client
  -spec root_url(string(), pos_integer(), boolean()) -> [string()].
  root_url(Ip, Port, true) ->
      ["https://", Ip, ":", integer_to_list(Port), "/"];
  root_url(Ip, Port, false) ->
      ["http://", Ip, ":", integer_to_list(Port), "/"].
  
  %% @doc Assemble the URL for the ping resource
  -spec ping_url(string(), pos_integer(), boolean()) -> string().
  ping_url(Ip, Port, Ssl) ->
      lists:flatten([root_url(Ip, Port, Ssl), "ping/"]).
  
  %% @doc Assemble the URL for the stats resource
  -spec stats_url(string(), pos_integer(), boolean()) -> string().
  stats_url(Ip, Port, Ssl) ->
      lists:flatten([root_url(Ip, Port, Ssl), "stats/"]).
  
  %% @doc Assemble the buckets URL
  -spec buckets_url(string(), pos_integer(), boolean()) -> string().
  buckets_url(Ip, Port, Ssl) ->
      lists:flatten([root_url(Ip, Port, Ssl), "/buckets"]).
  
  %% @doc Assemble the URL of a bucket
  -spec bucket_url(string(), pos_integer(), boolean(), binary()) ->
                                 string().
  bucket_url(Ip, Port, Ssl, Bucket) ->
      lists:flatten(
        [root_url(Ip, Port, Ssl),
         "/buckets/",
         binary_to_list(Bucket)
        ]).
  
  %% @doc Assemble the URL for the given bucket and key
  -spec list_buckets_url(string(), pos_integer(), boolean(), binary()) -> string().
  list_buckets_url(Ip, Port, Ssl, Owner) ->
      Query =
          "owner=" ++
          binary_to_list(Owner),
      lists:flatten(
        [root_url(Ip, Port, Ssl),
         "/buckets",
         ["?", mochiweb_util:quote_plus(Query)]
        ]).
  
  %% @doc send an ibrowse request
  request(Method, Url, Expect) ->
  