jonathanscard 0.1 → 0.1.1
raw patch · 3 files changed
+35/−14 lines, 3 filesdep +old-localedep +timePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: old-locale, time
API changes (from Hackage documentation)
+ Web.JonathansCard: data UTCTime :: *
- Web.JonathansCard: Balance :: Double -> Int -> String -> String -> Balance
+ Web.JonathansCard: Balance :: Double -> Int -> Maybe UTCTime -> String -> Balance
- Web.JonathansCard: Change :: Double -> String -> Double -> Change
+ Web.JonathansCard: Change :: Double -> Maybe UTCTime -> Double -> Change
- Web.JonathansCard: balCreated :: Balance -> String
+ Web.JonathansCard: balCreated :: Balance -> Maybe UTCTime
- Web.JonathansCard: chgCreated :: Change -> String
+ Web.JonathansCard: chgCreated :: Change -> Maybe UTCTime
Files
- README.mkd +8/−0
- jonathanscard.cabal +4/−1
- src/Web/JonathansCard.hs +23/−13
README.mkd view
@@ -15,3 +15,11 @@ and then unwrap it from the IO and Either monads to play with `Balance` or `Change`.++# Installaton++While you can install it directly from source, it's probably best to grab the+package from [Hackage](http://hackage.haskell.org/package/jonathanscard) with+`cabal-install`:++ cabal install jonathanscode
jonathanscard.cabal view
@@ -1,5 +1,6 @@ Name: jonathanscard-Version: 0.1+Version: 0.1.1+Homepage: http://rawr.mschade.me/jonathanscard/ Synopsis: An implementation of the Jonathan's Card API. Description: This implements the Jonathan's Card API, as detailed at <http://jonathanstark.com/card/#api>@@ -29,3 +30,5 @@ , json == 0.4.4 , mtl == 2.0.1.* , network == 2.3.*+ , old-locale == 1.0.0.*+ , time == 1.2.0.*
src/Web/JonathansCard.hs view
@@ -7,31 +7,37 @@ , balances , latest , changes++ {- Re-Export -}+ , UTCTime ) where -import Control.Monad ( ap, liftM )-import Text.JSON ( JSON(..), JSObject(..), JSValue(..), Result- , decode, resultToEither, valFromObj- )-import Network.HTTP ( Header(Header), HeaderName(..), Request(Request)- , RequestMethod(GET), getResponseBody, simpleHTTP- , catchIO- )-import Network.URI ( URI(URI), URIAuth(URIAuth) )+import Control.Monad ( ap, liftM ) import Data.ByteString.Char8 ( ByteString, unpack )+import Data.Time.Clock ( UTCTime )+import Data.Time.Format ( parseTime )+import Network.HTTP ( Header(Header), HeaderName(..), Request(Request)+ , RequestMethod(GET), getResponseBody, simpleHTTP+ , catchIO+ )+import Network.URI ( URI(URI), URIAuth(URIAuth) )+import System.Locale ( defaultTimeLocale )+import Text.JSON ( JSON(..), JSObject(..), JSValue(..), Result+ , decode, resultToEither, valFromObj+ ) -- | Represents a Balance on Jonathan's Card data Balance = Balance { balAmount :: Double , balBalanceId :: Int- , balCreated :: String+ , balCreated :: Maybe UTCTime , balMessage :: String } deriving Show -- | Represents the changes over time on Jonathan's Card data Change = Change { chgBalance :: Double- , chgCreated :: String+ , chgCreated :: Maybe UTCTime , chgDelta :: Double } deriving Show @@ -83,11 +89,15 @@ get :: JSON a => JSObject JSValue -> String -> Result a get = flip valFromObj +-- | Attempts to parse a string into a UTCTime.+getTime :: String -> Maybe UTCTime+getTime = parseTime defaultTimeLocale "%Y-%m-%dT%X%z"+ instance JSON Balance where readJSON (JSObject rsp) = do Balance `liftM` (read `liftM` get rsp "amount") `ap` (read `liftM` get rsp "balance_id")- `ap` get rsp "created_at"+ `ap` (getTime `liftM` get rsp "created_at") `ap` get rsp "message" readJSON _ = undefined showJSON = undefined@@ -95,7 +105,7 @@ instance JSON Change where readJSON (JSObject rsp) = do Change `liftM` (read `liftM` get rsp "balance")- `ap` get rsp "created_at"+ `ap` (getTime `liftM` get rsp "created_at") `ap` (read `liftM` get rsp "delta") readJSON _ = undefined showJSON = undefined