This repository has been archived by the owner on May 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJsonRequest.elm
67 lines (56 loc) · 2.06 KB
/
JsonRequest.elm
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
module JsonRequest exposing (defaultRewriteRequest, jsonMatchRequest, jsonRewriteRequest, jsonRewriteRequestDecoder)
import Json.Decode exposing (..)
import Json.Encode exposing (..)
type alias JsonRewriteRequest =
{ source : String
, match : String
, rule : String
, rewrite : String
, language : String
, substitutionKind : String
}
defaultRewriteRequest : JsonRewriteRequest
defaultRewriteRequest =
{ source = ""
, match = ""
, rule = "where true"
, rewrite = ""
, language = ".generic"
, substitutionKind = ""
}
jsonMatchRequest : String -> String -> String -> String -> Int -> String
jsonMatchRequest source match rule language id =
let
value =
Json.Encode.object
[ ( "source", Json.Encode.string source )
, ( "match", Json.Encode.string match )
, ( "rule", Json.Encode.string rule )
, ( "language", Json.Encode.string language )
, ( "id", Json.Encode.int id )
]
in
Json.Encode.encode 0 value
jsonRewriteRequest source match rule rewrite language substitutionKind id =
let
value =
Json.Encode.object
[ ( "source", Json.Encode.string source )
, ( "match", Json.Encode.string match )
, ( "rule", Json.Encode.string rule )
, ( "rewrite", Json.Encode.string rewrite )
, ( "language", Json.Encode.string language )
, ( "substitution_kind", Json.Encode.string substitutionKind )
, ( "id", Json.Encode.int id )
]
in
Json.Encode.encode 0 value
jsonRewriteRequestDecoder : Json.Decode.Decoder JsonRewriteRequest
jsonRewriteRequestDecoder =
Json.Decode.map6 JsonRewriteRequest
(field "source" Json.Decode.string)
(field "match" Json.Decode.string)
(field "rule" Json.Decode.string)
(field "rewrite" Json.Decode.string)
(field "language" Json.Decode.string)
(field "substitution_kind" Json.Decode.string)