Commit ce800e12 authored by Haye Böhm's avatar Haye Böhm

Fix examples

parent 62e7fb68
Pipeline #15420 failed with stage
in 10 minutes and 2 seconds
......@@ -25,18 +25,21 @@ where
serviceTask = get weatherService >>= viewInformation "Current weather" []
// api.openweathermap.org/data/2.5/weather?q=London,uk
weatherOptions :: OpenWeatherRequest -> WebServiceShareOptions (Either String OpenWeatherResponse)
weatherOptions owr = HttpShareOptions (toRequest owr) fromResp
weatherOptions :: OpenWeatherRequest -> WebServiceShareOptions () (Either String OpenWeatherResponse)
weatherOptions owr = HTTPShareOptions {host = "api.openweathermap.org"
, port = 80
, createRequest = \_. toRequest owr
, fromResponse = \response p. fromResp response}
where
toRequest {OpenWeatherRequest|apiKey, type}
# r = newHTTPRequest
= {HTTPRequest|r & server_name = "api.openweathermap.org", server_port = 80, req_path = "/data/2.5/weather", req_query = query type +++ "&APPID=" +++ apiKey}
fromResp response = case jsonQuery "weather/0" (fromString response.rsp_data) of
Nothing = Right (Left ("Could not select JSON"))
Nothing = Ok (Left ("Could not select JSON"))
(Just selected) = case fromJSON selected of
Nothing = Right (Left ("Could not transform JSON"))
(Just v) = Right (Right v)
Nothing = Ok (Left ("Could not transform JSON"))
(Just v) = Ok (Right v)
query (ByCityName name) = "?q=" +++ name
query (ByCoordinates lat long) = "?lat=" +++ toString lat +++ "&lon=" +++ toString long
......
......@@ -49,7 +49,6 @@ where
, publish "/SDSParallel" (const sdsParallelTest)
, publish "/SDSParallel/remoteleft" (const sdsParallelRemoteLeftTest)
, publish "/SDSParallel/remoteright" (const sdsParallelRemoteRightTest)
, publish "/SDSRemoteService" (const sdsRemoteServiceTest)
, publish "/SDSSelect" (const sdsSelectTest)
, publish "/SDSSelectRemote" (const sdsSelectRemoteTest)
, publish "/all" (\_. viewAll)
......@@ -74,8 +73,6 @@ where
(viewSharedInformation "View value by viewSharedInformation" [] (sdsFocus 1 selectShare)))
@! ()
sdsRemoteServiceTest = get weatherService >>= viewInformation "Current weather" []
sdsParallelRemoteRightTest = ((enterInformation "Enter the value to be SET for SDSParallelRemoteRight" [] >>= \v. set v parallelWithRightRemote)
-&&-
(get parallelWithRightRemote >>= viewInformation "View the value gotten for SDSParallelRemoteRight by GET" []))
......@@ -155,40 +152,4 @@ where
//# getV = get doubleRemote >>= viewInformation "View the value gotten for double remote by GET" []
//# updV = enterInformation "Enter the new value for the number" [] >>= \n. upd (\_. n) doubleRemote >>= viewInformation "Updated value" []
# shaV = updateSharedInformation "Update value by viewSharedInformation" [] doubleRemote
= shaV @! ()
// ======= Definitions required for defining a remote service =======
// TODO: Create HTTP request by focussing the parameter
:: OpenWeatherRequest =
{ apiKey :: String
, type :: OpenWeatherRequestType
}
:: OpenWeatherRequestType = ByCityName String | ByCoordinates Real Real
:: OpenWeatherResponse =
{ id :: Int
, main :: String
, description :: String
, icon :: String }
derive class iTask OpenWeatherResponse
// api.openweathermap.org/data/2.5/weather?q=London,uk
weatherOptions :: OpenWeatherRequest -> WebServiceShareOptions () OpenWeatherResponse ()
weatherOptions owr = HttpShareOptions (toRequest owr) fromResp
where
toRequest {OpenWeatherRequest|apiKey, type}
# r = newHTTPRequest
= {HTTPRequest|r & server_name = "api.openweathermap.org", server_port = 80, req_path = "/data/2.5/weather", req_query = query type +++ "&APPID=" +++ apiKey}
fromResp response = case jsonQuery "weather/0" (fromString response.rsp_data) of
Nothing = Left "Could not select JSON"
(Just selected) = case fromJSON selected of
Nothing = Left "Could not transform JSON"
(Just v) = Right v
query (ByCityName name) = "?q=" +++ name
query (ByCoordinates lat long) = "?lat=" +++ toString lat +++ "&lon=" +++ toString long
weatherService = remoteService (weatherOptions {apiKey = "1160ac287072c67ae44708dee89f9a8b" , type = ByCityName "Nijmegen"})
\ No newline at end of file
= shaV @! ()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment