-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathTraffic.hs
More file actions
126 lines (106 loc) · 2.91 KB
/
Traffic.hs
File metadata and controls
126 lines (106 loc) · 2.91 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
{-# 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"
instance ToJSON Referrer where
toJSON (Referrer r c u) = object
[ "referrer" .= r
, "count" .= c
, "uniques" .= u
]
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"
instance ToJSON PopularPath where
toJSON (PopularPath p t c u) = object
[ "path" .= p
, "title" .= t
, "count" .= c
, "uniques" .= u
]
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"
instance ToJSON (TrafficCount e) where
toJSON (TrafficCount t c u) = object
[ "timestamp" .= t
, "count" .= c
, "uniques" .= u
]
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"
instance ToJSON Views where
toJSON (Views c u v) = object
[ "count" .= c
, "uniques" .= u
, "views" .= v
]
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"
instance ToJSON Clones where
toJSON (Clones c u cs) = object
[ "count" .= c
, "uniques" .= u
, "clones" .= cs
]