File: jsontest.erl

package info (click to toggle)
yaws 2.0.8%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,084 kB
  • sloc: erlang: 42,190; sh: 2,543; javascript: 1,459; ansic: 890; makefile: 878; lisp: 79; python: 34; xml: 12; php: 1
file content (28 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-module(jsontest).
-export([out/1, handler/3]).

out(Arg) ->
    yaws_rpc:handler_session(Arg, {?MODULE, handler}).

handler(_State, {call, subtract, Params}, _Session) ->
    {Minuend, Subtrahend} = case Params of
                                {array, [M, S]} ->
                                    {M, S};
                                Obj ->
                                    {jsonrpc:s(Obj, "minuend"),
                                     jsonrpc:s(Obj, "subtrahend")}
                            end,
    {true, undefined, undefined, {response, Minuend - Subtrahend}};
handler(_State, {notification, update, {array, [1,2,3,4,5]}}, _Session) ->
    false;
handler(_State, {notification, foobar, undefined}, _Session) ->
    false;
handler(_State, {call, sum, {array, Params}}, _Session) ->
    {true, undefined, undefined, {response, lists:sum(Params)}};
handler(_State, {notification, "notify_hello", {array, [7]}}, _Session) ->
    false;
handler(_State, {call, get_data, undefined}, _Session) ->
    {true, undefined, undefined, {response, {array, ["hello", 5]}}}.