<commit_before>-- GSoC 2013 - Communicating with mobile devices.

import Network.PushNotify.Apns.Send
import Network.PushNotify.Apns.Types
import Data.Default
import Data.Text (pack)
import Control.Concurrent

{-
main :: IO ()
main = do
            let confg = def{
                            certificate = "public-cert.pem"
                        ,   privateKey = "private-key.pem"
                        ,   environment = Development }
            putStrLn "LET'S SEND A NOTIFICATION:"
            putStr "A device token (hexadecimal): "
            dtoken      <- getLine
            putStr "An alert message: "
            alertMsg    <- getLine
            let msg = def { deviceTokens = [pack dtoken,pack "3242"], alert = Left $ pack alertMsg }
            newConfg    <- startAPNS confg
            res         <- sendAPNS newConfg msg
            putStrLn ("Result: " ++ show res)
            putStrLn "\nLET'S CONNECT WITH FEEDBACK SERVICE:"
            fres        <- feedBackAPNS confg
            putStrLn ("Result: " ++ show fres)
-}

main :: IO ()
main = do
            let confg = def{
                            certificate = "public-cert.pem"
                        ,   privateKey  = "private-key.pem"
                        ,   environment = Development 
                        ,   timeoutTime = 100000 }

            let msg = def{
                            deviceTokens = map (pack . show) [1 .. 100]
                        ,   alert        = Left $ pack "Hello World!" }
            newConfg    <- startAPNS confg
            var         <- newEmptyMVar
            putMVar var ()
            loop 5 msg newConfg var
            where
                loop 0 msg newConfg var = do
                                            threadDelay 200000
                                            closeAPNS newConfg
                loop n msg newConfg var = do            
                           forkIO $ do
                                        res <- sendAPNS newConfg msg
                                        takeMVar var
                                        putStrLn ("Result: " ++ show res)
                                        putMVar var ()
                           loop (n-1) msg newConfg var
<commit_msg>details in test example<commit_after>-- GSoC 2013 - Communicating with mobile devices.

import Network.PushNotify.Apns.Send
import Network.PushNotify.Apns.Types
import Data.Default
import Data.Text (pack)
import Control.Concurrent

main :: IO ()
main = do
            let confg = def{
                            certificate = "public-cert.pem"
                        ,   privateKey  = "private-key.pem"
                        ,   environment = Development 
                        ,   timeoutTime = 1000000 
                        }

            newConfg    <- startAPNS confg
            var         <- newEmptyMVar
            putMVar var ()
            loop 10000 newConfg var
            where
                loop 0 newConfg var = do
                                            threadDelay 50000000
                                            closeAPNS newConfg
                loop n newConfg var = do
                           forkIO $ do
                                        n <- myThreadId
                                        let msg = def{
                                                deviceTokens = map (pack . show) [11 .. 20]
                                            ,   alert        = Left $ pack ("Hello World! by: " ++ show n) }
                                        sending msg newConfg var
                           loop (n-1) newConfg var
                
                sending msg newConfg var = do
                                                res <- sendAPNS newConfg msg
                                                takeMVar var
                                                putStrLn ("Result: " ++ show res)
                                                putMVar var ()
                                                let rest = toReSendTokens res
                                                if rest /= []
                                                then sending msg{deviceTokens = rest} newConfg var
                                                else return ()

{'fraction_non_alphanumeric': 0.06030855539971949, 'fraction_numerical': 0.01332398316970547, 'mean_word_length': 0.8185295367615809, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 41, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5505416', 'n_tokens_mistral': 962, 'n_tokens_neox': 889, 'n_words': 283}