Skip to content
Browse files

Fixed broken Customer object parsing and bumped Aeson to get better p…

…arse error messages.
  • Loading branch information...
1 parent 3fa49be commit 2a7ad28714d808db288ccc5ca927e13657aa80df @LukeHoersten committed
Showing with 7 additions and 7 deletions.
  1. +4 −4 src/Web/Stripe/Client.hs
  2. +2 −2 src/Web/Stripe/Customer.hs
  3. +1 −1 stripe.cabal
View
8 src/Web/Stripe/Client.hs
@@ -29,7 +29,7 @@ import Control.Monad.Error (Error, ErrorT, MonadError, MonadIO,
import Control.Monad.State (MonadState, StateT, get, runStateT)
import Control.Monad.Trans (liftIO)
import Data.Aeson (FromJSON (..), Value (..), decode',
- (.:), (.:?))
+ eitherDecode', (.:), (.:?))
import Data.Aeson.Types (parseMaybe)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C8
@@ -43,7 +43,7 @@ import Network.HTTP.Types
import Web.Stripe.Utils (textToByteString)
------------------------
--- General Data T\ypes --
+-- General Data Types --
------------------------
-- | Configuration for the 'StripeT' monad transformer.
@@ -208,12 +208,12 @@ query' sReq = do
-- > query baseSReq { sDestination = ["charges"] }
query :: (MonadIO m, FromJSON a) => StripeRequest -> StripeT m (StripeResponseCode, a)
query req = query' req >>= \(code, ans) ->
- maybe (throwError $ strMsg "could not parse JSON") (return . (code, )) $ decode' ans
+ either (throwError . strMsg) (return . (code, )) $ eitherDecode' ans
-- | same as `query` but pulls out the value inside a data field and returns that
queryData :: (MonadIO m, FromJSON a) => StripeRequest -> StripeT m (StripeResponseCode, a)
queryData req = query' req >>= \(code, ans) -> do
- val <- maybe (throwError $ strMsg "could not parse JSON") return $ decode' ans
+ val <- either (throwError . strMsg) return $ eitherDecode' ans
case val of
Object o -> do
objVal <- maybe (throwError $ strMsg "no data in json" ) return $
View
4 src/Web/Stripe/Customer.hs
@@ -39,7 +39,7 @@ import Web.Stripe.Coupon (CpnId (..))
import Web.Stripe.Plan (PlanId (..))
import Web.Stripe.Token (TokenId (..))
import Web.Stripe.Utils (Count (..), Description (..), Offset (..),
- UTCTime (..), optionalArgs,
+ UTCTime (..), fromSeconds, optionalArgs,
showByteString, textToByteString)
----------------
@@ -176,6 +176,6 @@ instance FromJSON Customer where
<*> (Email <$> o .: "email")
<*> (fmap . fmap) Description (o .:? "description")
<*> o .: "livemode"
- <*> o .: "created"
+ <*> (fromSeconds <$> o .: "created")
<*> o .:? "active_card"
parseJSON _ = mzero
View
2 stripe.cabal
@@ -29,7 +29,7 @@ Library
, Web.Stripe.Utils
Build-depends: base >= 3 && < 5
, text == 0.11.*
- , aeson >= 0.6
+ , aeson >= 0.6.1
, unordered-containers >= 0.1.4.6
, time >= 1.0
, http-conduit >= 1.4.1.2

0 comments on commit 2a7ad28

Please sign in to comment.
Something went wrong with that request. Please try again.