elm-package.json
file at this tag.Tag | 7.0.0 |
Committed At | 2021-03-22 16:08:39 UTC |
Decoders and a few other helpers for using Twitch.tv APIs.
Partial coverage of the APIs I have used.
Most modules provide decoders for a specific api request. Notable exceptions include:
Twitch.Helix
- generic types and decodersTwitch.Helix.Request
- HTTP request helperTwitch.Kraken.Request
- HTTP request helperTwitch.Template
- template url helpersDecoder modules provide stock decoders for each field in an api response. These decoders are usually trivial, and can be easily replaced if you want to decode as a different type. Most of them are of the form.
id : Decoder UserId
id = (field "id" Helix.userId)
The library provides:
Notably, video durations are of the form "1h22m33s", and the Twitch.Helix.Video.duration
decoder returns it as milliseconds.
Most ids are numbers as strings; the library uses an aliased string with a custom name for documentation purposes, but treats the ids as opaque tokens.
import Twitch.Helix.User as User
import Json.Decode exposing (..)
users : Decoder (List User)
users = User.response user
user : Decoder User
user =
map3 User
User.id
User.login
User.displayName
fetchUserByNameUrl : String -> String
fetchUserByNameUrl login =
"https://api.twitch.tv/helix/users?login=" ++ login
fetchUserByName : String -> String -> Cmd Msg
fetchUserByName auth login =
Twitch.Helix.send <|
{ clientId = TwitchId.clientId -- your id
-- I keep mine in a separate module
-- so it can be excluded from version control
, auth = auth
, decoder = users -- your function, see above
, tagger = User
, url = (fetchUserByNameUrl login)
}