mi/sina/src/Mi/Switch.elm

58 lines
1.1 KiB
Elm
Raw Normal View History

2020-11-10 22:11:05 +00:00
module Mi.Switch exposing (Switch, decoder, frontURL, idURL, listURL, switchURL)
import Iso8601
2020-11-16 15:10:57 +00:00
import Json.Decode exposing (Decoder, field, int, map6, nullable, string)
2020-11-10 22:11:05 +00:00
import Time exposing (Posix)
import Url.Builder as UB
2020-11-10 22:11:05 +00:00
type alias Switch =
{ id : String
, who : String
, started_at : Posix
, ended_at : Maybe Posix
, duration : Maybe Int
2020-11-16 15:10:57 +00:00
, img_url : String
}
decoder : Decoder Switch
decoder =
2020-11-16 15:10:57 +00:00
map6 Switch
(field "id" string)
(field "who" string)
(field "started_at" Iso8601.decoder)
(field "ended_at" (nullable Iso8601.decoder))
(field "duration" (nullable int))
2020-11-16 15:10:57 +00:00
(field "img_url" string)
switchURL : String
switchURL =
UB.absolute
[ "api", "switches", "switch" ]
[]
idURL : String -> String
idURL id =
UB.absolute
2020-11-16 17:35:33 +00:00
[ "api", "switches", id ]
[]
frontURL : String
frontURL =
UB.absolute
2020-11-10 22:11:05 +00:00
[ "api", "switches", "current" ]
[]
listURL : Int -> Int -> String
listURL limit page =
UB.absolute
2020-11-10 22:11:05 +00:00
[ "api", "switches", "" ]
[ UB.int "limit" limit
, UB.int "page" page
2020-11-10 22:11:05 +00:00
]