Refactor JoinedMembers API endpoint

pull/1/head
Bram van den Heuvel 2023-02-13 18:05:05 +01:00
parent e8c0345290
commit 293a37c8cd
31 changed files with 25 additions and 769 deletions

View File

@ -17,7 +17,7 @@ getEvent =
{-| Get a list of members who are part of a Matrix room.
-}
joinedMembers : List String -> JoinedMembers.JoinedMembersInput -> JoinedMembers.JoinedMembersOutput
joinedMembers : List String -> Maybe (JoinedMembers.JoinedMembersInput -> JoinedMembers.JoinedMembersOutput)
joinedMembers =
JoinedMembers.joinedMembers

View File

@ -1,8 +1,8 @@
module Internal.Api.JoinedMembers.Api exposing (..)
import Internal.Api.JoinedMembers.V1.SpecObjects as SO1
import Internal.Api.Request as R
import Internal.Tools.Exceptions as X
import Json.Decode as D
import Task exposing (Task)
@ -13,8 +13,12 @@ type alias JoinedMembersInputV1 =
}
joinedMembersInputV1 : D.Decoder a -> (a -> b) -> JoinedMembersInputV1 -> Task X.Error b
joinedMembersInputV1 decoder mapping data =
type alias JoinedMembersOutputV1 =
Task X.Error SO1.RoomMemberList
joinedMembersInputV1 : JoinedMembersInputV1 -> JoinedMembersOutputV1
joinedMembersInputV1 data =
R.rawApiCall
{ headers = R.WithAccessToken data.accessToken
, method = "GET"
@ -26,5 +30,5 @@ joinedMembersInputV1 decoder mapping data =
, queryParams = []
, bodyParams = []
, timeout = Nothing
, decoder = \_ -> D.map mapping decoder
, decoder = \_ -> SO1.roomMemberListDecoder
}

View File

@ -1,23 +1,20 @@
module Internal.Api.JoinedMembers.Main exposing (..)
import Internal.Api.JoinedMembers.Api as Api
import Internal.Api.JoinedMembers.V1_2.Api as V1_2
import Internal.Api.JoinedMembers.V1_3.Api as V1_3
import Internal.Api.JoinedMembers.V1_4.Api as V1_4
import Internal.Api.JoinedMembers.V1_5.Api as V1_5
import Internal.Api.JoinedMembers.V1_5.Objects as O
import Internal.Api.VersionControl as V
import Internal.Tools.Exceptions as X
import Task exposing (Task)
import Internal.Tools.VersionControl as VC
joinedMembers : List String -> JoinedMembersInput -> JoinedMembersOutput
joinedMembers =
V.firstVersion V1_2.packet
|> V.updateWith V1_3.packet
|> V.updateWith V1_4.packet
|> V.updateWith V1_5.packet
|> V.toFunction
joinedMembers : List String -> Maybe (JoinedMembersInput -> JoinedMembersOutput)
joinedMembers versions =
VC.withBottomLayer
{ current = Api.joinedMembersInputV1
, version = "v1.1"
}
|> VC.sameForVersion "v1.2"
|> VC.sameForVersion "v1.3"
|> VC.sameForVersion "v1.4"
|> VC.sameForVersion "v1.5"
|> VC.mostRecentFromVersionList versions
type alias JoinedMembersInput =
@ -25,4 +22,4 @@ type alias JoinedMembersInput =
type alias JoinedMembersOutput =
Task X.Error O.RoomMemberList
Api.JoinedMembersOutputV1

View File

@ -1,4 +1,4 @@
module Internal.Api.JoinedMembers.V1_2.SpecObjects exposing
module Internal.Api.JoinedMembers.V1.SpecObjects exposing
( RoomMember
, RoomMemberList
, encodeRoomMember
@ -9,7 +9,7 @@ module Internal.Api.JoinedMembers.V1_2.SpecObjects exposing
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
Last generated at Unix time 1676307378
-}

View File

@ -1,4 +1,4 @@
version: v1.4
version: v1
name: SpecObjects
objects:
RoomMemberList:

