smsaero 0.6.2 → 0.7
raw patch · 5 files changed
+43/−67 lines, 5 filesdep ~servant
Dependency ranges changed: servant
Files
- CHANGELOG.md +5/−0
- smsaero.cabal +2/−2
- src/SMSAero/API.hs +12/−3
- src/SMSAero/Client.hs +14/−59
- src/SMSAero/Types.hs +10/−3
CHANGELOG.md view
@@ -1,3 +1,8 @@+0.7+---+* Add support for `aeson-1`;+* Switch to `servant-0.9`.+ 0.6.2 --- * Get rid of `SmsAeroJson` (they have finally fixed their `Content-Type`!). See [5a7539e](https://github.com/GetShopTV/smsaero/commit/5a7539edff7f274d39c58ce02f19bcb14bbc05b5).
smsaero.cabal view
@@ -1,5 +1,5 @@ name: smsaero-version: 0.6.2+version: 0.7 synopsis: SMSAero API and HTTP client based on servant library. description: Please see README.md homepage: https://github.com/GetShopTV/smsaero@@ -26,7 +26,7 @@ SMSAero.Client SMSAero.Types build-depends: base >= 4.7 && < 5- , servant >= 0.7.1+ , servant >= 0.9 , servant-client , servant-docs , http-api-data >= 0.2.3
src/SMSAero/API.hs view
@@ -1,4 +1,5 @@ {-# OPTIONS -fno-warn-orphans #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-}@@ -57,13 +58,10 @@ import qualified Data.Text as Text import Data.Map (Map)-import qualified Data.Map as Map -import Data.Maybe (catMaybes) import Text.Read (readEither) import Control.Applicative-import Control.Arrow ((***)) import GHC.TypeLits (Symbol, KnownSymbol) import Servant.API@@ -77,6 +75,13 @@ import SMSAero.Types +#if MIN_VERSION_aeson(1,0,0)+#else+import Data.Maybe (catMaybes)+import Control.Arrow ((***))+import qualified Data.Map as Map+#endif+ -- | Like 'QueryParam', but always required. data RequiredQueryParam (sym :: Symbol) a @@ -411,6 +416,9 @@ instance ToJSON SignResponse where toJSON s = object [ "accepted" .= toUrlPiece s ] +#if MIN_VERSION_aeson(1,0,0)+#else+ instance ToJSON CheckSendingResponse where toJSON = toJSON . Map.mapKeys toQueryParam . fmap toQueryParam @@ -420,3 +428,4 @@ where dist (x, y) = (,) <$> x <*> y +#endif
src/SMSAero/Client.hs view
@@ -43,8 +43,6 @@ import SMSAero.API import SMSAero.Types -import Network.HTTP.Client (Manager)- -- | SMSAero client. smsAeroClient :: Client SMSAeroAPI smsAeroClient = client (Proxy :: Proxy SMSAeroAPI)@@ -64,9 +62,7 @@ -> Maybe SMSAeroDate -- ^ Date stating when to send a postponed message. -> Maybe SendType -- ^ Send channel description. -> Maybe DigitalChannel -- ^ Use digital send channel.- -> Manager -- ^ Connection manager. -> SmsAero SendResponse-smsAeroSend auth p m s md mt mdig manager = smsAeroSend_ auth p m s md mt mdig manager defaultBaseUrl -- | Send a group message. smsAeroSendToGroup :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password).@@ -76,67 +72,47 @@ -> Maybe SMSAeroDate -- ^ Date stating when to send a postponed message. -> Maybe SendType -- ^ Send channel description. -> Maybe DigitalChannel -- ^ Use digital send channel.- -> Manager -- ^ Connection manager. -> SmsAero SendResponse-smsAeroSendToGroup auth g m s md mt mdig manager = smsAeroSendToGroup_ auth g m s md mt mdig manager defaultBaseUrl -- | Check status of a previously sent message. smsAeroStatus :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password). -> MessageId -- ^ Message ID.- -> Manager -- ^ Connection manager. -> SmsAero MessageStatus-smsAeroStatus auth mid manager = smsAeroStatus_ auth mid manager defaultBaseUrl -- | Check status of a broadcast. smsAeroCheckSending :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password). -> MessageId -- ^ Broadcast ID.- -> Manager -- ^ Connection manager. -> SmsAero CheckSendingResponse-smsAeroCheckSending auth mid manager = smsAeroCheckSending_ auth mid manager defaultBaseUrl -- | Check balance. smsAeroBalance :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password).- -> Manager -- ^ Connection manager. -> SmsAero BalanceResponse-smsAeroBalance auth manager = smsAeroBalance_ auth manager defaultBaseUrl -- | Check tariff. smsAeroCheckTariff :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password).- -> Manager -- ^ Connection manager. -> SmsAero CheckTariffResponse-smsAeroCheckTariff auth manager = smsAeroCheckTariff_ auth manager defaultBaseUrl -- | Check the list of available sender signatures. smsAeroSenders :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password).- -> Manager -- ^ Connection manager. -> SmsAero SendersResponse-smsAeroSenders auth manager = smsAeroSenders_ auth manager defaultBaseUrl -- | Acquire a new signature. smsAeroSign :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password).- -> Manager -- ^ Connection manager. -> SmsAero SignResponse-smsAeroSign auth manager = smsAeroSign_ auth manager defaultBaseUrl -- | Get groups list (corresponds to 'checkgroup' endpoint). smsAeroListGroups :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password).- -> Manager -- ^ Connection manager. -> SmsAero [Group]-smsAeroListGroups auth manager = smsAeroListGroups_ auth manager defaultBaseUrl -- | Add a group. smsAeroAddGroup :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password). -> Group -- ^ Name for the new group.- -> Manager -- ^ Connection manager. -> SmsAero GroupResponse-smsAeroAddGroup auth g manager = smsAeroAddGroup_ auth g manager defaultBaseUrl -- | Delete a group. smsAeroDeleteGroup :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password). -> Group -- ^ Name of the group to be deleted.- -> Manager -- ^ Connection manager. -> SmsAero GroupResponse-smsAeroDeleteGroup auth g manager = smsAeroDeleteGroup_ auth g manager defaultBaseUrl -- | Add a phone to contact list or group. smsAeroAddPhone :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password).@@ -147,52 +123,31 @@ -> Maybe Name -- ^ Subscriber's middle name. -> Maybe BirthDate -- ^ Subscriber's birth date. -> Maybe Text -- ^ Any additional information.- -> Manager -- ^ Connection manager. -> SmsAero PhoneResponse-smsAeroAddPhone auth p g ln fn mn bd txt manager = smsAeroAddPhone_ auth p g ln fn mn bd txt manager defaultBaseUrl -- | Delete a phone from contact list or group. smsAeroDeletePhone :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password). -> Phone -- ^ Subscriber's phone number. -> Maybe Group -- ^ Group to remove contact from. If absent, contact will be deleted from general contact list.- -> Manager -- ^ Connection manager. -> SmsAero PhoneResponse-smsAeroDeletePhone auth p mg manager = smsAeroDeletePhone_ auth p mg manager defaultBaseUrl -- | Add a phone number to blacklist. smsAeroAddToBlacklist :: SMSAeroAuth -- ^ Authentication data (login and MD5 hash of password) -> Phone -- ^ Phone number to be added to blacklist.- -> Manager -- ^ Connection manager. -> SmsAero BlacklistResponse-smsAeroAddToBlacklist auth p manager = smsAeroAddToBlacklist_ auth p manager defaultBaseUrl -smsAeroSend_ :: SMSAeroAuth -> Phone -> MessageBody -> Signature -> Maybe SMSAeroDate -> Maybe SendType -> Maybe DigitalChannel -> Manager -> BaseUrl -> SmsAero SendResponse-smsAeroSendToGroup_ :: SMSAeroAuth -> Group -> MessageBody -> Signature -> Maybe SMSAeroDate -> Maybe SendType -> Maybe DigitalChannel -> Manager -> BaseUrl -> SmsAero SendResponse-smsAeroStatus_ :: SMSAeroAuth -> MessageId -> Manager -> BaseUrl -> SmsAero MessageStatus-smsAeroCheckSending_ :: SMSAeroAuth -> MessageId -> Manager -> BaseUrl -> SmsAero CheckSendingResponse-smsAeroBalance_ :: SMSAeroAuth -> Manager -> BaseUrl -> SmsAero BalanceResponse-smsAeroCheckTariff_ :: SMSAeroAuth -> Manager -> BaseUrl -> SmsAero CheckTariffResponse-smsAeroSenders_ :: SMSAeroAuth -> Manager -> BaseUrl -> SmsAero SendersResponse-smsAeroSign_ :: SMSAeroAuth -> Manager -> BaseUrl -> SmsAero SignResponse-smsAeroListGroups_ :: SMSAeroAuth -> Manager -> BaseUrl -> SmsAero [Group]-smsAeroAddGroup_ :: SMSAeroAuth -> Group -> Manager -> BaseUrl -> SmsAero GroupResponse-smsAeroDeleteGroup_ :: SMSAeroAuth -> Group -> Manager -> BaseUrl -> SmsAero GroupResponse-smsAeroAddPhone_ :: SMSAeroAuth -> Phone -> Maybe Group -> Maybe Name -> Maybe Name -> Maybe Name -> Maybe BirthDate -> Maybe Text -> Manager -> BaseUrl -> SmsAero PhoneResponse-smsAeroDeletePhone_ :: SMSAeroAuth -> Phone -> Maybe Group -> Manager -> BaseUrl -> SmsAero PhoneResponse-smsAeroAddToBlacklist_ :: SMSAeroAuth -> Phone -> Manager -> BaseUrl -> SmsAero BlacklistResponse--smsAeroSend_ auth = let (f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroSendToGroup_ auth = let (_ :<|> f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroStatus_ auth = let (_ :<|> _ :<|> f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroCheckSending_ auth = let (_ :<|> _ :<|> _ :<|> f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroBalance_ auth = let (_ :<|> _ :<|> _ :<|> _ :<|> f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroCheckTariff_ auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroSenders_ auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> f :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroSign_ auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> f :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroListGroups_ auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> (f :<|> _ :<|> _) :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroAddGroup_ auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> (_ :<|> f :<|> _) :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroDeleteGroup_ auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> (_ :<|> _ :<|> f) :<|> _ :<|> _) = smsAeroClient auth in f-smsAeroAddPhone_ auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> (f :<|> _) :<|> _) = smsAeroClient auth in f-smsAeroDeletePhone_ auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> (_ :<|> f) :<|> _) = smsAeroClient auth in f-smsAeroAddToBlacklist_ auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> f) = smsAeroClient auth in f+smsAeroSend auth = let (f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroSendToGroup auth = let (_ :<|> f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroStatus auth = let (_ :<|> _ :<|> f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroCheckSending auth = let (_ :<|> _ :<|> _ :<|> f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroBalance auth = let (_ :<|> _ :<|> _ :<|> _ :<|> f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroCheckTariff auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> f :<|> _ :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroSenders auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> f :<|> _ :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroSign auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> f :<|> _ :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroListGroups auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> (f :<|> _ :<|> _) :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroAddGroup auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> (_ :<|> f :<|> _) :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroDeleteGroup auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> (_ :<|> _ :<|> f) :<|> _ :<|> _) = smsAeroClient auth in f+smsAeroAddPhone auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> (f :<|> _) :<|> _) = smsAeroClient auth in f+smsAeroDeletePhone auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> (_ :<|> f) :<|> _) = smsAeroClient auth in f+smsAeroAddToBlacklist auth = let (_ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> _ :<|> f) = smsAeroClient auth in f
src/SMSAero/Types.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-}@@ -28,6 +29,7 @@ import Data.Aeson import Data.Int (Int64)+import Data.Monoid import Data.Time (UTCTime) import Data.Time.Calendar (Day)@@ -36,13 +38,18 @@ import Data.Text (Text) import qualified Data.Text as Text -import Web.HttpApiData.Internal+import Web.HttpApiData -- | SMSAero sender's signature. This is used for the "from" field. newtype Signature = Signature { getSignature :: Text } deriving (Eq, Show, FromJSON, ToJSON, ToHttpApiData, FromHttpApiData) -- | SMSAero sent message id.-newtype MessageId = MessageId Int64 deriving (Eq, Show, Ord, FromJSON, ToJSON, ToHttpApiData, FromHttpApiData)+newtype MessageId = MessageId Int64+ deriving (Eq, Show, Ord, FromJSON, ToJSON, ToHttpApiData, FromHttpApiData+#if MIN_VERSION_aeson(1,0,0)+ , ToJSONKey, FromJSONKey+#endif+ ) -- | SMSAero message body. newtype MessageBody = MessageBody Text deriving (Eq, Show, FromJSON, ToJSON, ToHttpApiData, FromHttpApiData)@@ -102,7 +109,7 @@ instance FromHttpApiData DigitalChannel where parseQueryParam "1" = Right DigitalChannel- parseQueryParam x = defaultParseError x+ parseQueryParam x = Left ("expected 1 for digital channel (but got " <> x <> ")") instance ToHttpApiData SendType where toQueryParam PaidSignature = "1"