module Travis where
import Data.Aeson (decode)
import Network.HTTP.Conduit
import Travis.Types (BuildRaw (..), BuildsRaw (..),
RepoRaw (..), RepositoryRaw (..))
type AccountName = String
type RepositoryName = String
travisAPIBaseURL = "https://api.travis-ci.org/repos/" :: String
requestH = [("Accept", "application/vnd.travis-ci.2+json"),
("User-Agent", "HaskellHTTPConduit/2.1.8")]
fetchRepository :: AccountName -> RepositoryName -> IO (Maybe RepositoryRaw, Maybe [BuildRaw])
fetchRepository acname reponame = do
let coreUrl = travisAPIBaseURL ++ acname ++ "/" ++ reponame
req1 <- parseUrl coreUrl
let request1 = req1 { requestHeaders = requestH}
manager <- newManager conduitManagerSettings
_response1 <- httpLbs request1 manager
let repository = decode (responseBody _response1) :: Maybe RepoRaw
let buildsUrl = coreUrl ++ "/builds"
req2 <- parseUrl buildsUrl
let request2 = req2 { requestHeaders = requestH}
_response2 <- httpLbs request2 manager
let repobuilds = decode (responseBody _response2) :: Maybe BuildsRaw
return (fmap repo repository, fmap builds repobuilds)