View File

@ -1,17 +0,0 @@
module Internal.Api.JoinedMembers.V1_2.Api exposing (..)
import Internal.Api.JoinedMembers.Api as Api
import Internal.Api.JoinedMembers.V1_2.Convert as C
import Internal.Api.JoinedMembers.V1_2.Objects as O
import Internal.Api.JoinedMembers.V1_2.SpecObjects as SO
import Internal.Api.JoinedMembers.V1_2.Upcast as U
import Internal.Api.VersionControl as V
packet : V.SingleVersion () () Api.JoinedMembersInputV1 O.RoomMemberList
packet =
{ version = "v1.2"
, downcast = \_ -> ()
, current = Api.joinedMembersInputV1 SO.roomMemberListDecoder C.convert
, upcast = U.upcast
}

View File

@ -1,9 +0,0 @@
module Internal.Api.JoinedMembers.V1_2.Convert exposing (..)
import Internal.Api.JoinedMembers.V1_2.Objects as O
import Internal.Api.JoinedMembers.V1_2.SpecObjects as SO
convert : SO.RoomMemberList -> O.RoomMemberList
convert =
identity

View File

@ -1,69 +0,0 @@
module Internal.Api.JoinedMembers.V1_2.Objects exposing
( RoomMember
, RoomMemberList
, encodeRoomMember
, encodeRoomMemberList
, roomMemberDecoder
, roomMemberListDecoder
)
{-| Automatically generated 'Objects'
Last generated at Unix time 1673279712
-}
import Dict exposing (Dict)
import Internal.Tools.DecodeExtra exposing (opField, opFieldWithDefault)
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| User information of joined users.
-}
type alias RoomMember =
{ avatarUrl : Maybe String
, displayName : Maybe String
}
encodeRoomMember : RoomMember -> E.Value
encodeRoomMember data =
maybeObject
[ ( "avatar_url", Maybe.map E.string data.avatarUrl )
, ( "display_name", Maybe.map E.string data.displayName )
]
roomMemberDecoder : D.Decoder RoomMember
roomMemberDecoder =
D.map2
(\a b ->
{ avatarUrl = a, displayName = b }
)
(opField "avatar_url" D.string)
(opField "display_name" D.string)
{-| The dictionary containing all room member data.
-}
type alias RoomMemberList =
{ joined : Dict String RoomMember
}
encodeRoomMemberList : RoomMemberList -> E.Value
encodeRoomMemberList data =
maybeObject
[ ( "joined", Just <| E.dict identity encodeRoomMember data.joined )
]
roomMemberListDecoder : D.Decoder RoomMemberList
roomMemberListDecoder =
D.map
(\a ->
{ joined = a }
)
(opFieldWithDefault "joined" Dict.empty (D.dict roomMemberDecoder))

View File

@ -1,17 +0,0 @@
version: v1.2
name: Objects
objects:
RoomMemberList:
description: The dictionary containing all room member data.
fields:
joined:
type: "{RoomMember}"
required: false
default: Dict.empty
RoomMember:
description: User information of joined users.
fields:
avatar_url:
type: string
display_name:
type: string

View File

@ -1,17 +0,0 @@
version: v1.2
name: SpecObjects
objects:
RoomMemberList:
description: The dictionary containing all room member data.
fields:
joined:
type: "{RoomMember}"
required: false
default: Dict.empty
RoomMember:
description: User information of joined users.
fields:
avatar_url:
type: string
display_name:
type: string

View File

@ -1,9 +0,0 @@
module Internal.Api.JoinedMembers.V1_2.Upcast exposing (..)
import Dict
import Internal.Api.JoinedMembers.V1_2.Objects as O
upcast : () -> O.RoomMemberList
upcast _ =
{ joined = Dict.empty }

View File

