oauth_params.erl 675 B

123456789101112131415161718192021222324252627
  1. -module(oauth_params).
  2. -export([from_string/1, to_string/1, to_header_string/1]).
  3. from_string(Data) ->
  4. [percent_decode(break_at($=, P)) || P <- string:tokens(Data, "&")].
  5. to_string(Params) ->
  6. to_string(Params, "%s=%s", "&").
  7. to_string(Params, Fmt, Sep) ->
  8. string:join([oauth_util:esprintf(Fmt, Param) || Param <- Params], Sep).
  9. to_header_string(Params) ->
  10. to_string(Params, "%s=\"%s\"", ",").
  11. percent_decode({K, V}) ->
  12. {oauth_util:percent_decode(K), oauth_util:percent_decode(V)}.
  13. break_at(Sep, Chars) ->
  14. case lists:splitwith(fun(C) -> C =/= Sep end, Chars) of
  15. Result={_, []} ->
  16. Result;
  17. {Before, [Sep|After]} ->
  18. {Before, After}
  19. end.