module Rakuten.Client (
AppId
, RakutenClient
, defaultRaktenClient
, Client(..)
) where
import Control.Lens hiding ((:>))
import Data.Default.Class (Default (def))
import Data.Extensible
import Data.Function ((&))
import Data.Text (Text)
import Network.HTTP.Req (Option, Scheme (Https), Url, https, (/:),
(=:))
import Rakuten.Types
type AppId = Text
type RakutenClient =
Record '[
"applicationId" ':> Text,
"affiliateId" ':> Maybe Text,
"callback" ':> Maybe Text,
"elements" ':> [Text]
]
defaultRaktenClient :: AppId -> RakutenClient
defaultRaktenClient appId = def & #applicationId .~ appId
class Client a where
type ClientScheme a :: Scheme
baseUrl :: a -> Url (ClientScheme a)
mkHeader :: a -> Option scheme
instance Client RakutenClient where
type ClientScheme RakutenClient = 'Https
baseUrl = const (https "app.rakuten.co.jp" /: "services" /: "api")
mkHeader = mappend ("format" =: ("json" :: Text)) . toParams