Skip to content
Browse files

API change: the Story and Iteration data structure store its datetime…

…s as TimeWithZone instead of String now. This is a newtype wrapper around UTCTime that handles Rails's default stringification for a TimeWithZone.
  • Loading branch information...
1 parent c8377e4 commit ae344c1814610544c76e5ec208a3777a85a8d73f @mike-burns committed Dec 28, 2011
Showing with 20 additions and 5 deletions.
  1. +11 −1 Trajectory/API.hs
  2. +8 −4 Trajectory/Types.hs
  3. +1 −0 trajectory.cabal
View
12 Trajectory/API.hs
@@ -10,7 +10,7 @@ module Trajectory.API (
import Data.Data
import Data.Aeson
-import Control.Applicative ( (<$>), (<*>) )
+import Control.Applicative ( (<$>), (<*>), pure )
import Data.List (intercalate)
import Data.Attoparsec.ByteString.Lazy
@@ -21,6 +21,9 @@ import Network.HTTP.Enumerator
import Text.URI
import qualified Control.Exception as E
import Data.Maybe (fromMaybe)
+import Data.Time (parseTime)
+import System.Locale (defaultTimeLocale)
+import qualified Data.Text as T (unpack)
import Trajectory.Types
@@ -107,6 +110,13 @@ instance FromJSON Stories where
Stories <$> o .: "stories" <*> o .: "iterations"
parseJSON _ = fail "Could not build Stories"
+instance FromJSON TimeWithZone where
+ parseJSON (String t) =
+ case parseTime defaultTimeLocale "%FT%T%Z" (T.unpack t) of
+ Just d -> pure $ TimeWithZone d
+ _ -> fail "could not parse a Rails default datetime"
+ parseJSON _ = fail "Given something besides a String to parse into a datetime"
+
buildUrl :: [String] -> String
buildUrl paths = "https://www.apptrajectory.com/api/" ++ intercalate "/" paths
View
12 Trajectory/Types.hs
@@ -3,6 +3,7 @@ module Trajectory.Types where
import Control.Exception (IOException)
import Data.Data (Typeable, Data)
+import Data.Time.Clock (UTCTime(..))
-- | Errors have been tagged according to their source, so you can more easily
-- dispatch and handle them.
@@ -13,12 +14,15 @@ data Error =
| UserError String -- ^ Incorrect input.
deriving (Show, Eq)
+-- | A time type representing Rails' TimeWithZone as its default string.
+newtype TimeWithZone = TimeWithZone UTCTime deriving (Show, Eq, Typeable, Data)
+
-- | A Trajectory story.
data Story = Story {
storyArchived :: Bool
,storyAssigneeId :: Maybe Int
,storyBranch :: Maybe String
- ,storyCreatedAt :: String
+ ,storyCreatedAt :: TimeWithZone
,storyDeleted :: Bool
,storyDesignNeeded :: Bool
,storyDevelopmentNeeded :: Bool
@@ -30,7 +34,7 @@ data Story = Story {
,storyState :: String
,storyTaskType :: String
,storyTitle :: String
- ,storyUpdatedAt :: String
+ ,storyUpdatedAt :: TimeWithZone
,storyUserId :: Int
,storyCommentsCount :: Int
,storyAssigneeName :: Maybe String
@@ -45,14 +49,14 @@ data Story = Story {
data Iteration = Iteration {
iterationAcceptedPoints :: Int
,iterationIsComplete :: Bool
- ,iterationCreatedAt :: String
+ ,iterationCreatedAt :: TimeWithZone
,iterationEstimatedPoints :: Int
,iterationEstimatedVelocity :: Int
,iterationId :: Int
,iterationStartsOn :: String
,iterationStoriesCount :: Int
,iterationTeamStrength :: Int
- ,iterationUpdatedAt :: String
+ ,iterationUpdatedAt :: TimeWithZone
,iterationPercentComplete :: Int
,iterationIsCurrent :: Bool
,iterationUnstartedStoriesCount :: Int
View
1 trajectory.cabal
@@ -129,6 +129,7 @@ Library
,http-enumerator == 0.7.2.1
,uri
,http-types
+ ,time
-- Modules not exported by this package.
-- Other-modules:

0 comments on commit ae344c1

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