@ -1,18 +0,0 @@
module Internal.Api.JoinedMembers.V1_3.Api exposing (..)
import Internal.Api.JoinedMembers.Api as Api
import Internal.Api.JoinedMembers.V1_2.Objects as PO
import Internal.Api.JoinedMembers.V1_3.Convert as C
import Internal.Api.JoinedMembers.V1_3.Objects as O
import Internal.Api.JoinedMembers.V1_3.SpecObjects as SO
import Internal.Api.JoinedMembers.V1_3.Upcast as U
import Internal.Api.VersionControl as V
packet : V.SingleVersion Api.JoinedMembersInputV1 PO.RoomMemberList Api.JoinedMembersInputV1 O.RoomMemberList
packet =
{ version = "v1.3"
, downcast = identity
, current = Api.joinedMembersInputV1 SO.roomMemberListDecoder C.convert
, upcast = U.upcast
}

View File

@ -1,9 +0,0 @@
module Internal.Api.JoinedMembers.V1_3.Convert exposing (..)
import Internal.Api.JoinedMembers.V1_3.Objects as O
import Internal.Api.JoinedMembers.V1_3.SpecObjects as SO
convert : SO.RoomMemberList -> O.RoomMemberList
convert =
identity

View File

@ -1,69 +0,0 @@
module Internal.Api.JoinedMembers.V1_3.Objects exposing
( RoomMember
, RoomMemberList
, encodeRoomMember
, encodeRoomMemberList
, roomMemberDecoder
, roomMemberListDecoder
)
{-| Automatically generated 'Objects'
Last generated at Unix time 1673279712
-}
import Dict exposing (Dict)
import Internal.Tools.DecodeExtra exposing (opField, opFieldWithDefault)
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| User information of joined users.
-}
type alias RoomMember =
{ avatarUrl : Maybe String
, displayName : Maybe String
}
encodeRoomMember : RoomMember -> E.Value
encodeRoomMember data =
maybeObject
[ ( "avatar_url", Maybe.map E.string data.avatarUrl )
, ( "display_name", Maybe.map E.string data.displayName )
]
roomMemberDecoder : D.Decoder RoomMember
roomMemberDecoder =
D.map2
(\a b ->
{ avatarUrl = a, displayName = b }
)
(opField "avatar_url" D.string)
(opField "display_name" D.string)
{-| The dictionary containing all room member data.
-}
type alias RoomMemberList =
{ joined : Dict String RoomMember
}
encodeRoomMemberList : RoomMemberList -> E.Value
encodeRoomMemberList data =
maybeObject
[ ( "joined", Just <| E.dict identity encodeRoomMember data.joined )
]
roomMemberListDecoder : D.Decoder RoomMemberList
roomMemberListDecoder =
D.map
(\a ->
{ joined = a }
)
(opFieldWithDefault "joined" Dict.empty (D.dict roomMemberDecoder))

View File

@ -1,17 +0,0 @@
version: v1.3
name: Objects
objects:
RoomMemberList:
description: The dictionary containing all room member data.
fields:
joined:
type: "{RoomMember}"
required: false
default: Dict.empty
RoomMember:
description: User information of joined users.
fields:
avatar_url:
type: string
display_name:
type: string

View File

@ -1,69 +0,0 @@
module Internal.Api.JoinedMembers.V1_3.SpecObjects exposing
( RoomMember
, RoomMemberList
, encodeRoomMember
, encodeRoomMemberList
, roomMemberDecoder
, roomMemberListDecoder
)
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
-}
import Dict exposing (Dict)
import Internal.Tools.DecodeExtra exposing (opField, opFieldWithDefault)
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| User information of joined users.
-}
type alias RoomMember =
{ avatarUrl : Maybe String
, displayName : Maybe String
}
encodeRoomMember : RoomMember -> E.Value
encodeRoomMember data =
maybeObject
[ ( "avatar_url", Maybe.map E.string data.avatarUrl )
, ( "display_name", Maybe.map E.string data.displayName )
]
roomMemberDecoder : D.Decoder RoomMember
roomMemberDecoder =
D.map2
(\a b ->
{ avatarUrl = a, displayName = b }
)
(opField "avatar_url" D.string)
(opField "display_name" D.string)
{-| The dictionary containing all room member data.
-}
type alias RoomMemberList =
{ joined : Dict String RoomMember
}
encodeRoomMemberList : RoomMemberList -> E.Value
encodeRoomMemberList data =
maybeObject
[ ( "joined", Just <| E.dict identity encodeRoomMember data.joined )
]
roomMemberListDecoder : D.Decoder RoomMemberList
roomMemberListDecoder =
D.map
(\a ->
{ joined = a }
)
(opFieldWithDefault "joined" Dict.empty (D.dict roomMemberDecoder))

