summaryrefslogtreecommitdiff
path: root/haskell/src/SpaceTraders/APIClient
diff options
context:
space:
mode:
Diffstat (limited to 'haskell/src/SpaceTraders/APIClient')
-rw-r--r--haskell/src/SpaceTraders/APIClient/Ships.hs33
1 files changed, 31 insertions, 2 deletions
diff --git a/haskell/src/SpaceTraders/APIClient/Ships.hs b/haskell/src/SpaceTraders/APIClient/Ships.hs
index e2cf15c..f4b7290 100644
--- a/haskell/src/SpaceTraders/APIClient/Ships.hs
+++ b/haskell/src/SpaceTraders/APIClient/Ships.hs
@@ -3,16 +3,34 @@
{-# LANGUAGE OverloadedStrings #-}
module SpaceTraders.APIClient.Ships
- ( myShips
+ ( dock
+ , myShips
+ , orbit
) where
+import Data.Aeson.Types
+import qualified Data.Text.Encoding as T
+import GHC.Generics
import Network.HTTP.Simple
import SpaceTraders
import SpaceTraders.APIClient.Client
import SpaceTraders.APIClient.Pagination
import SpaceTraders.Database.Ships
-import SpaceTraders.Model.Ship(Ship)
+import SpaceTraders.Model.Nav
+import SpaceTraders.Model.Ship
+
+data NavMessage = NavMessage { nav :: Nav } deriving (FromJSON, Generic, Show)
+dock :: Ship -> SpaceTradersT (APIResponse Ship)
+dock ship = do
+ resp <- send $ setRequestPath (T.encodeUtf8 $ mconcat ["/v2/my/ships/", symbol ship, "/dock"])
+ . setRequestMethod "POST" :: SpaceTradersT (APIResponse NavMessage)
+ case resp of
+ Left e -> return $ Left e
+ Right (NavMessage n) -> do
+ let s = ship{SpaceTraders.Model.Ship.nav=n}
+ updateShip s Nothing
+ return $ Right s
myShips :: SpaceTradersT (APIResponse [Ship])
myShips = do
@@ -28,3 +46,14 @@ myShips = do
if (limit p' * page p' < total p') then listShips' (nextPage p')
else Right <$> getShips
_ -> undefined
+
+orbit :: Ship -> SpaceTradersT (APIResponse Ship)
+orbit ship = do
+ resp <- send $ setRequestPath (T.encodeUtf8 $ mconcat ["/v2/my/ships/", symbol ship, "/orbit"])
+ . setRequestMethod "POST" :: SpaceTradersT (APIResponse NavMessage)
+ case resp of
+ Left e -> return $ Left e
+ Right (NavMessage n) -> do
+ let s = ship{SpaceTraders.Model.Ship.nav=n}
+ updateShip s Nothing
+ return $ Right s