packages feed

pagarme (empty) → 0.1.0.0

raw patch · 5 files changed

+126/−0 lines, 5 filesdep +aesondep +basedep +bytestringsetup-changed

Dependencies added: aeson, base, bytestring, containers, lens, pagarme, text, wreq

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 Diogo Biazus++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pagarme.cabal view
@@ -0,0 +1,45 @@+-- Initial pagarme.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                pagarme+version:             0.1.0.0+synopsis:            Pagarme API wrapper+description:         Pagarme API wrapper+homepage:            https://github.com/diogob/pagarme_haskell+license:             MIT+license-file:        LICENSE+author:              Diogo Biazus+maintainer:          diogo@biazus.me+-- copyright:           +category:            Web+build-type:          Simple+-- extra-source-files:  +cabal-version:       >=1.10+source-repository head+  type: git+  location: git@github.com:diogob/pagarme_haskell.git++library+  exposed-modules:     +    Network.Pagarme+  -- other-modules:       +  -- other-extensions:    +  build-depends:       base >=4.7 && <4.8+                       , wreq+                       , text+                       , lens+                       , bytestring+                       , aeson+                       , containers+  hs-source-dirs:      src+  default-language:    Haskell2010++-- A convenient executable to test the library getting a single transaction+executable testbin+  hs-source-dirs: testbin+  main-is: Main.hs+  default-language:    Haskell2010+  build-depends:       base >=4.7 && <4.8+                       , pagarme+                       , wreq+                       , text
+ src/Network/Pagarme.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE OverloadedStrings #-}++module Network.Pagarme (baseUrl+                       , withApiKey+                       , getTransactions+                       , byPage+                       , byConfirmedStatus+                       , byStatus+                        ) where++import qualified Data.ByteString.Lazy as BS+import Network.Wreq+import Control.Lens+import qualified Data.Text as T+import Data.Map as Map+import Data.Aeson (Value)+import qualified Data.Aeson.Types as A+type SingleResult = Response A.Object+type ResultSet = Response [A.Object]++baseUrl :: String+baseUrl = "https://api.pagar.me/1/"++getJSON :: A.FromJSON a => Options -> String -> IO (Response a)+getJSON requestOptions path = asJSON =<< getWith requestOptions (baseUrl ++ path)++toText :: Show a => a -> T.Text+toText = T.pack . show++getOne requestOptions path = do +  r <- getJSON requestOptions path :: IO SingleResult+  return $ r ^. responseBody++getAll requestOptions path = do +  r <- getJSON requestOptions path :: IO ResultSet+  return $ r ^. responseBody++byPage pageNumber requestOptions = requestOptions & param "page" .~ [toText pageNumber]+                                                  & param "count" .~ ["100"]++byStatus status requestOptions = requestOptions & param "status" .~ [status]+byConfirmedStatus = byStatus "paid"++withApiKey key requestOptions = requestOptions & param "api_key" .~ [key]++getTransactions requestOptions = getAll requestOptions "transactions"+
+ testbin/Main.hs view
@@ -0,0 +1,12 @@+{-# LANGUAGE OverloadedStrings #-}++module Main where++import Network.Pagarme+import Network.Wreq++main :: IO ()+main = do+  let usingKey = withApiKey "YOUR_API_KEY"+  t <- getTransactions $ (byPage 1 . byConfirmedStatus . usingKey) defaults+  print t