View File

@ -1,17 +0,0 @@
version: v1.3
name: SpecObjects
objects:
RoomMemberList:
description: The dictionary containing all room member data.
fields:
joined:
type: "{RoomMember}"
required: false
default: Dict.empty
RoomMember:
description: User information of joined users.
fields:
avatar_url:
type: string
display_name:
type: string

View File

@ -1,9 +0,0 @@
module Internal.Api.JoinedMembers.V1_3.Upcast exposing (..)
import Internal.Api.JoinedMembers.V1_2.Objects as PO
import Internal.Api.JoinedMembers.V1_3.Objects as O
upcast : PO.RoomMemberList -> O.RoomMemberList
upcast =
identity

View File

@ -1,18 +0,0 @@
module Internal.Api.JoinedMembers.V1_4.Api exposing (..)
import Internal.Api.JoinedMembers.Api as Api
import Internal.Api.JoinedMembers.V1_3.Objects as PO
import Internal.Api.JoinedMembers.V1_4.Convert as C
import Internal.Api.JoinedMembers.V1_4.Objects as O
import Internal.Api.JoinedMembers.V1_4.SpecObjects as SO
import Internal.Api.JoinedMembers.V1_4.Upcast as U
import Internal.Api.VersionControl as V
packet : V.SingleVersion Api.JoinedMembersInputV1 PO.RoomMemberList Api.JoinedMembersInputV1 O.RoomMemberList
packet =
{ version = "v1.4"
, downcast = identity
, current = Api.joinedMembersInputV1 SO.roomMemberListDecoder C.convert
, upcast = U.upcast
}

View File

@ -1,9 +0,0 @@
module Internal.Api.JoinedMembers.V1_4.Convert exposing (..)
import Internal.Api.JoinedMembers.V1_4.Objects as O
import Internal.Api.JoinedMembers.V1_4.SpecObjects as SO
convert : SO.RoomMemberList -> O.RoomMemberList
convert =
identity

View File

@ -1,69 +0,0 @@
module Internal.Api.JoinedMembers.V1_4.Objects exposing
( RoomMember
, RoomMemberList
, encodeRoomMember
, encodeRoomMemberList
, roomMemberDecoder
, roomMemberListDecoder
)
{-| Automatically generated 'Objects'
Last generated at Unix time 1673279712
-}
import Dict exposing (Dict)
import Internal.Tools.DecodeExtra exposing (opField, opFieldWithDefault)
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| User information of joined users.
-}
type alias RoomMember =
{ avatarUrl : Maybe String
, displayName : Maybe String
}
encodeRoomMember : RoomMember -> E.Value
encodeRoomMember data =
maybeObject
[ ( "avatar_url", Maybe.map E.string data.avatarUrl )
, ( "display_name", Maybe.map E.string data.displayName )
]
roomMemberDecoder : D.Decoder RoomMember
roomMemberDecoder =
D.map2
(\a b ->
{ avatarUrl = a, displayName = b }
)
(opField "avatar_url" D.string)
(opField "display_name" D.string)
{-| The dictionary containing all room member data.
-}
type alias RoomMemberList =
{ joined : Dict String RoomMember
}
encodeRoomMemberList : RoomMemberList -> E.Value
encodeRoomMemberList data =
maybeObject
[ ( "joined", Just <| E.dict identity encodeRoomMember data.joined )
]
roomMemberListDecoder : D.Decoder RoomMemberList
roomMemberListDecoder =
D.map
(\a ->
{ joined = a }
)
(opFieldWithDefault "joined" Dict.empty (D.dict roomMemberDecoder))

