Skip to content

Instantly share code, notes, and snippets.

@drewr
Created January 12, 2018 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewr/025bd7bf1cb9403a44462ce665bc9060 to your computer and use it in GitHub Desktop.
Save drewr/025bd7bf1cb9403a44462ce665bc9060 to your computer and use it in GitHub Desktop.
{
"name": "maybenothing",
"license": "Apache-2.0",
"ignore": [
"**/.*",
"bower_components",
"node_modules",
"output",
"test",
"tmp",
"bower.json",
"gulpfile.js",
"package.json"
],
"dependencies": {
"purescript-yargs": "^3.1.0",
"purescript-console": "^3.0.0",
"purescript-debug": "^3.0.0",
"purescript-affjax": "^5.0.0",
"purescript-config": "^0.0.6"
},
"devDependencies": {
"purescript-psci-support": "^3.0.0"
}
}
module PagerDuty (main) where
import Prelude
import Control.Monad.Aff (launchAff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
import Data.Config (Config, string)
import Data.Config.Node (fromEnv)
import Data.Either (Either(..))
import Data.Array
import Data.Foldable
import Data.HTTP.Method (Method(..))
import Data.MediaType (MediaType(..))
import Debug.Trace
import Network.HTTP.Affjax (AJAX, affjax, defaultRequest)
import Network.HTTP.RequestHeader (RequestHeader(..))
import Node.Process as Process
import Node.Process (PROCESS)
import Data.Set (Set)
type PagerDutyConfig =
{ token :: String
}
url :: String
url = "https://api.pagerduty.com/schedules?query=infra"
pdMedia :: MediaType
pdMedia = MediaType "application/vnd.pagerduty+json;version=2"
main :: forall eff. Eff ( console :: CONSOLE
, process :: PROCESS
, ajax :: AJAX
| eff ) Unit
main = do
conf <- getPdConfig
_ <- case conf of
Left a -> do
log "error with environment"
Process.exit 1
Right { token } -> do
launchAff $ do
res <- affjax $ defaultRequest { url = url
, method = Left GET
, headers = [ ContentType pdMedia
, makeAuth token
]}
liftEff $ log $ "res: " <> res.response
log "done"
makeAuth :: String -> RequestHeader
makeAuth tok = RequestHeader "Authorization" ("Token token=" <> tok)
pdConfig :: Config { name :: String } PagerDutyConfig
pdConfig =
{ token: _ } <$> string { name: "token" }
getPdConfig :: forall eff.
Eff (process :: PROCESS | eff) (Either (Set String) PagerDutyConfig)
getPdConfig = fromEnv "PAGERDUTY" pdConfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment