packages feed

iron-mq 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+81/−67 lines, 4 filesdep ~base

Dependency ranges changed: base

Files

+ CHANGES.md view
@@ -0,0 +1,15 @@+# Changes++## Version 0.1.1.0++### Major++- Rename package from iron-mq-haskell to iron-mq+- Implement `postMessages`, `deleteMessage`, `deleteQueue` `peek` and `touch`functions+- Provide a default constructor for messages++### Minor++ - Prettify iron-mq.cabal+ - Prettify postJSONWithBody function+ - Implement a deleteJSONWith function for making DELETE requests
iron-mq.cabal view
@@ -1,70 +1,23 @@--- Initial iron-mq-haskell.cabal generated by cabal init.  For further --- documentation, see http://haskell.org/cabal/users-guide/---- The name of the package. name:                iron-mq---- The package version.  See the Haskell package versioning policy (PVP) --- for standards guiding when and how versions should be incremented.--- http://www.haskell.org/haskellwiki/Package_versioning_policy--- PVP summary:      +-+------- breaking API changes---                   | | +----- non-breaking API additions---                   | | | +--- code changes with no API change-version:             0.1.0.0---- A short (one-line) description of the package.-synopsis:            A client for IronMQ message queueing service---- A longer description of the package.-description:         A client library for communication with the IronMQ message queueing service---- URL for the project homepage or repository.+version:             0.1.1.0+synopsis:            Iron.IO message queueing client library+description:         A client library for communication with Iron.IO's message queueing service homepage:            https://github.com/arnoblalam/iron_mq_haskell---- The license under which the package is released. license:             GPL-3---- The file containing the license text. license-file:        LICENSE---- The package author(s). author:              Arnob Alam---- An email address to which users can send suggestions, bug reports, and --- patches. maintainer:          arnoblalam@gmail.com---- A copyright notice. -- copyright:           - category:            Network- build-type:          Simple---- Extra files to be distributed with the package, such as examples or a --- README.-extra-source-files: README.md  ---- Constraint on the version of Cabal needed to build this package.+extra-source-files: README.md, CHANGES.md cabal-version:       >=1.10 - library-  -- Modules exported by the library.   exposed-modules:     Network.IronMQ, Network.IronMQ.Types-  -  -- Modules included in this library but not exported.   -- other-modules:       -  -  -- LANGUAGE extensions used by modules in this package.   other-extensions:    OverloadedStrings, DeriveGeneric-  -  -- Other library packages from which modules are imported.-  build-depends:       base >=4.6 && <=4.7 , wreq >=0.3, lens >=4.6, aeson >=0.7, text >=0.11, http-client >=0.4-  -  -- Directories containing source files.+  build-depends:       base >=4.6 && <=4.8 , wreq >=0.3, lens >=4.6, aeson >=0.7, text >=0.11, http-client >=0.4   hs-source-dirs:      src-  -  -- Base language which the package is written in.   default-language:    Haskell2010-  +  ghc-options:         -O2  
src/Network/IronMQ.hs view
@@ -1,5 +1,9 @@ {-# LANGUAGE OverloadedStrings #-}-module Network.IronMQ (module Network.IronMQ, Network.IronMQ.Types.Client(..)) where+module Network.IronMQ (module+        Network.IronMQ, +        Client(..),+        message+        ) where  import Network.Wreq import Network.Wreq.Types (Postable)@@ -53,8 +57,9 @@ postJSONWithBody :: (Postable a, FromJSON b) => Client -> Endpoint -> a -> IO b postJSONWithBody client endpoint body = do     let url = baseurl client `append` endpoint-        postOpts = defaults & header "Authorization" .~-            [encodeUtf8 ("OAuth " `append` token client)]+        postOpts = defaults+                & header "Content-Type" .~ ["application/json"]+                & header "Authorization" .~ [encodeUtf8 ("OAuth " `append` token client)]     response <- asJSON =<< postWith postOpts (unpack url) body     return (response ^. responseBody) @@ -63,7 +68,26 @@ postJSON :: (ToJSON b, FromJSON b) => Client -> Endpoint -> IO b postJSON client endpoint = postJSONWithBody client endpoint emptyBody +{-+deleteJSONWithBody :: (Postable a, FromJSON b) => Client ->Endpoint -> Postable a -> IO b+deleteJSONWithBody client endpoint body = do+        let url = baseurl client `append` endpoint+            deleteOpts = defaults +                & header "Content-Type" .~ ["application/json"] +                & header "Authorization" .~ [encodeUtf8 ("OAuth " `append` token client)]+        response <- asJSON =<< deleteWith deleteOpts (unpack url)+        return (response ^. responseBody)+-} +deleteJSON :: FromJSON a => Client ->Endpoint -> IO a+deleteJSON client endpoint = do+        let url = baseurl client `append` endpoint+            deleteOpts = defaults +                & header "Content-Type" .~ ["application/json"] +                & header "Authorization" .~ [encodeUtf8 ("OAuth " `append` token client)]+        response <- asJSON =<< deleteWith deleteOpts (unpack url)+        return (response ^. responseBody)+ -- * The public API  -- | Get a list of queues available to the client@@ -89,6 +113,7 @@ getMessages :: Client -> QueueName -> IO MessageList getMessages client queueName = getMessages' client queueName Nothing Nothing +-- | Get a message by ID getMessageById :: Client -> QueueName -> ID -> IO Message getMessageById client queueName messageID = getJSON client     ("/queues/" `append` queueName `append` "/messages/" `append` messageID)@@ -99,24 +124,30 @@  -- | Post messages to a queue postMessages :: Client -> QueueName -> [Message] -> IO IronResponse-postMessages client queueName messageList = undefined+postMessages client queueName messages = postJSONWithBody client endpoint body where+        endpoint = "/queues/" `append` queueName `append` "/messages"+        body = toJSON (MessageList {messages = messages}) + -- | Clear all messages from a queue clear :: Client -> QueueName -> IO IronResponse clear client queueName = postJSON client ("/queues/" `append` queueName  `append` "/clear") -{- -- | Delete a queue deleteQueue :: Client -> QueueName -> IO IronResponse-deleteQueue client queueName = undefined+deleteQueue client queueName = deleteJSON client endpoint where+        endpoint = "/queues/" `append` queueName  -- | Delete a message from a queue deleteMessage :: Client -> QueueName -> ID -> IO IronResponse-deleteMessage client queueName messageID = undefined+deleteMessage client queueName messageID = deleteJSON client endpoint where+        endpoint = "/queues/" `append` queueName `append` "/messages/" `append` messageID +{- -- | Delete several messages from a queue deleteMessages :: Client -> QueueName -> [ID] -> IO IronResponse-deleteMessages client queueName meessageIDs = undefined+deleteMessages client queueName meessageIDs = deleteJSON client endpoint+-}  -- | Delete the message push status of a message deleteMessagePushStatus :: Client -> QueueName -> ID -> IO IronResponse@@ -134,22 +165,33 @@ deleteSubscribers client queueName subscribers = undefined  -- | Take a look at the next item on the queue-peek :: Client -> QueueName -> IO IronResponse-peek client queueName = undefined+peek' :: Client -> QueueName -> Maybe Int -> IO MessageList+peek' client queueName max = getJSONWithOpts client endpoint opts where+        opts = case max of+                Nothing -> []+                Just x -> [("n", pack (show x))]+        endpoint = "/queues/" `append` queueName `append` "/messages/peek" +peek :: Client -> QueueName -> IO MessageList+peek client queueName = peek' client queueName Nothing+ -- | Touch a message on the queue touch :: Client -> QueueName -> ID -> IO IronResponse-touch client queueName messageID = undefined+touch client queueName messageID = postJSON client endpoint where+        endpoint = "/queues/" `append` queueName `append` "/messages/" `append` pack (show messageID) `append` "/touch" --- | Update a+-- | Update a queues subscribers+update :: Client -> QueueName -> [Subscriber] -> IO IronResponse update client queueName subscribers = undefined  -- | Add alerts to a queue+addAlerts :: Client -> QueueName -> [Alert] -> IO IronResponse addAlerts client queueName alerts = undefined  -- | Update alerts on a queue+updateAlerts :: Client -> QueueName -> [Alert] -> IO IronResponse updateAlerts client queueName alerts = undefined  -- | Add subscribers to a queue-addSubsrubers client queueName subscribers = undefined--}+addSubscribers :: Client -> QueueName -> [Subscriber] -> IO IronResponse+addSubscribers client queueName subscribers = undefined
src/Network/IronMQ/Types.hs view
@@ -100,6 +100,10 @@         mReservedCount :: Maybe Int } deriving (Show) +-- | A default constructor for message+message :: Message+message = Message Nothing "" Nothing Nothing+ instance FromJSON Message where         parseJSON (Object v) = Message <$>                 v .:? "id" <*>