View File

@ -1,17 +0,0 @@
version: v1.4
name: Objects
objects:
RoomMemberList:
description: The dictionary containing all room member data.
fields:
joined:
type: "{RoomMember}"
required: false
default: Dict.empty
RoomMember:
description: User information of joined users.
fields:
avatar_url:
type: string
display_name:
type: string

View File

@ -1,69 +0,0 @@
module Internal.Api.JoinedMembers.V1_4.SpecObjects exposing
( RoomMember
, RoomMemberList
, encodeRoomMember
, encodeRoomMemberList
, roomMemberDecoder
, roomMemberListDecoder
)
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
-}
import Dict exposing (Dict)
import Internal.Tools.DecodeExtra exposing (opField, opFieldWithDefault)
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| User information of joined users.
-}
type alias RoomMember =
{ avatarUrl : Maybe String
, displayName : Maybe String
}
encodeRoomMember : RoomMember -> E.Value
encodeRoomMember data =
maybeObject
[ ( "avatar_url", Maybe.map E.string data.avatarUrl )
, ( "display_name", Maybe.map E.string data.displayName )
]
roomMemberDecoder : D.Decoder RoomMember
roomMemberDecoder =
D.map2
(\a b ->
{ avatarUrl = a, displayName = b }
)
(opField "avatar_url" D.string)
(opField "display_name" D.string)
{-| The dictionary containing all room member data.
-}
type alias RoomMemberList =
{ joined : Dict String RoomMember
}
encodeRoomMemberList : RoomMemberList -> E.Value
encodeRoomMemberList data =
maybeObject
[ ( "joined", Just <| E.dict identity encodeRoomMember data.joined )
]
roomMemberListDecoder : D.Decoder RoomMemberList
roomMemberListDecoder =
D.map
(\a ->
{ joined = a }
)
(opFieldWithDefault "joined" Dict.empty (D.dict roomMemberDecoder))

View File

@ -1,9 +0,0 @@
module Internal.Api.JoinedMembers.V1_4.Upcast exposing (..)
import Internal.Api.JoinedMembers.V1_3.Objects as PO
import Internal.Api.JoinedMembers.V1_4.Objects as O
upcast : PO.RoomMemberList -> O.RoomMemberList
upcast =
identity

View File

@ -1,18 +0,0 @@
module Internal.Api.JoinedMembers.V1_5.Api exposing (..)
import Internal.Api.JoinedMembers.Api as Api
import Internal.Api.JoinedMembers.V1_4.Objects as PO
import Internal.Api.JoinedMembers.V1_5.Convert as C
import Internal.Api.JoinedMembers.V1_5.Objects as O
import Internal.Api.JoinedMembers.V1_5.SpecObjects as SO
import Internal.Api.JoinedMembers.V1_5.Upcast as U
import Internal.Api.VersionControl as V
packet : V.SingleVersion Api.JoinedMembersInputV1 PO.RoomMemberList Api.JoinedMembersInputV1 O.RoomMemberList
packet =
{ version = "v1.5"
, downcast = identity
, current = Api.joinedMembersInputV1 SO.roomMemberListDecoder C.convert
, upcast = U.upcast
}

View File

@ -1,9 +0,0 @@
module Internal.Api.JoinedMembers.V1_5.Convert exposing (..)
import Internal.Api.JoinedMembers.V1_5.Objects as O
import Internal.Api.JoinedMembers.V1_5.SpecObjects as SO
convert : SO.RoomMemberList -> O.RoomMemberList
convert =
identity

View File

