pushbullet (empty) → 0.0.0
raw patch · 7 files changed
+181/−0 lines, 7 filesdep +aesondep +basedep +bytestringsetup-changed
Dependencies added: aeson, base, bytestring, hspec, lens, text, unordered-containers, wreq
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- pushbullet.cabal +39/−0
- src/Network/Pushbullet.hs +32/−0
- src/Network/Pushbullet/Internal.hs +10/−0
- src/Network/Pushbullet/Types.hs +67/−0
- test/Spec.hs +1/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Kevin Cotrone++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Kevin Cotrone nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pushbullet.cabal view
@@ -0,0 +1,39 @@+Name: pushbullet+Version: 0.0.0+Author: Kevin Cotrone <kevincotrone@gmail.com>+Maintainer: Kevin Cotrone <kevincotrone@gmail.com>+License: BSD3+License-File: LICENSE+Synopsis: Simple push support for pushbullet+Description: Pushbullet support for sending simple push notifications through pushbullet+Cabal-Version: >= 1.10+Build-Type: Simple++Library+ Default-Language: Haskell2010+ HS-Source-Dirs: src+ GHC-Options: -Wall+ Exposed-Modules: Network.Pushbullet+ , Network.Pushbullet.Types+ Other-Modules: Network.Pushbullet.Internal+ Build-Depends: base >= 4 && < 5+ , lens >= 4.5+ , wreq == 0.5.*+ , aeson+ , text >= 1.0.0.0+ , bytestring+ , unordered-containers++Test-Suite spec+ Type: exitcode-stdio-1.0+ Default-Language: Haskell2010+ Hs-Source-Dirs: src+ , test+ Ghc-Options: -Wall+ Main-Is: Spec.hs+ Build-Depends: base+ , hspec++Source-Repository head+ Type: git+ Location: git@github.com:cotrone/pushbullet.git
+ src/Network/Pushbullet.hs view
@@ -0,0 +1,32 @@+{-# LANGUAGE OverloadedStrings #-}+module Network.Pushbullet (+ sendPush+ , module PBT+)where++import Control.Lens ((&), (?~))+import Data.Aeson+import qualified Data.HashMap.Strict as H+import Data.Monoid+import Network.Pushbullet.Internal+import Network.Pushbullet.Types as PBT+import Network.Wreq++-- | Send a push to a given device+-- if device is+sendPush :: PushSecret -- ^ Access Token for pushbullet+ -> Maybe DeviceId -- ^ Send to a specific device. If Nothing it will broadcast+ -> PushBullet -- ^ Message to push+ -> IO () -- ^ Will eventuall return some sort of error/success+sendPush secret d p = do+ _ <- postWith+ (defaults & auth ?~ (unPushSecret secret))+ "https://api.pushbullet.com/v2/pushes"+ (addDeviceIden d $ toJSON p)+ return ()++addDeviceIden :: Maybe DeviceId -> Value -> Value+addDeviceIden (Just devId) (Object o) =+ Object $+ o <> H.fromList ["device_iden" .= unDeviceId devId]+addDeviceIden _ v = v
+ src/Network/Pushbullet/Internal.hs view
@@ -0,0 +1,10 @@+module Network.Pushbullet.Internal+ (+ PushSecret (..)+ ) where++import Network.Wreq++newtype PushSecret = PushSecret {+ unPushSecret :: Auth+} deriving (Eq, Show)
+ src/Network/Pushbullet/Types.hs view
@@ -0,0 +1,67 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE OverloadedStrings #-}++module Network.Pushbullet.Types(+ Title+ , Body+ , FileName+ , FileType+ , FileUrl+ , DeviceId(..)+ , PushBullet(..)+ , pushSecret+) where++import Control.Applicative+import Control.Monad+import Data.Aeson+import Data.ByteString+import Data.String+import Data.Text+import Network.Pushbullet.Internal+import Network.Wreq++newtype DeviceId = DeviceId {+ unDeviceId :: Text+} deriving (Eq, Show, IsString)++type Title = Text+type Body = Text+type FileName = Text+type FileType = Text+type FileUrl = Text++data PushBullet =+ PushNote Title Body+ -- ^ A note with a title and body+ | PushLink Title Body Text+ -- ^ A link with a message and title+ | PushFile Body FileName FileType FileUrl+ -- ^ A File with a message, name, type, and url++instance ToJSON PushBullet where+ toJSON (PushNote title body) =+ object [+ "type" .= ("note" :: Text)+ , "title" .= title, "body" .= body+ ]+ toJSON (PushLink title body url) =+ object [+ "type" .= ("link" :: Text)+ , "title" .= title+ , "body" .= body+ , "url" .= url+ ]+ toJSON (PushFile body fileName fileType fileUrl) =+ object [+ "type" .= ("file" :: Text)+ , "body" .= body+ , "file_name" .= fileName+ , "file_type" .= fileType+ , "file_url" .= fileUrl+ ]++-- | Generate the PushSecret from a ByteString+pushSecret :: ByteString -- ^ Access Token found in Account Settings+ -> PushSecret+pushSecret = PushSecret . oauth2Bearer
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}