line 2.2.0 → 3.0.0
raw patch · 5 files changed
+90/−6 lines, 5 files
Files
- CHANGELOG.md +4/−0
- line.cabal +1/−1
- src/Line/Messaging/Webhook/Types.hs +23/−4
- test/Line/Messaging/Webhook/TypesSpec.hs +4/−1
- test/Line/Messaging/Webhook/TypesSpecHelper.hs +58/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+## 3.0.0 (26 Apr 2017)++* Add type and dm support for Beacon event+ ## 2.2.0 (15 Jan 2017) * Add multicast API support
line.cabal view
@@ -1,5 +1,5 @@ name: line-version: 2.2.0+version: 3.0.0 synopsis: Haskell SDK for the LINE API homepage: https://github.com/noraesae/line license: BSD3
src/Line/Messaging/Webhook/Types.hs view
@@ -40,6 +40,8 @@ EventMessage (..), -- *** Beacon event BeaconData (..),+ getHWID,+ getDeviceMessage, ) where import Data.Aeson@@ -239,14 +241,31 @@ parseJSON _ = fail "IncommingMessage" -- | Represent beacon data.-data BeaconData = BeaconEnter { getHWID :: ID- -- ^ Get hardware ID of the beacon.- }+data BeaconData = BeaconEnter ID (Maybe String)+ | BeaconLeave ID (Maybe String)+ | BeaconBanner ID (Maybe String) deriving (Eq, Show) ++-- | Get hardware ID of the beacon.+getHWID :: BeaconData -> ID+getHWID (BeaconEnter hwid _) = hwid+getHWID (BeaconLeave hwid _) = hwid+getHWID (BeaconBanner hwid _) = hwid++-- | Get device message from the beacon, if exists.+getDeviceMessage :: BeaconData -> Maybe String+getDeviceMessage (BeaconEnter _ dm) = dm+getDeviceMessage (BeaconLeave _ dm) = dm+getDeviceMessage (BeaconBanner _ dm) = dm+ instance FromJSON BeaconData where parseJSON (Object v) = v .: "type" >>= \ t -> case t :: T.Text of- "enter" -> BeaconEnter <$> v .: "hwid"+ "enter" -> parseBeacon BeaconEnter+ "leave" -> parseBeacon BeaconLeave+ "banner" -> parseBeacon BeaconBanner _ -> fail "BeaconData"+ where+ parseBeacon f = f <$> v .: "hwid" <*> v .:? "dm" parseJSON _ = fail "BeaconData"
test/Line/Messaging/Webhook/TypesSpec.hs view
@@ -129,6 +129,9 @@ ] describe "beacon event" $ fromJSONSpec- [ ( goodBeacon, replyE BeaconEvent (BeaconEnter "d41d8cd98f") )+ [ ( goodBeacon, replyE BeaconEvent (BeaconEnter "d41d8cd98f" Nothing) )+ , ( goodBeaconLeave, replyE BeaconEvent (BeaconLeave "d41d8cd98f" Nothing) )+ , ( goodBeaconBanner, replyE BeaconEvent (BeaconBanner "d41d8cd98f" Nothing) )+ , ( goodBeaconWithDm, replyE BeaconEvent (BeaconEnter "d41d8cd98f" (Just "i am a direct message.")) ) , ( badBeacon, Nothing ) ]
test/Line/Messaging/Webhook/TypesSpecHelper.hs view
@@ -449,6 +449,64 @@ ] } |] +goodBeaconLeave :: BL.ByteString+goodBeaconLeave = [r|+{ "events": [+{+ "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",+ "type": "beacon",+ "timestamp": 1462629479859,+ "source": {+ "type": "user",+ "userId": "U206d25c2ea6bd87c17655609a1c37cb8"+ },+ "beacon": {+ "hwid": "d41d8cd98f",+ "type": "leave"+ }+}+] }+|]++goodBeaconBanner :: BL.ByteString+goodBeaconBanner = [r|+{ "events": [+{+ "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",+ "type": "beacon",+ "timestamp": 1462629479859,+ "source": {+ "type": "user",+ "userId": "U206d25c2ea6bd87c17655609a1c37cb8"+ },+ "beacon": {+ "hwid": "d41d8cd98f",+ "type": "banner"+ }+}+] }+|]++goodBeaconWithDm :: BL.ByteString+goodBeaconWithDm = [r|+{ "events": [+{+ "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",+ "type": "beacon",+ "timestamp": 1462629479859,+ "source": {+ "type": "user",+ "userId": "U206d25c2ea6bd87c17655609a1c37cb8"+ },+ "beacon": {+ "hwid": "d41d8cd98f",+ "type": "enter",+ "dm": "i am a direct message."+ }+}+] }+|]+ badBeacon :: BL.ByteString badBeacon = [r| { "events": [