-
Notifications
You must be signed in to change notification settings - Fork 1
/
SmsApi.purs
59 lines (43 loc) · 2.06 KB
/
SmsApi.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module SmsApi
( SmsApi
, MessageType
, authenticateOAuth
, authenticateSimple
, authenticateSimpleHashed
, sendSms
) where
import Control.Category ((<<<))
import Data.Unit (Unit)
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff)
----------------------------
-- authentication
----------------------------
-- | Foreign type representing authenticated API
foreign import data SmsApi ∷ Type
foreign import authenticateSimpleImpl ∷ { user ∷ String, password ∷ String } → EffectFnAff SmsApi
foreign import authenticateSimpleHashedImpl ∷ { user ∷ String, md5password ∷ String } → EffectFnAff SmsApi
-- | Requests simple login with Basic auth using user and password.
authenticateSimple ∷ { user ∷ String, password ∷ String } → Aff SmsApi
authenticateSimple = fromEffectFnAff <<< authenticateSimpleImpl
-- | Requests simple login with Basic auth using user and md5-hashed password.
authenticateSimpleHashed ∷ { user ∷ String, md5password ∷ String } → Aff SmsApi
authenticateSimpleHashed = fromEffectFnAff <<< authenticateSimpleHashedImpl
-- | Returns authenticated api using OAuth access token.
foreign import authenticateOAuth ∷ { accessToken ∷ String } → Effect SmsApi
-----------------------------
-- sending simple sms
-----------------------------
foreign import sendSmsImpl ∷ SmsApi → { from ∷ String, to ∷ String, message ∷ String } → EffectFnAff Unit
-- | Data type representing different kinds of messages that Smsapi.pl can send.
-- | Read more at https://www.smsapi.pl/docs/#2-pojedynczy-sms
data MessageType = Eco | TwoWay | Pro { verifiedName ∷ String }
-- | Requests simple sms send.
sendSms ∷ { msgType ∷ MessageType, to ∷ String, message ∷ String } → SmsApi → Aff Unit
sendSms input api = fromEffectFnAff (sendSmsImpl api {from: buildFrom input.msgType, to: input.to, message: input.message })
where
buildFrom = case _ of
Eco → "Eco"
TwoWay → "2way"
Pro {verifiedName} → verifiedName