@ -1,69 +0,0 @@
module Internal.Api.JoinedMembers.V1_5.Objects exposing
( RoomMember
, RoomMemberList
, encodeRoomMember
, encodeRoomMemberList
, roomMemberDecoder
, roomMemberListDecoder
)
{-| Automatically generated 'Objects'
Last generated at Unix time 1673279712
-}
import Dict exposing (Dict)
import Internal.Tools.DecodeExtra exposing (opField, opFieldWithDefault)
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| User information of joined users.
-}
type alias RoomMember =
{ avatarUrl : Maybe String
, displayName : Maybe String
}
encodeRoomMember : RoomMember -> E.Value
encodeRoomMember data =
maybeObject
[ ( "avatar_url", Maybe.map E.string data.avatarUrl )
, ( "display_name", Maybe.map E.string data.displayName )
]
roomMemberDecoder : D.Decoder RoomMember
roomMemberDecoder =
D.map2
(\a b ->
{ avatarUrl = a, displayName = b }
)
(opField "avatar_url" D.string)
(opField "display_name" D.string)
{-| The dictionary containing all room member data.
-}
type alias RoomMemberList =
{ joined : Dict String RoomMember
}
encodeRoomMemberList : RoomMemberList -> E.Value
encodeRoomMemberList data =
maybeObject
[ ( "joined", Just <| E.dict identity encodeRoomMember data.joined )
]
roomMemberListDecoder : D.Decoder RoomMemberList
roomMemberListDecoder =
D.map
(\a ->
{ joined = a }
)
(opFieldWithDefault "joined" Dict.empty (D.dict roomMemberDecoder))

View File

@ -1,17 +0,0 @@
version: v1.5
name: Objects
objects:
RoomMemberList:
description: The dictionary containing all room member data.
fields:
joined:
type: "{RoomMember}"
required: false
default: Dict.empty
RoomMember:
description: User information of joined users.
fields:
avatar_url:
type: string
display_name:
type: string

View File

@ -1,69 +0,0 @@
module Internal.Api.JoinedMembers.V1_5.SpecObjects exposing
( RoomMember
, RoomMemberList
, encodeRoomMember
, encodeRoomMemberList
, roomMemberDecoder
, roomMemberListDecoder
)
{-| Automatically generated 'SpecObjects'
Last generated at Unix time 1673279712
-}
import Dict exposing (Dict)
import Internal.Tools.DecodeExtra exposing (opField, opFieldWithDefault)
import Internal.Tools.EncodeExtra exposing (maybeObject)
import Json.Decode as D
import Json.Encode as E
{-| User information of joined users.
-}
type alias RoomMember =
{ avatarUrl : Maybe String
, displayName : Maybe String
}
encodeRoomMember : RoomMember -> E.Value
encodeRoomMember data =
maybeObject
[ ( "avatar_url", Maybe.map E.string data.avatarUrl )
, ( "display_name", Maybe.map E.string data.displayName )
]
roomMemberDecoder : D.Decoder RoomMember
roomMemberDecoder =
D.map2
(\a b ->
{ avatarUrl = a, displayName = b }
)
(opField "avatar_url" D.string)
(opField "display_name" D.string)
{-| The dictionary containing all room member data.
-}
type alias RoomMemberList =
{ joined : Dict String RoomMember
}
encodeRoomMemberList : RoomMemberList -> E.Value
encodeRoomMemberList data =
maybeObject
[ ( "joined", Just <| E.dict identity encodeRoomMember data.joined )
]
roomMemberListDecoder : D.Decoder RoomMemberList
roomMemberListDecoder =
D.map
(\a ->
{ joined = a }
)
(opFieldWithDefault "joined" Dict.empty (D.dict roomMemberDecoder))

View File

@ -1,17 +0,0 @@
version: v1.5
name: SpecObjects
objects:
RoomMemberList:
description: The dictionary containing all room member data.
fields:
joined:
type: "{RoomMember}"
required: false
default: Dict.empty
RoomMember:
description: User information of joined users.
fields:
avatar_url:
type: string
display_name:
type: string

View File

@ -1,9 +0,0 @@
module Internal.Api.JoinedMembers.V1_5.Upcast exposing (..)
import Internal.Api.JoinedMembers.V1_4.Objects as PO
import Internal.Api.JoinedMembers.V1_5.Objects as O
upcast : PO.RoomMemberList -> O.RoomMemberList
upcast =
identity