2017-03-08 21:33:55 +03:00
|
|
|
-- Copyright (c) 2016-present, Facebook, Inc.
|
|
|
|
-- All rights reserved.
|
|
|
|
--
|
|
|
|
-- This source code is licensed under the BSD-style license found in the
|
2019-05-22 20:36:43 +03:00
|
|
|
-- LICENSE file in the root directory of this source tree.
|
2017-03-08 21:33:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-# LANGUAGE DeriveAnyClass #-}
|
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
{-# LANGUAGE NoRebindableSyntax #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
|
|
|
|
|
|
module Duckling.Url.Types where
|
|
|
|
|
|
|
|
import Control.DeepSeq
|
|
|
|
import Data.Aeson
|
|
|
|
import Data.Hashable
|
|
|
|
import Data.Maybe
|
|
|
|
import Data.Text (Text)
|
|
|
|
import GHC.Generics
|
|
|
|
import Prelude
|
|
|
|
|
|
|
|
import Duckling.Resolve (Resolve(..))
|
|
|
|
|
|
|
|
data UrlData = UrlData
|
2017-03-14 23:31:44 +03:00
|
|
|
{ value :: Text
|
2017-03-08 21:33:55 +03:00
|
|
|
, domain :: Text
|
|
|
|
}
|
|
|
|
deriving (Eq, Generic, Hashable, Ord, Show, NFData)
|
|
|
|
|
|
|
|
instance Resolve UrlData where
|
2017-03-14 23:31:44 +03:00
|
|
|
type ResolvedValue UrlData = UrlData
|
2018-03-20 00:34:58 +03:00
|
|
|
resolve _ _ x = Just (x, False)
|
2017-03-14 23:31:44 +03:00
|
|
|
|
|
|
|
instance ToJSON UrlData where
|
|
|
|
toJSON (UrlData value domain) = object
|
|
|
|
[ "value" .= value
|
|
|
|
, "domain" .= domain
|
2020-03-19 02:57:04 +03:00
|
|
|
, "type" .= ("value" :: Text)
|
2017-03-14 23:31:44 +03:00
|
|
|
]
|