Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ matrix:
compiler: ": #GHC 8.0.1"
addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1], sources: [hvr-ghc]}}

- env: BUILD=cabal CABALVER=3.6.2 GHCVER=9.0.2
compiler: ": #GHC 9.0.2"
addons: {apt: {packages: [cabal-install-3.6.2.0,ghc-9.0.2], sources: [hvr-ghc]}}

- env: BUILD=cabal CABALVER=3.6.2 GHCVER=9.2.4
compiler: ": #GHC 9.2.4"
addons: {apt: {packages: [cabal-install-3.6.2.0,ghc-9.2.4], sources: [hvr-ghc]}}

# NOTE(mroberts): I've borrowed this from Yesod's .travis.yml:
#
# https://github.com/yesodweb/yesod/blob/master/.travis.yml
Expand Down Expand Up @@ -76,6 +84,10 @@ matrix:
compiler: ": #stack 8.2.2"
addons: {apt: {packages: [libgmp-dev]}}

- env: BUILD=stack ARGS="--resolver lts-19"
compiler: ": #stack 9.0.2"
addons: {apt: {packages: [libgmp-dev]}}

before_install:
- unset CC
- export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$HOME/.local/bin:$PATH
Expand Down
2 changes: 1 addition & 1 deletion src/Control/Monad/Twilio.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ data TwilioException
| InvalidAuthToken !Text
| InvalidCredentials
| UnexpectedResponse !(Response LBS.ByteString)
deriving (Show, Eq, Typeable)
deriving (Show, Typeable)

