PageRenderTime 29ms CodeModel.GetById 17ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/mod_base/services/service_base_persistent_set.erl

https://code.google.com/p/zotonic/
Erlang | 32 lines | 19 code | 8 blank | 5 comment | 0 complexity | ddc0425b7a259a5a3a20bd3caca03e98 MD5 | raw file
 1%% @author Arjan Scherpenisse <arjan@scherpenisse.net>
 2%% @copyright 2009 Arjan Scherpenisse
 3%% Date: 2009-10-03
 4%%
 5%% @doc Set a value in the zotonic visitor record.
 6
 7-module(service_base_persistent_set).
 8-author("Arjan Scherpenisse <arjan@scherpenisse.net>").
 9
10-svc_title("Set a value in the Zotonic persistent record.").
11-svc_needauth(false).
12
13-export([process_get/2]).
14
15-include_lib("zotonic.hrl").
16
17
18process_get(_ReqData, Context) ->
19    case z_context:get_q("key", Context) of
20        X when X =:= undefined orelse X =:= [] ->
21            {error, missing_arg, "key"};
22        Key ->
23            case z_context:get_q("value", Context) of
24                X when X =:= undefined orelse X =:= [] ->
25                    {error, missing_arg, "value"};
26                Value ->
27                    z_context:set_persistent(list_to_atom(Key), Value, Context),
28                    z_convert:to_json([{key, Key}, {value, Value}])
29            end
30    end.
31
32