packages feed

help-esb 0.1.2 → 0.1.3

raw patch · 2 files changed

+31/−9 lines, 2 filesdep +containersdep +network-uri

Dependencies added: containers, network-uri

Files

HelpEsbClient.hs view
@@ -39,9 +39,12 @@ import System.IO import System.Environment import Network.Socket+import Network.URI import Control.Exception import GHC.Generics-import Data.Text hiding (replace)+import Data.Maybe+import Data.Map+import Data.Text hiding (replace, tail, drop, reverse) import Data.List.Utils import Data.UUID import Data.UUID.V4@@ -58,7 +61,7 @@ -- Classes -- | The 'EsbSend' class determines how a message should be sent to the ESB. class EsbSend a where-  -- | The 'esbSend' method takes a socket and writes somekind of payload.+  -- | The 'esbSend' method takes a socket and writes some kind of payload.   esbSend :: Socket -- ^ The socket connection.     -> a -- ^ The payload.     -> IO () -- ^ Any IO output.@@ -66,7 +69,7 @@ -- | The 'EsbRecieve' class determines how a message from the ESB should be -- recieved. class EsbRecieve a where-  -- | The 'esbRecieve' method takes a socket and reads somekind of payload.+  -- | The 'esbRecieve' method takes a socket and reads some kind of payload.   esbRecieve :: Socket -- ^ The socket connection.     -> a -- ^ The payload.     -> IO () -- ^ Any IO output.@@ -180,10 +183,29 @@ -- into the ESB. esbInit :: Text -- ^ Group name.   -> [Text] -- ^ Subscriptions.-  -> String -- ^ Host address.-  -> Int -- ^ Host port.+  -> Maybe String -- ^ Host address or Nothing. Defaults to 127.0.0.1.+  -> Maybe Int -- ^ Host port or Nothing. Defaults to 8900.   -> IO Socket -- ^ The socket connection.-esbInit name subscriptions host port = do+esbInit name subscriptions maybeHost maybePort = do+  let argHost = fromMaybe "Nothing" maybeHost+  let argPort = fromMaybe 0 maybePort++  envVars <- getEnvironment+  let envMap = Data.Map.fromList envVars+  let envUriString = fromMaybe "tcp://127.0.0.1:8900" (Data.Map.lookup "ESB" envMap)++  let envUri = fromMaybe nullURI (parseURI envUriString)++  let defaultUriAuth = URIAuth {+      uriUserInfo = ""+    , uriRegName = "127.0.0.1"+    , uriPort = ":8900"+    }+  let envUriAuth = fromMaybe defaultUriAuth (uriAuthority envUri)++  let host = if argHost /= "Nothing" then argHost else uriRegName envUriAuth+  let port = if argPort /= 0 then argPort else read (tail (uriPort envUriAuth))+   sock <- getSocket host port   let loginData = Login.Request.Data { Login.Request.h_name = name, Login.Request.h_subscriptions = subscriptions }   esbSend sock loginData
help-esb.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                help-esb-version:             0.1.2+version:             0.1.3 synopsis:            A Haskell client for the Help.com team's ESB. description:         A Haskell client for the Help.com team's ESB. homepage:            https://github.com/helpdotcom/help-esb.hs@@ -17,9 +17,9 @@  source-repository head   type: git-  location: git://github.com/helpdotcom/help-esb.hs+  location: git://github.come/helpdotcom/help-esb.hs  library   exposed-modules:     HelpEsbClient, JSON.API.EventGroup.Post.Request, JSON.API.Event.Post.Request, JSON.Login.Request, JSON.Login.Response, JSON.Basic.Request, JSON.Basic.Response   -- other-modules:       -  build-depends:       base ==4.6.*, network ==2.6.*, text ==1.2.*, MissingH ==1.3.*, uuid ==1.3.*, aeson ==0.8.*, bytestring ==0.10.*+  build-depends:       base ==4.*, network ==2.*, network-uri ==2.*, containers ==0.*, text ==1.*, MissingH ==1.*, uuid ==1.*, aeson ==0.*, bytestring ==0.*