Guest User

Untitled

a guest
Jun 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. %% dispatch.conf
  2. %% {["_env", '*'], wmdemo_resource, []}.
  3.  
  4. -module(wmdemo_resource).
  5. -export([init/1, to_json/2, content_types_provided/2]).
  6.  
  7. -include_lib("webmachine/include/webmachine.hrl").
  8.  
  9. init([]) -> {ok, x}.
  10.  
  11. os_env_list(L) -> os_env_list(L,[]).
  12. os_env_list([],L)-> L;
  13. os_env_list([H|T], L) ->
  14. case os:getenv(H) of
  15. false ->
  16. os_env_list(T,L);
  17. Val ->
  18. D = {H,Val},
  19. A = lists:append([L,[D]]),
  20. os_env_list(T,A)
  21. end.
  22.  
  23. get_vars(Path) ->
  24. string:tokens(string:to_upper(Path),"/").
  25.  
  26. to_json(RD,X) ->
  27. L = os_env_list(get_vars(wrq:path(RD))),
  28. JSON = mochijson:encode({struct, L}),
  29. {JSON, RD, X}.
  30.  
  31. content_types_provided(RD,X) ->
  32. {[{"application/json", to_json},{"text/plain", to_json}], RD, X}.
Add Comment
Please, Sign In to add comment