1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE RecordWildCards #-}
3
4{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
5{-# OPTIONS_GHC -fno-warn-orphans #-}
6
7module Compare.JsonBuilder () where
8
9import Prelude.Compat hiding ((<>))
10
11import Data.Json.Builder
12import Data.Monoid ((<>))
13import Twitter
14
15instance JsObject Metadata where
16    toObject Metadata{..} = row "result_type" result_type
17
18instance Value Metadata where
19    toJson = toJson . toObject
20
21instance JsObject Geo where
22    toObject Geo{..} =
23       row "type_" type_ <>
24       row "coordinates" coordinates
25
26instance Value Geo where
27    toJson = toJson . toObject
28
29instance Value a => Value (Maybe a) where
30    toJson (Just a) = toJson a
31    toJson Nothing  = jsNull
32
33instance JsObject Story where
34  toObject Story{..} =
35    row "from_user_id_str" from_user_id_str <>
36    row "profile_image_url" profile_image_url <>
37    row "created_at" created_at <>
38    row "from_user" from_user <>
39    row "id_str" id_str <>
40    row "metadata" metadata <>
41    row "to_user_id" to_user_id <>
42    row "text" text <>
43    row "id" id_ <>
44    row "from_user_id" from_user_id <>
45    row "geo" geo <>
46    row "iso_language_code" iso_language_code <>
47    row "to_user_id_str" to_user_id_str <>
48    row "source" source
49
50instance Value Story where
51    toJson = toJson . toObject
52
53instance JsObject Result where
54    toObject Result{..} =
55      row "results" results <>
56      row "max_id" max_id <>
57      row "since_id" since_id <>
58      row "refresh_url" refresh_url <>
59      row "next_page" next_page <>
60      row "results_per_page" results_per_page <>
61      row "page" page <>
62      row "completed_in" completed_in <>
63      row "since_id_str" since_id_str <>
64      row "max_id_str" max_id_str <>
65      row "query" query
66
67instance Value Result where
68    toJson = toJson . toObject
69