tesla 0.1.0.0 → 0.1.0.1
raw patch · 3 files changed
+23/−3 lines, 3 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Tesla.Car: instance GHC.Classes.Eq Tesla.Car.BadCarException
+ Tesla.Car: instance GHC.Exception.Type.Exception Tesla.Car.BadCarException
+ Tesla.Car: instance GHC.Show.Show Tesla.Car.BadCarException
Files
- ChangeLog.md +5/−0
- src/Tesla/Car.hs +16/−1
- tesla.cabal +2/−2
ChangeLog.md view
@@ -1,3 +1,8 @@ # Changelog for tesla +# Release 0.1.0.1++A more informative exception is thrown from `runNamedCar` when an+unknown car name is given.+ ## Unreleased changes
src/Tesla/Car.hs view
@@ -32,6 +32,7 @@ vehicleURL, authInfo, vehicleID ) where +import Control.Exception (Exception, throwIO) import Control.Lens import Control.Monad ((<=<)) import Control.Monad.IO.Class (MonadIO (..))@@ -83,12 +84,26 @@ runCar :: MonadIO m => IO AuthInfo -> VehicleID -> Car m a -> m a runCar ai vi f = runReaderT f (CarEnv ai vi) +newtype BadCarException = BadCar String deriving Eq++instance Show BadCarException where+ show (BadCar s) = "BadCar: " <> s++instance Exception BadCarException+ -- | Run a Car Monad by looking up a car by name. runNamedCar :: MonadIO m => Text -> IO AuthInfo -> Car m a -> m a runNamedCar name ai f = do a <- liftIO ai vs <- vehicles a- runCar ai (vs Map.! name) f+ c <- case Map.lookup name vs of+ Nothing -> throw $ mconcat [show name, " is not a valid vehicle name. Try one of: ",+ show $ Map.keys vs]+ Just c -> pure c+ runCar ai c f++ where+ throw = liftIO . throwIO . BadCar -- | Giant blob of VehicleData describing all known state of the vehicle. --
tesla.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 8cdeecd446c907e59d314404de69be9fd58fd7e9276d2d0e1b34f4f222b77c1f+-- hash: bc86432b798b84de1d75a14ba3e27975fe6c0c2431111c061bfcd48bdf851848 name: tesla-version: 0.1.0.0+version: 0.1.0.1 synopsis: Tesla API client. description: Please see the README on GitHub at <https://github.com/dustin/tesla#readme> category: Web