<commit_before>-- GSoC 2013 - Communicating with mobile devices.
{-# LANGUAGE FlexibleContexts #-}
-- | This Module define the main data types for sending Push Notifications through Google Cloud Messaging.
module Network.PushNotify.Gcm.Types
    ( GCMAppConfig(..)
    , GCMmessage(..)
    , GCMresult(..)
    , RegId
    ) where


import Network.PushNotify.Gcm.Constants
import Data.Default
import Data.Aeson.Types
import Data.Text
import Control.Monad.Writer


-- | 'GCMAppConfig' represents the main necessary information for sending notifications through GCM.
data GCMAppConfig = GCMAppConfig
    {   apiKey :: Text
    ,   numRet :: Int
    }   deriving Show


type RegId = Text


-- | 'GCMmessage' represents a message to be sent through GCM.
data GCMmessage = GCMmessage
    {   registration_ids        :: [RegId]
    ,   collapse_key            :: Maybe Text
    ,   data_object             :: Maybe Object
    ,   delay_while_idle        :: Bool
    ,   time_to_live            :: Maybe Int
    ,   restricted_package_name :: Maybe Text
    ,   dry_run                 :: Bool
    } deriving Show

instance Default GCMmessage where
    def = GCMmessage {
        registration_ids        = []
    ,   collapse_key            = Nothing
    ,   data_object             = Nothing
    ,   delay_while_idle        = False
    ,   time_to_live            = Nothing
    ,   restricted_package_name = Nothing
    ,   dry_run                 = False
    }


-- | 'GCMresult' represents information about messages after a communication with GCM Servers.
data GCMresult = GCMresult
    {   multicast_id      :: Maybe Integer
    ,   success           :: Maybe Int
    ,   failure           :: Maybe Int
    ,   canonical_ids     :: Maybe Int
    ,   newRegids         :: [(RegId,RegId)] -- ^ regIds that need to be replaced.
    ,   messagesIds       :: [(RegId,Text)] -- ^ Successful RegIds, and its message_id
    ,   errorUnRegistered :: [RegId] -- ^ Failed regIds that need to be removed.
    ,   errorToReSend     :: [RegId] -- ^ Failed regIds that I need to resend the message to,
                                 -- ^ because there was an internal problem in the GCM servers.
    ,   errorRest         :: [(RegId,Text)] -- ^ Failed regIds with the rest of the possible errors (probably a non-recoverable errors)
    } deriving Show

instance Default GCMresult where
    def = GCMresult {
        multicast_id      = Nothing
    ,   success           = Nothing
    ,   failure           = Nothing
    ,   canonical_ids     = Nothing
    ,   newRegids         = []<commit_msg>I continue working on the CCS Api<commit_after>-- GSoC 2013 - Communicating with mobile devices.
{-# LANGUAGE FlexibleContexts #-}
-- | This Module define the main data types for sending Push Notifications through Google Cloud Messaging.
module Network.PushNotify.Gcm.Types
    ( GCMAppConfig(..)
    , GCMmessage(..)
    , GCMresult(..)
    , RegId
    ) where


import Network.PushNotify.Gcm.Constants
import Data.Default
import Data.Aeson.Types
import Data.Text
import Control.Monad.Writer


-- | 'GCMAppConfig' represents the main necessary information for sending notifications through GCM.
data GCMAppConfig = GCMAppConfig
    {   apiKey   :: Text
    ,   senderID :: Text
    ,   numRet   :: Int
    }   deriving Show


type RegId = Text


-- | 'GCMmessage' represents a message to be sent through GCM.
data GCMmessage = GCMmessage
    {   registration_ids        :: [RegId]
    ,   collapse_key            :: Maybe Text
    ,   data_object             :: Maybe Object
    ,   delay_while_idle        :: Bool
    ,   time_to_live            :: Maybe Int
    ,   restricted_package_name :: Maybe Text
    ,   dry_run                 :: Bool
    } deriving Show

instance Default GCMmessage where
    def = GCMmessage {
        registration_ids        = []
    ,   collapse_key            = Nothing
    ,   data_object             = Nothing
    ,   delay_while_idle        = False
    ,   time_to_live            = Nothing
    ,   restricted_package_name = Nothing
    ,   dry_run                 = False
    }


-- | 'GCMresult' represents information about messages after a communication with GCM Servers.
data GCMresult = GCMresult
    {   multicast_id      :: Maybe Integer
    ,   success           :: Maybe Int
    ,   failure           :: Maybe Int
    ,   canonical_ids     :: Maybe Int
    ,   newRegids         :: [(RegId,RegId)] -- ^ regIds that need to be replaced.
    ,   messagesIds       :: [(RegId,Text)] -- ^ Successful RegIds, and its message_id
    ,   errorUnRegistered :: [RegId] -- ^ Failed regIds that need to be removed.
    ,   errorToReSend     :: [RegId] -- ^ Failed regIds that I need to resend the message to,
                                     -- ^ because there was an internal problem in the GCM servers.
    ,   errorRest         :: [(RegId,Text)] -- ^ Failed regIds with the rest of the possible errors (probably a non-recoverable errors)
    } deriving Show

instance Default GCMresult where
    def = GCMresult {
        multicast_id      = Nothing
    ,   success           = Nothing
    ,   failure           = Nothing
    ,   canonical_ids     = Nothing
    ,   newRegids         = []
{'fraction_non_alphanumeric': 0.07851794970243808, 'fraction_numerical': 0.0015358034171626032, 'mean_word_length': 1.9686609686609686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6530095', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1440, 'n_words': 446}