1-- Manually write instances. 2{-# LANGUAGE NoImplicitPrelude #-} 3{-# LANGUAGE OverloadedStrings #-} 4{-# LANGUAGE RecordWildCards #-} 5 6{-# OPTIONS_GHC -fno-warn-orphans #-} 7 8module Twitter.Manual 9 ( 10 Metadata(..) 11 , Geo(..) 12 , Story(..) 13 , Result(..) 14 ) where 15 16import Prelude.Compat 17 18import Control.Applicative 19import Data.Semigroup ((<>)) 20import Twitter 21 22import Data.Aeson hiding (Result) 23 24instance ToJSON Metadata where 25 26 toJSON Metadata{..} = object [ 27 "result_type" .= result_type 28 ] 29 30 toEncoding Metadata{..} = pairs $ 31 "result_type" .= result_type 32 33instance FromJSON Metadata where 34 parseJSON (Object v) = Metadata <$> v .: "result_type" 35 parseJSON _ = empty 36 37instance ToJSON Geo where 38 toJSON Geo{..} = object [ 39 "type_" .= type_ 40 , "coordinates" .= coordinates 41 ] 42 43 toEncoding Geo{..} = pairs $ 44 "type_" .= type_ 45 <> "coordinates" .= coordinates 46 47instance FromJSON Geo where 48 parseJSON (Object v) = Geo <$> 49 v .: "type_" 50 <*> v .: "coordinates" 51 parseJSON _ = empty 52 53instance ToJSON Story where 54 toJSON Story{..} = object [ 55 "from_user_id_str" .= from_user_id_str 56 , "profile_image_url" .= profile_image_url 57 , "created_at" .= created_at 58 , "from_user" .= from_user 59 , "id_str" .= id_str 60 , "metadata" .= metadata 61 , "to_user_id" .= to_user_id 62 , "text" .= text 63 , "id" .= id_ 64 , "from_user_id" .= from_user_id 65 , "geo" .= geo 66 , "iso_language_code" .= iso_language_code 67 , "to_user_id_str" .= to_user_id_str 68 , "source" .= source 69 ] 70 71 toEncoding Story{..} = pairs $ 72 "from_user_id_str" .= from_user_id_str 73 <> "profile_image_url" .= profile_image_url 74 <> "created_at" .= created_at 75 <> "from_user" .= from_user 76 <> "id_str" .= id_str 77 <> "metadata" .= metadata 78 <> "to_user_id" .= to_user_id 79 <> "text" .= text 80 <> "id" .= id_ 81 <> "from_user_id" .= from_user_id 82 <> "geo" .= geo 83 <> "iso_language_code" .= iso_language_code 84 <> "to_user_id_str" .= to_user_id_str 85 <> "source" .= source 86 87instance FromJSON Story where 88 parseJSON (Object v) = Story <$> 89 v .: "from_user_id_str" 90 <*> v .: "profile_image_url" 91 <*> v .: "created_at" 92 <*> v .: "from_user" 93 <*> v .: "id_str" 94 <*> v .: "metadata" 95 <*> v .: "to_user_id" 96 <*> v .: "text" 97 <*> v .: "id" 98 <*> v .: "from_user_id" 99 <*> v .: "geo" 100 <*> v .: "iso_language_code" 101 <*> v .: "to_user_id_str" 102 <*> v .: "source" 103 parseJSON _ = empty 104 105instance ToJSON Result where 106 toJSON Result{..} = object [ 107 "results" .= results 108 , "max_id" .= max_id 109 , "since_id" .= since_id 110 , "refresh_url" .= refresh_url 111 , "next_page" .= next_page 112 , "results_per_page" .= results_per_page 113 , "page" .= page 114 , "completed_in" .= completed_in 115 , "since_id_str" .= since_id_str 116 , "max_id_str" .= max_id_str 117 , "query" .= query 118 ] 119 120 toEncoding Result{..} = pairs $ 121 "results" .= results 122 <> "max_id" .= max_id 123 <> "since_id" .= since_id 124 <> "refresh_url" .= refresh_url 125 <> "next_page" .= next_page 126 <> "results_per_page" .= results_per_page 127 <> "page" .= page 128 <> "completed_in" .= completed_in 129 <> "since_id_str" .= since_id_str 130 <> "max_id_str" .= max_id_str 131 <> "query" .= query 132 133instance FromJSON Result where 134 parseJSON (Object v) = Result <$> 135 v .: "results" 136 <*> v .: "max_id" 137 <*> v .: "since_id" 138 <*> v .: "refresh_url" 139 <*> v .: "next_page" 140 <*> v .: "results_per_page" 141 <*> v .: "page" 142 <*> v .: "completed_in" 143 <*> v .: "since_id_str" 144 <*> v .: "max_id_str" 145 <*> v .: "query" 146 parseJSON _ = empty 147