hissmetrics 0.1.1 → 0.2
raw patch · 2 files changed
+55/−18 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Web.KISSmetrics: class EventName event
+ Web.KISSmetrics: class Identity ident
+ Web.KISSmetrics: fromEventName :: EventName event => event -> SimpleText
+ Web.KISSmetrics: fromIdentity :: Identity ident => ident -> SimpleText
+ Web.KISSmetrics: instance EventName ByteString
+ Web.KISSmetrics: instance Identity ByteString
- Web.KISSmetrics: Alias :: SimpleText -> SimpleText -> CallType
+ Web.KISSmetrics: Alias :: ident -> ident -> CallType event ident
- Web.KISSmetrics: Record :: SimpleText -> SimpleText -> Timestamp -> [Property] -> CallType
+ Web.KISSmetrics: Record :: event -> ident -> Timestamp -> [Property] -> CallType event ident
- Web.KISSmetrics: SetProps :: SimpleText -> Timestamp -> [Property] -> CallType
+ Web.KISSmetrics: SetProps :: ident -> Timestamp -> [Property] -> CallType event ident
- Web.KISSmetrics: call :: Manager -> APIKey -> CallType -> IO ()
+ Web.KISSmetrics: call :: (EventName event, Identity ident) => Manager -> APIKey -> CallType event ident -> IO ()
- Web.KISSmetrics: data CallType
+ Web.KISSmetrics: data CallType event ident
- Web.KISSmetrics: eventName :: CallType -> SimpleText
+ Web.KISSmetrics: eventName :: CallType event ident -> event
- Web.KISSmetrics: identity :: CallType -> SimpleText
+ Web.KISSmetrics: identity :: CallType event ident -> ident
- Web.KISSmetrics: identity' :: CallType -> SimpleText
+ Web.KISSmetrics: identity' :: CallType event ident -> ident
- Web.KISSmetrics: properties :: CallType -> [Property]
+ Web.KISSmetrics: properties :: CallType event ident -> [Property]
- Web.KISSmetrics: timestamp :: CallType -> Timestamp
+ Web.KISSmetrics: timestamp :: CallType event ident -> Timestamp
Files
- hissmetrics.cabal +1/−1
- src/Web/KISSmetrics.hs +54/−17
hissmetrics.cabal view
@@ -1,5 +1,5 @@ Name: hissmetrics-Version: 0.1.1+Version: 0.2 Synopsis: Unofficial API bindings to KISSmetrics. Homepage: https://github.com/meteficha/hissmetrics License: BSD3
src/Web/KISSmetrics.hs view
@@ -4,12 +4,17 @@ -- import qualified Web.KISSmetrics as KISSmetrics -- @ module Web.KISSmetrics- ( APIKey+ ( -- * Data types+ APIKey , SimpleText , Property , Timestamp(..)- , CallType(..)+ -- * Making calls , call+ , CallType(..)+ -- * Type classes+ , EventName(..)+ , Identity(..) ) where import Control.Arrow (second)@@ -50,11 +55,13 @@ -- ^ Use given time as the timestamp. -data CallType =+-- | A type of call that may be made to KISSmetrics. See also+-- <http://support.kissmetrics.com/apis/specifications>.+data CallType event ident = -- | Record an event.- Record { eventName :: SimpleText+ Record { eventName :: event -- ^ Name of the event being recorded.- , identity :: SimpleText+ , identity :: ident -- ^ Identity of the person doing the event. , timestamp :: Timestamp -- ^ See 'Timestamp'.@@ -62,22 +69,48 @@ -- ^ Any additional properties you may want. } -- | Set user properties without recording an event.- | SetProps { identity :: SimpleText+ | SetProps { identity :: ident -- ^ Identity of the person whose properties will- -- to be changed.+ -- be changed. , timestamp :: Timestamp -- ^ See 'Timestamp'. , properties :: [Property] -- ^ Properties to be set. } -- | Alias two identities as the same one.- | Alias { identity :: SimpleText+ | Alias { identity :: ident -- ^ Identity of the person you're aliasing.- , identity' :: SimpleText+ , identity' :: ident -- ^ Other identity you want to alias. } +-- | Type class of data types that are event names.+--+-- You may just use 'SimpleText' (which is the only instance+-- provided by default), but you may also create your own data+-- type for event names and add an instance of this class.+class EventName event where+ fromEventName :: event -> SimpleText++-- | This is the same as 'SimpleText'.+instance EventName B8.ByteString where+ fromEventName = id+++-- | Type class of data types that are user identities.+--+-- You may just use 'SimpleText' (which is the only instance+-- provided by default), but you may also create your own data+-- type for event names and add an instance of this class.+class Identity ident where+ fromIdentity :: ident -> SimpleText++-- | This is the same as 'SimpleText'.+instance Identity B8.ByteString where+ fromIdentity = id++ -- | Call KISSmetrics' API. See 'CallType' for documentation -- about which calls you may make. --@@ -88,9 +121,10 @@ -- -- TODO: Currently there's no support for automatically retrying -- failed request, you need to retry yourself.-call :: H.Manager -- ^ HTTP connection manager (cf. 'H.newManager').- -> APIKey -- ^ Your KISSmetrics API key.- -> CallType -- ^ Which call you would like to make.+call :: (EventName event, Identity ident) =>+ H.Manager -- ^ HTTP connection manager (cf. 'H.newManager').+ -> APIKey -- ^ Your KISSmetrics API key.+ -> CallType event ident -- ^ Which call you would like to make. -> IO () call manager apikey callType = C.runResourceT $ do@@ -122,23 +156,26 @@ -- | Internal function. Given a 'CallType', return the URL to be -- used and generate a list of arguments.-callInfo :: CallType -> (H.Ascii, H.SimpleQuery)+callInfo :: (EventName event, Identity ident) =>+ CallType event ident -> (H.Ascii, H.SimpleQuery) callInfo Record {..} = ( "/e"- , (:) ("_n", eventName) $- (:) ("_p", identity) $+ , (:) ("_n", fromEventName eventName) $+ (:) ("_p", fromIdentity identity) $ timestampInfo timestamp $ propsInfo properties ) callInfo SetProps {..} = ( "/s"- , (:) ("_p", identity) $+ , (:) ("_p", fromIdentity identity) $ timestampInfo timestamp $ propsInfo properties ) callInfo Alias {..} = ( "/a"- , [("_p", identity), ("_n", identity')]+ , [ ("_p", fromIdentity identity)+ , ("_n", fromIdentity identity')+ ] )