Finish files before API end functions refactor
parent
305a312b72
commit
c844c94564
|
@ -9,9 +9,11 @@ import Internal.Api.Versions.Main as Versions
|
|||
import Internal.Tools.Exceptions as X
|
||||
import Task exposing (Task)
|
||||
|
||||
|
||||
type alias Future a =
|
||||
Task X.Error a
|
||||
|
||||
|
||||
{-| Get a specific event from the Matrix API.
|
||||
-}
|
||||
getEvent : List String -> Maybe (GetEvent.EventInput -> Future GetEvent.EventOutput)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
module Internal.Api.Helpers exposing (..)
|
||||
|
||||
import Http
|
||||
import Internal.Tools.Exceptions as X
|
||||
import Process
|
||||
import Task exposing (Task)
|
||||
import Http
|
||||
|
||||
|
||||
{-| Sometimes, a URL endpoint might be ratelimited. In such a case,
|
||||
the homeserver tells the SDK to wait for a while and then send its response again.
|
||||
|
@ -37,14 +38,16 @@ ratelimited task =
|
|||
Task.fail e
|
||||
)
|
||||
|
||||
|
||||
{-| Sometimes, you don't really care if something went wrong - you just want to try again.
|
||||
|
||||
This task will only return an error if it went wrong on the n'th attempt.
|
||||
|
||||
-}
|
||||
retryTask : Int -> Task x a -> Task x a
|
||||
retryTask n task =
|
||||
if n <= 0 then
|
||||
task
|
||||
|
||||
else
|
||||
Task.onError (\_ -> retryTask (n - 1) task) task
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import Internal.Tools.Exceptions as X
|
|||
import Internal.Tools.VersionControl as VC
|
||||
import Task exposing (Task)
|
||||
|
||||
|
||||
sendMessageEvent : List String -> Maybe (SendMessageEventInput -> Task X.Error SendMessageEventOutput)
|
||||
sendMessageEvent versions =
|
||||
VC.withBottomLayer
|
||||
|
|
|
@ -5,6 +5,7 @@ import Internal.Tools.Exceptions as X
|
|||
import Internal.Tools.VersionControl as VC
|
||||
import Task exposing (Task)
|
||||
|
||||
|
||||
sendStateKey : List String -> Maybe (SendStateKeyInput -> Task X.Error SendStateKeyOutput)
|
||||
sendStateKey versions =
|
||||
VC.withBottomLayer
|
||||
|
|
|
@ -37,4 +37,4 @@ serverSaysForbidden error =
|
|||
|
||||
unsupportedVersion : String
|
||||
unsupportedVersion =
|
||||
"UNSUPPORTED HOMESERVER: the homeserver only supports Spec versions that this library doesn't support."
|
||||
"UNSUPPORTED HOMESERVER: the homeserver only supports spec versions that this library doesn't support."
|
||||
|
|
|
@ -10,12 +10,14 @@ import Internal.Tools.DecodeExtra exposing (opField)
|
|||
import Json.Decode as D
|
||||
import Json.Encode as E
|
||||
|
||||
|
||||
{-| Errors that may return in any circumstance:
|
||||
|
||||
- `InternetException` Errors that the `elm/http` library might raise.
|
||||
- `SDKException` Errors that this SDK might raise if it doesn't like its own input
|
||||
- `ServerException` Errors that the homeserver might bring
|
||||
- `UnsupportedSpecVersion` This SDK does not support the needed spec versions for certain operations - usually because a homeserver is extremely old.
|
||||
|
||||
-}
|
||||
type Error
|
||||
= InternetException Http.Error
|
||||
|
@ -32,12 +34,14 @@ input.
|
|||
- `CouldntGetTimestamp` The Elm core somehow failed to get the current
|
||||
Unix timestamp.
|
||||
- `NotSupportedYet` Some part of the SDK is intended to be implemented - but it isn't yet.
|
||||
- `NoAccessToken` There is no more access token and no way of getting a new one.
|
||||
|
||||
-}
|
||||
type ClientError
|
||||
= ServerReturnsBadJSON String
|
||||
| CouldntGetTimestamp
|
||||
| NotSupportedYet String
|
||||
| NoAccessToken
|
||||
|
||||
|
||||
{-| Potential error codes that the server may return. If the error is not a
|
||||
|
@ -201,7 +205,7 @@ errorDecoder name code decoder =
|
|||
errorToString : Error -> String
|
||||
errorToString e =
|
||||
case e of
|
||||
UnsupportedVersion ->
|
||||
UnsupportedSpecVersion ->
|
||||
ES.unsupportedVersion
|
||||
|
||||
SDKException (ServerReturnsBadJSON s) ->
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
module Internal.Tools.Timestamp exposing (Timestamp, encodeTimestamp, timestampDecoder)
|
||||
module Internal.Tools.Timestamp exposing (Timestamp, encodeTimestamp, generateTransactionId, timestampDecoder)
|
||||
|
||||
import Json.Decode as D
|
||||
import Json.Encode as E
|
||||
import Task exposing (Task)
|
||||
import Time
|
||||
|
||||
|
||||
|
@ -21,3 +22,13 @@ encodeTimestamp =
|
|||
timestampDecoder : D.Decoder Timestamp
|
||||
timestampDecoder =
|
||||
D.map Time.millisToPosix D.int
|
||||
|
||||
|
||||
{-| Generate a transaction id from the current Unix timestamp
|
||||
-}
|
||||
generateTransactionId : Task x String
|
||||
generateTransactionId =
|
||||
Time.now
|
||||
|> Task.map Time.posixToMillis
|
||||
|> Task.map String.fromInt
|
||||
|> Task.map ((++) "elm")
|
||||
|
|
|
@ -2,6 +2,7 @@ module Internal.Tools.VersionControl exposing
|
|||
( VersionControl, withBottomLayer
|
||||
, MiddleLayer, addMiddleLayer
|
||||
, toDict, fromVersion, fromVersionList
|
||||
, isSupported
|
||||
, mostRecentFromVersionList, sameForVersion
|
||||
)
|
||||
|
||||
|
@ -62,6 +63,11 @@ you prefer to use.
|
|||
|
||||
@docs toDict, fromVersion, mostRecentFromVerionList, fromVersionList
|
||||
|
||||
|
||||
# Checking functions
|
||||
|
||||
@docs isSupported
|
||||
|
||||
-}
|
||||
|
||||
import Dict exposing (Dict)
|
||||
|
@ -138,6 +144,17 @@ fromVersionList versionList vc =
|
|||
versionList
|
||||
|
||||
|
||||
{-| Sometimes, you may not wish to "just" get the info.
|
||||
Sometimes, all you're interested in, is whether a given version is supported.
|
||||
|
||||
In such a case, you can use this function to check whether a given version is supported.
|
||||
|
||||
-}
|
||||
isSupported : String -> VersionControl a b -> Bool
|
||||
isSupported version (VersionControl d) =
|
||||
Dict.member version d.versions
|
||||
|
||||
|
||||
{-| Get a dict of all available functions.
|
||||
-}
|
||||
toDict : VersionControl a b -> Dict String (a -> b)
|
||||
|
|
Loading…
Reference in New Issue