Compare commits

..

No commits in common. "642bab0ba2d73df4e039c68ddba9af81ed3df74b" and "be65a9bfd4362d2184de28349b388bf09abe403d" have entirely different histories.

3 changed files with 6 additions and 36 deletions

View File

@ -7,12 +7,8 @@ to get the needed dependencies.
### Dependencies
This project makes use of the following dependencies (specified in `profun.cabal`):
* http-client (for API requests)
* http-client-tls (for API requests)
* http-conduit (for API requests)
* aeson (JSON parsing)
* http-client
* http-client-tls
* http-conduit
* Chart
* Chart-diagrams
* Chart-diagrams

View File

@ -1,37 +1,12 @@
{-# LANGUAGE OverloadedStrings #-} --needed for ByteString arguments
{-# LANGUAGE OverloadedStrings #-} --needed for string arguments
import Network.HTTP.Simple
import System.Environment (lookupEnv)
import Plot
main :: IO ()
main = do
apiKey <- getWeatherKey
let todayRequest = apiRequestBuilder apiKey "today"
response <- httpJSON todayRequest :: IO (Response ())
generatePlot 20 30 25 --example
putStrLn $ show todayRequest
putStrLn $ show $ getResponseStatusCode response
--apiResponse <- httpJSON "http://httpbin.org/get" :: IO (Response ()) -- specifying type as httpJSON return value is ambigious
apiResponse <- httpLBS "POST http://httpbin.org/get"
putStrLn $ "Status code: " ++ show (getResponseStatusCode apiResponse)
getWeatherKey :: IO String
getWeatherKey = do
result <- lookupEnv "WEATHER_API_KEY"
case result of
Just a -> return a
Nothing -> error "API key not set in environmental variables!" -- exception thrown (but not handled) per project requirement
apiRequestBuilder :: String -> String -> Request
apiRequestBuilder apiKey day =
setRequestHost "api.weatherapi.com"
$ setRequestPath path
$ setRequestMethod "GET"
$ setRequestQueryString [("q", Just "Poznan"), ("key", Just "apiKey")]
$ setRequestPort 443
$ setRequestSecure True
$ defaultRequest
where path
| day == "today" = "/v1/current.json"
| otherwise = "/d"
generatePlot 20 30 25 --example

View File

@ -69,8 +69,7 @@ executable profun
http-client-tls ^>=0.3.6.3,
http-conduit ^>=2.3.8.3,
Chart ^>=1.9.5,
Chart-diagrams ^>=1.9.5,
aeson ^>=2.2.2.0
Chart-diagrams ^>=1.9.5
-- Directories containing source files.
hs-source-dirs: app