line-bot-sdk 0.5.0.0 → 0.5.0.1
raw patch · 7 files changed
+76/−24 lines, 7 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Line.Bot.Webhook.Events: ContentProvider :: Maybe URL -> Maybe URL -> ContentProvider
+ Line.Bot.Webhook.Events: [$sel:originalContentUrl:ContentProvider] :: ContentProvider -> Maybe URL
+ Line.Bot.Webhook.Events: [$sel:previewImageUrl:ContentProvider] :: ContentProvider -> Maybe URL
+ Line.Bot.Webhook.Events: data ContentProvider
- Line.Bot.Client: issueChannelToken :: ClientCredentials -> ClientM ShortLivedChannelToken
+ Line.Bot.Client: issueChannelToken :: ChannelId -> ChannelSecret -> ClientM ShortLivedChannelToken
- Line.Bot.Internal.Endpoints: type IssueChannelToken' a b = ReqBody '[FormUrlEncoded] a :> "v2" :> "bot" :> "oauth" :> "accessToken" :> Post '[JSON] b
+ Line.Bot.Internal.Endpoints: type IssueChannelToken' a b = ReqBody '[FormUrlEncoded] a :> "v2" :> "oauth" :> "accessToken" :> Post '[JSON] b
- Line.Bot.Internal.Endpoints: type RevokeChannelToken' a = ReqBody '[FormUrlEncoded] a :> "v2" :> "bot" :> "oauth" :> "revoke" :> PostNoContent '[JSON] NoContent
+ Line.Bot.Internal.Endpoints: type RevokeChannelToken' a = ReqBody '[FormUrlEncoded] a :> "v2" :> "oauth" :> "revoke" :> PostNoContent '[JSON] NoContent
Files
- README.md +47/−4
- line-bot-sdk.cabal +1/−1
- src/Line/Bot/Client.hs +5/−2
- src/Line/Bot/Internal/Endpoints.hs +2/−2
- src/Line/Bot/Types.hs +2/−1
- src/Line/Bot/Webhook/Events.hs +1/−0
- test/Line/Bot/ClientSpec.hs +18/−14
README.md view
@@ -8,16 +8,59 @@ * Bindings for (most) of the Messaging APIs -## Usage+## Installation -See the -[examples/](https://github.com/moleike/line-bot-sdk/tree/master/examples) directory.+### From Hackage +`line-bot-sdk` is available on [Hackage](https://hackage.haskell.org). Using the [`cabal-install`][cabal] tool:++```bash+cabal update+cabal install line-bot-sdk+```++### From source++Building from source can be done using [stack][stack] or [cabal][cabal]:++```bash+git clone github.com/moleike/line-bot-sdk.git+cd line-bot-sdk+stack install # Alternatively, `cabal install`+```++[cabal]: https://www.haskell.org/cabal+[stack]: https://docs.haskellstack.org/en/stable/README+ ## Documentation -For details see the reference [documentation on Hackage][hackage].+The documentation for the latest release is available on [Hackage][hackage]. [hackage]: http://hackage.haskell.org/package/line-bot-sdk "Hackage"++## Usage++```haskell+{-# LANGUAGE OverloadedStrings #-}++import Data.String (fromString)+import Line.Bot.Client (Line, getProfile, runLine)+import Line.Bot.Types (Profile)+import System.Environment (getEnv)++profile :: Line Profile+profile = getProfile "U4af4980629..."++main = do+ token <- fromString <$> getEnv "CHANNEL_TOKEN"+ result <- runLine profile token+ case result of+ Left err -> print err+ Right profile -> print profile+```++See the+[examples/](https://github.com/moleike/line-bot-sdk/tree/master/examples) directory for more comprehensive examples. ## Contribute
line-bot-sdk.cabal view
@@ -1,5 +1,5 @@ name: line-bot-sdk-version: 0.5.0.0+version: 0.5.0.1 synopsis: Haskell SDK for LINE Messaging API homepage: https://github.com/moleike/line-bot-sdk#readme bug-reports: https://github.com/moleike/line-bot-sdk/issues
src/Line/Bot/Client.hs view
@@ -145,8 +145,11 @@ issueLinkToken a = ask >>= \auth -> lift $ client (Proxy :: Proxy IssueLinkToken) auth a -issueChannelToken :: ClientCredentials -> ClientM ShortLivedChannelToken-issueChannelToken = client (Proxy :: Proxy IssueChannelToken)+issueChannelToken' :: ClientCredentials -> ClientM ShortLivedChannelToken+issueChannelToken' = client (Proxy :: Proxy IssueChannelToken)++issueChannelToken :: ChannelId -> ChannelSecret -> ClientM ShortLivedChannelToken+issueChannelToken a b = issueChannelToken' $ ClientCredentials a b revokeChannelToken :: ChannelToken -> ClientM NoContent revokeChannelToken = client (Proxy :: Proxy RevokeChannelToken)
src/Line/Bot/Internal/Endpoints.hs view
@@ -147,7 +147,7 @@ type IssueChannelToken' a b = ReqBody '[FormUrlEncoded] a- :> "v2" :> "bot"+ :> "v2" :> "oauth" :> "accessToken" :> Post '[JSON] b@@ -156,7 +156,7 @@ type RevokeChannelToken' a = ReqBody '[FormUrlEncoded] a- :> "v2" :> "bot"+ :> "v2" :> "oauth" :> "revoke" :> PostNoContent '[JSON] NoContent
src/Line/Bot/Types.hs view
@@ -66,7 +66,8 @@ newtype ChannelToken = ChannelToken { unChannelToken :: Text } deriving (Eq, Show, Generic) -instance FromJSON ChannelToken+instance FromJSON ChannelToken where+ parseJSON = withText "ChannelToken" $ return . ChannelToken instance IsString ChannelToken where fromString s = ChannelToken (fromString s)
src/Line/Bot/Webhook/Events.hs view
@@ -18,6 +18,7 @@ ( Events(..) , Event(..) , Message(..)+ , ContentProvider(..) , EpochMilli(..) , Source(..) , Members(..)
test/Line/Bot/ClientSpec.hs view
@@ -32,7 +32,7 @@ import Servant import Servant.Client import Servant.Client.Core-import Servant.Client.Free as F+import Servant.Client.Free as F import Servant.Server (Context (..)) import Servant.Server.Experimental.Auth (AuthHandler, AuthServerData, mkAuthHandler)@@ -56,6 +56,15 @@ :<|> GetGroupMemberProfile' Value :<|> GetRoomMemberProfile' Value +getReplyMessageCountF :: Auth -> LineDate -> Free ClientF MessageCount+getReplyMessageCountF = F.client (Proxy :: Proxy GetReplyMessageCount)++getPushMessageCountF :: Auth -> LineDate -> Free ClientF MessageCount+getPushMessageCountF = F.client (Proxy :: Proxy GetPushMessageCount)++getMulticastMessageCountF :: Auth -> LineDate -> Free ClientF MessageCount+getMulticastMessageCountF = F.client (Proxy :: Proxy GetMulticastMessageCount)+ testProfile :: Value testProfile = [aesonQQ| {@@ -71,17 +80,10 @@ manager <- newManager defaultManagerSettings app $ mkClientEnv manager $ BaseUrl Http "localhost" port "" -runLine :: Line a -> Port -> IO (Either ServantError a)-runLine comp port = withPort port $ runClientM $ runReaderT comp (mkAuth "fake")--getReplyMessageCountF :: Auth -> LineDate -> Free ClientF MessageCount-getReplyMessageCountF = F.client (Proxy :: Proxy GetReplyMessageCount)--getPushMessageCountF :: Auth -> LineDate -> Free ClientF MessageCount-getPushMessageCountF = F.client (Proxy :: Proxy GetPushMessageCount)+auth = mkAuth "fake" -getMulticastMessageCountF :: Auth -> LineDate -> Free ClientF MessageCount-getMulticastMessageCountF = F.client (Proxy :: Proxy GetMulticastMessageCount)+runLine :: Line a -> Port -> IO (Either ServantError a)+runLine comp port = withPort port $ runClientM $ runReaderT comp auth app :: Application app = serveWithContext (Proxy :: Proxy API) serverContext $@@ -104,14 +106,16 @@ runLine (getRoomMemberProfile "1" "1") >=> (`shouldSatisfy` isRight) it "should send `date` query param for push message count" $ do- let Free (RunRequest Request{..} _) = getPushMessageCountF (mkAuth "fake") (LineDate $ fromGregorian 2019 4 7)+ let Free (RunRequest Request{..} _) = getPushMessageCountF auth date toList requestQueryString `shouldBe` [("date", Just "20190407")] it "should send `date` query param for reply message count" $ do- let Free (RunRequest Request{..} _) = getReplyMessageCountF (mkAuth "fake") (LineDate $ fromGregorian 2019 4 7)+ let Free (RunRequest Request{..} _) = getReplyMessageCountF auth date toList requestQueryString `shouldBe` [("date", Just "20190407")] it "should send `date` query param for multicast message count" $ do- let Free (RunRequest Request{..} _) = getMulticastMessageCountF (mkAuth "fake") (LineDate $ fromGregorian 2019 4 7)+ let Free (RunRequest Request{..} _) = getMulticastMessageCountF auth date toList requestQueryString `shouldBe` [("date", Just "20190407")]+ where+ date = LineDate $ fromGregorian 2019 4 7