-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathTraffic.hs
More file actions
90 lines (75 loc) · 2.13 KB
/
Traffic.hs
File metadata and controls
90 lines (75 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
-- | Data types used in the traffic API
module GitHub.Data.Traffic where
import Data.Text (Text)
import Data.Time (UTCTime)
import Data.Vector (Vector)
import GitHub.Data.Name (Name)
import GitHub.Internal.Prelude
import Prelude ()
data Referrer = Referrer
{ referrer :: !(Name Referrer)
, referrerCount :: !Int
, referrerUniques :: !Int
}
deriving (Eq, Show, Generic)
instance FromJSON Referrer where
parseJSON = withObject "Referrer" $ \o -> Referrer
<$> o .: "referrer"
<*> o .: "count"
<*> o .: "uniques"
data PopularPath = PopularPath
{ popularPath :: !Text
, popularPathTitle :: !Text
, popularPathCount :: !Int
, popularPathUniques :: !Int
}
deriving (Eq, Show)
instance FromJSON PopularPath where
parseJSON = withObject "Path" $ \o -> PopularPath
<$> o .: "path"
<*> o .: "title"
<*> o .: "count"
<*> o .: "uniques"
data Period =
Day
| Week
deriving (Eq, Show)
data TrafficEvent
= View
| Clone
deriving (Eq, Show)
data TrafficCount (e :: TrafficEvent) = TrafficCount
{ trafficCountTimestamp :: !UTCTime
, trafficCount :: !Int
, trafficCountUniques :: !Int
}
deriving (Eq, Show)
instance FromJSON (TrafficCount e) where
parseJSON = withObject "TrafficCount" $ \o -> TrafficCount
<$> o .: "timestamp"
<*> o .: "count"
<*> o .: "uniques"
data Views = Views
{ viewsCount :: !Int
, viewsUniques :: !Int
, views :: !(Vector (TrafficCount 'View))
}
deriving (Eq, Show)
instance FromJSON Views where
parseJSON = withObject "Views" $ \o -> Views
<$> o .: "count"
<*> o .: "uniques"
<*> o .: "views"
data Clones = Clones
{ clonesCount :: !Int
, clonesUniques :: !Int
, clones :: !(Vector (TrafficCount 'Clone))
}
deriving (Eq, Show)
instance FromJSON Clones where
parseJSON = withObject "Clones" $ \o -> Clones
<$> o .: "count"
<*> o .: "uniques"
<*> o .: "clones"