instance Exception TwilioException
14 changes: 10 additions & 4 deletions src/Twilio/Tokens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-#LANGUAGE MultiParamTypeClasses #-}
{-#LANGUAGE OverloadedStrings #-}
{-#LANGUAGE ViewPatterns #-}
{-# LANGUAGE CPP #-}
-------------------------------------------------------------------------------
-- |
-- Module : Twilio.Tokens
Expand All @@ -21,14 +22,19 @@ import Control.Error.Safe
import Control.Monad
import Control.Monad.Catch
import Data.Aeson
import qualified Data.HashMap.Strict as HashMap
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding
import Data.Time.Clock
import Network.URI

#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.KeyMap as KeyMap
#else
import qualified Data.HashMap.Strict as KeyMap
#endif

import Control.Monad.Twilio
import Twilio.Types
import Twilio.Internal.Parser
Expand Down Expand Up @@ -67,13 +73,13 @@ data IceServer

instance FromJSON IceServer where
parseJSON (Object map) =
let url = HashMap.lookup "url" map >>= valueToText >>= parseAbsoluteURI . T.unpack
let url = KeyMap.lookup "url" map >>= valueToText >>= parseAbsoluteURI . T.unpack
in case url of
Nothing -> mzero
Just url' -> return . fromMaybe (StunServer url') $ TurnServer
<$> url
<*> (HashMap.lookup "credential" map >>= valueToText)
<*> (HashMap.lookup "username" map >>= valueToText)
<*> (KeyMap.lookup "credential" map >>= valueToText)
<*> (KeyMap.lookup "username" map >>= valueToText)
parseJSON _ = mzero

instance Post0 Token where
Expand Down
21 changes: 18 additions & 3 deletions src/Twilio/Types/Capability.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-#LANGUAGE FlexibleInstances #-}
{-#LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE CPP #-}
-------------------------------------------------------------------------------
-- |
-- Module : Twilio.Capability
Expand All @@ -12,11 +13,25 @@ module Twilio.Types.Capability where

import Control.Monad
import Data.Aeson
import qualified Data.HashMap.Strict as HashMap
import Data.Maybe
import Data.Set (Set)
import qualified Data.Set as Set

#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.KeyMap as KeyMap
import qualified Data.Aeson.Key as Key

keyFromString :: String -> Key.Key
keyFromString = Key.fromString

#else
import qualified Data.HashMap.Strict as KeyMap
import qualified Data.Text as T

keyFromString :: String -> T.Text
keyFromString = T.pack
#endif

type Capabilities = Set Capability

data Capability
Expand All @@ -26,12 +41,12 @@ data Capability
deriving (Bounded, Enum, Eq, Ord, Read, Show)

instance {-# OVERLAPPING #-} FromJSON Capabilities where
parseJSON (Object map)
parseJSON (Object map)
= let map' = fmap (\value -> case value of
Bool bool -> bool
_ -> False) map
in return $ foldr (\capability set ->
if HashMap.lookupDefault False (T.pack $ show capability) map'
if fromMaybe False $ KeyMap.lookup (keyFromString $ show capability) map'
then Set.insert capability set
else set
) Set.empty [Voice, SMS, MMS]
Expand Down
12 changes: 9 additions & 3 deletions src/Twilio/Types/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-#LANGUAGE FunctionalDependencies #-}
{-#LANGUAGE OverloadedStrings #-}
{-#LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE CPP #-}
-------------------------------------------------------------------------------
-- |
-- Module : Twilio.Types.List
Expand All @@ -23,11 +24,16 @@ import Control.Monad
import Data.Aeson
import Data.Aeson.Types
import Data.Data
import Data.Text (Text)
import Debug.Trace (trace)
import GHC.Generics
import Network.URI

#if MIN_VERSION_aeson(2,0,0)
#else
import Data.Text (Text)
type Key = Text
#endif

(<&>) :: Functor f => f a -> (a -> b) -> f b
(<&>) = flip fmap

Expand All @@ -43,14 +49,14 @@ class FromJSON b => List a b | a -> b where
getList :: a -> [b]

-- | The plural name for the items in the 'List'.
getPlural :: Const Text (a, b)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think you could do something like:

#if MIN_VERSION_aeson(2,0,0)
#else
type Key = Text
#endif

getPlural :: Const Key (a, b)

-- | Parse a 'JSON' 'Value' to an instance of the 'List'.
parseJSONToList :: Value -> Parser a
parseJSONToList o@(Object v)
= unwrap (getListWrapper :: Wrapper (Maybe PagingInformation -> [b] -> a))
<$> maybePagingInformation
<*> (v .: getConst (getPlural :: Const Text (a, b)) :: Parser [b])
<*> (v .: getConst (getPlural :: Const Key (a, b)) :: Parser [b])
where
maybePagingInformation = case fromJSON o of
Success pagingInformation -> return $ Just pagingInformation
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-8.20
resolver: lts-19.25

# User packages to be built.
# Various formats can be used as shown in the example below.
Expand Down
10 changes: 5 additions & 5 deletions twilio.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: twilio
version: 0.3.0.0
version: 0.4.0.0
synopsis: Twilio REST API library for Haskell
description: This package exports bindings to Twilio's REST API (<https://www.twilio.com/docs/api/rest>). While we would like to have a complete binding to Twilio's REST API, this package is being developed on demand. If you need something that has not been implemented yet, please send a pull request or file an issue on GitHub (<https://github.com/markandrus/twilio-haskell>).
homepage: https://github.com/markandrus/twilio-haskell
Expand Down Expand Up @@ -84,11 +84,11 @@ library
Twilio.UsageTrigger,
Twilio.UsageTriggers
hs-source-dirs: src
build-depends: aeson >=0.8 && <0.10 || >=0.11,
build-depends: aeson >= 0.11 && <1.6 || >=2.0 && <2.2,
base ==4.*,
binary >=0.7,
bytestring ==0.10.*,
containers ==0.5.*,
bytestring ==0.11.*,
containers ==0.6.*,
deepseq >=1,
errors >=1,
exceptions ==0.*,
Expand All @@ -102,7 +102,7 @@ library
old-locale ==1.0.*,
scientific ==0.*,
template-haskell >=2,
text ==1.*,
text ==1.* || ==2.0.*,
time >=1,
transformers >=0.3,
unordered-containers ==0.2.*
Expand Down