Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Remove implode/2; use string:join/2 instead.
  • Loading branch information
Tim Fletcher committed Jun 15, 2008
1 parent ea425f0 commit fb94962935d0932cfdc59dba6e2471af1fe8327c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
@@ -12,7 +12,6 @@

-import(fmt, [sprintf/2, percent_encode/1]).
-import(lists, [map/2]).
-import(oauth_util, [implode/2]).


url(Method, URL, ExtraParams, Consumer, Tokens) ->
@@ -83,19 +82,19 @@ hmac_sha1_key(ConsumerSecret, TokenSecret) ->
sprintf("%s&%s", [percent_encode(ConsumerSecret), percent_encode(TokenSecret)]).

hmac_sha1_base_string(MethodString, URL, Params) ->
implode($&, map(fun fmt:percent_encode/1, [MethodString, URL, hmac_sha1_normalize(Params)])).
string:join(map(fun fmt:percent_encode/1, [MethodString, URL, hmac_sha1_normalize(Params)]), "&").

hmac_sha1_normalize(Params) ->
params_to_string(lists:sort(fun({K,X},{K,Y}) -> X < Y; ({A,_},{B,_}) -> A < B end, Params)).

params_to_string(Params) ->
implode($&, map(fun param_to_string/1, Params)).
string:join(map(fun param_to_string/1, Params), "&").

param_to_string({K,V}) ->
sprintf("%s=%s", [percent_encode(K), percent_encode(V)]).

params_to_header_string(Params) ->
implode($,, map(fun param_to_header_string/1, Params)).
string:join(map(fun param_to_header_string/1, Params), ",").

param_to_header_string({K,V}) ->
sprintf("%s=\"%s\"", [percent_encode(K), percent_encode(V)]).
@@ -23,16 +23,6 @@ unix_epoch() ->
nonce() ->
base64:encode_to_string(crypto:rand_bytes(32)). % cf. ruby-oauth

implode(Sep, Strings) when is_list(Strings) ->
implode(Sep, Strings, []).

implode(_Sep, [], Imploded) ->
lists:flatten(lists:reverse(Imploded));
implode(Sep, [String|Strings], []) ->
implode(Sep, Strings, [String]);
implode(Sep, [String|Strings], Imploded) ->
implode(Sep, Strings, [String,Sep|Imploded]).

percent_decode(Chars) when is_list(Chars) ->
percent_decode(Chars, []).

0 comments on commit fb94962

Please sign in to comment.