Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Rework oauth_params.
  • Loading branch information
Tim Fletcher committed Nov 6, 2008
1 parent 144eef2 commit 9c4973ad9d037d91d6a9a6f52a2318959263495a
Showing 1 changed file with 9 additions and 14 deletions.
@@ -2,25 +2,20 @@

-export([from_string/1, to_string/1, to_header_string/1]).

-import(lists, [map/2]).

from_string(Data) ->
[percent_decode(break_at($=, P)) || P <- string:tokens(Data, "&")].

to_string(Params) when is_list(Params) ->
string:join(map(fun to_string/1, Params), "&");
to_string({K,V}) ->
fmt:sprintf("%s=%s", [fmt:percent_encode(K), fmt:percent_encode(V)]).
to_string(Params) ->
to_string(Params, "%s=%s", "&").

to_header_string(Params) when is_list(Params) ->
string:join(map(fun to_header_string/1, Params), ",");
to_header_string({K,V}) ->
fmt:sprintf("%s=\"%s\"", [fmt:percent_encode(K), fmt:percent_encode(V)]).
to_string(Params, Fmt, Sep) ->
string:join([oauth_util:esprintf(Fmt, Param) || Param <- Params], Sep).

from_string(Data) ->
map(fun param_from_string/1, string:tokens(Data, "&")).
to_header_string(Params) ->
to_string(Params, "%s=\"%s\"", ",").

param_from_string(Data) when is_list(Data) ->
param_from_string(break_at($=, Data));
param_from_string({K, V}) ->
percent_decode({K, V}) ->
{oauth_util:percent_decode(K), oauth_util:percent_decode(V)}.

break_at(Sep, Chars) ->

0 comments on commit 9c4973a

Please sign in to comment.