matrix-client 0.1.4.0 → 0.1.4.1
raw patch · 4 files changed
+26/−5 lines, 4 filesdep ~aesonPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependency ranges changed: aeson
API changes (from Hackage documentation)
+ Network.Matrix.Client: loginToken :: LoginCredentials -> IO (ClientSession, MatrixToken)
Files
- CHANGELOG.md +4/−0
- matrix-client.cabal +2/−2
- src/Network/Matrix/Client.hs +7/−2
- src/Network/Matrix/Identity.hs +13/−1
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Changelog +## 0.1.4.1++- Support aeson-2.0+ ## 0.1.4.0 - Completes The Room API
matrix-client.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: matrix-client-version: 0.1.4.0+version: 0.1.4.1 synopsis: A matrix client library description: Matrix client is a library to interface with https://matrix.org.@@ -31,7 +31,7 @@ common common-options build-depends: base >= 4.11.0.0 && < 5 , aeson-casing >= 0.2.0.0 && < 0.3.0.0- , aeson >= 1.0.0.0 && < 1.6+ , aeson >= 1.0.0.0 && < 2.1 ghc-options: -Wall -Wcompat -Widentities
src/Network/Matrix/Client.hs view
@@ -24,6 +24,7 @@ getTokenFromEnv, createSession, login,+ loginToken, logout, -- * API@@ -179,12 +180,16 @@ -- | 'login' allows you to generate a session token. login :: LoginCredentials -> IO ClientSession-login cred = do+login = fmap fst . loginToken ++-- | 'loginToken' allows you to generate a session token and recover the Matrix auth token.+loginToken :: LoginCredentials -> IO (ClientSession, MatrixToken)+loginToken cred = do req <- mkLoginRequest cred manager <- mkManager resp' <- doRequest' manager req case resp' of- Right LoginResponse {..} -> pure $ ClientSession (lBaseUrl cred) (MatrixToken lrAccessToken) manager+ Right LoginResponse {..} -> pure (ClientSession (lBaseUrl cred) (MatrixToken lrAccessToken) manager, (MatrixToken lrAccessToken)) Left err -> -- NOTE: There is nothing to recover after a failed login attempt fail $ show err
src/Network/Matrix/Identity.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} @@ -40,6 +41,9 @@ import Data.ByteString.Lazy (fromStrict) import Data.ByteString.Lazy.Base64.URL (encodeBase64Unpadded) import Data.Digest.Pure.SHA (bytestringDigest, sha256)+#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.KeyMap as KeyMap+#endif import qualified Data.HashMap.Strict as HM import Data.List (lookup) import Data.List.NonEmpty (NonEmpty)@@ -50,6 +54,14 @@ import qualified Network.HTTP.Client as HTTP import Network.Matrix.Internal +#if MIN_VERSION_aeson(2,0,0)+toKVList :: KeyMap.KeyMap v -> [(Text, v)]+toKVList = HM.toList . KeyMap.toHashMapText+#else+toKVList :: HM.HashMap Text v -> [(Text, v)]+toKVList = HM.toList+#endif+ -- $setup -- >>> import Data.Aeson (decode) @@ -123,7 +135,7 @@ parseJSON (Object v) = do mappings <- v .: "mappings" case mappings of- (Object kv) -> pure . IdentityLookupResponse $ mapMaybe toTuple (HM.toList kv)+ (Object kv) -> pure . IdentityLookupResponse $ mapMaybe toTuple (toKVList kv) _ -> mzero where toTuple (k, String s) = Just (HashedAddress k, UserID s)