Commits

Benoit Chesneau  committed c009c59

removve some macros and clean request function to prepare streaming
feature.

  • Participants
  • Parent commits 9f75233

Comments (0)

Files changed (5)

File include/couchbeam.hrl

     refs=dict:new()
 }).
     
--define(USER_AGENT, "couchbeam/0.1").
-
--define(b2l(V), binary_to_list(V)).
--define(l2b(V), list_to_binary(V)).
+-define(USER_AGENT, "couchbeam/0.1").

File src/couchbeam_db.erl

             #server_state{uuids_pid=UuidsPid} = ServerState,
             couchbeam_uuids:next_uuid(UuidsPid);
         Id1 when is_list(Id1) -> Id1;
-        Id1 -> ?b2l(Id1)
+        Id1 -> binary_to_list(Id1)
     end,
     Path = Base ++ "/" ++ DocId,
     Body = couchbeam:json_encode(Doc),

File src/couchbeam_resource.erl

     request(State, "PUT", Path, Headers, Params, Body, Opts).
     
     
-request(State, Method, Path, Headers, Params, Body, Opts) ->
-    Result = do_request(State, Method, Path, Headers, Params, Body, Opts),
-    case Result of
+request(#couchdb_params{host=Host, port=Port, ssl=Ssl, timeout=Timeout}=State,
+        Method, Path, Headers, Params, Body, Opts) ->
+    Path1 = lists:append([Path, 
+            case Params of
+            [] -> [];
+            Props -> "?" ++ encode_query(Props)
+            end]),
+    Headers1 = make_auth(State, Headers),
+    Headers2 = default_header("Content-Type", "application/json", Headers1),
+    
+    case lhttpc:request(Host, Port, Ssl, Path1, Method, Headers2, Body, Timeout, Opts) of
         {ok, {{StatusCode, ReasonPhrase}, _Hdrs, ResponseBody}} ->
             if
                 StatusCode >= 400, StatusCode == 404 ->
                         Method == "HEAD" ->
                             {ok, {StatusCode, ReasonPhrase}};
                         true ->
-                            try couchbeam:json_decode(?b2l(ResponseBody)) of
+                            try couchbeam:json_decode(binary_to_list(ResponseBody)) of
                                 Resp1 -> 
                                     case Resp1 of
                                         {[{<<"ok">>, true}]} -> ok;
                             end
                     end
             end;
-        _ -> Result
+        Else -> Else
     end.  
     
-do_request(#couchdb_params{host=Host, port=Port, ssl=Ssl, timeout=Timeout}=State, 
-        Method, Path, Headers, Params, Body, Opts) ->
-    Path1 = lists:append([Path, 
-            case Params of
-            [] -> [];
-            Props -> "?" ++ encode_query(Props)
-            end]),
-    Headers1 = make_auth(State, Headers),
-    Headers2 = default_header("Content-Type", "application/json", Headers1),
-    Result = lhttpc:request(Host, Port, Ssl, Path1, Method, Headers2, Body, Timeout, Opts),
-    Result.
 
 make_auth(#couchdb_params{username=nil, password=nil}, Headers) ->
     Headers;

File src/couchbeam_server.erl

 %% @doc If database exist in the node returns true    
 is_db(ConnectionId, DbName) ->
     AllDbs = all_dbs(ConnectionId),
-    lists:member(?l2b(DbName), AllDbs).
+    lists:member(list_to_binary(DbName), AllDbs).
 
 %% @spec create_db(ConnectionId::pid(), DbName::string()) -> ok
 %% @doc create a database with DbName

File src/couchbeam_uuids.erl

         [{_, []}] -> new_uuids(C, Base, UuidsTid);
         [{_, [Id2|Uuids]}] ->
             true = ets:insert(UuidsTid, {uuids, Uuids}),
-            ?b2l(Id2)
+            binary_to_list(Id2)
     end,
     {reply, Uuid, State}.
     
                             [{"count", "1000"}], []) of
         {ok, {[{<<"uuids">>, [Id|Uuids1]}]}} -> 
             ets:insert(UuidsTid, {uuids, Uuids1}),
-            ?b2l(Id);
+            binary_to_list(Id);
         {error, Reason} -> Reason
     end,
     Uuid.