API
init
Initialize and setup the stathat plugin.
Default global log level is LOG
. See Levels for full list of available levels.
stathat.init(options)
where options
is a table including the following keys
user_key
- The ezkey for your StatHat account (defaults to email address)api
- Specifies the type of api to use. Currently onlyez
is supportedtoken
- Optional. Required to access the export API.
Example
local options = {
user_key = "hello@example.com",
api = "ez",
token = "ACCESSTOKEN"
}
stathat.init(options)
count
Post count for specified stat
stathat.count(name, count, time, callback)
name
- Unique stat name (any character except ~ allowed, 255 characters maximum)count
- Number you want to counttime
- Optional. Timestamp (unix seconds since epoch)callback
- Optional. Function that will be called on stathat response
value
Post value for specified stat
stathat.value(name, value, time, callback)
name
- Unique stat name (any character except ~ allowed, 255 characters maximum)value
- Value you want to tracktime
- Optional. Timestamp (unix seconds since epoch)callback
- Optional. Function that will be called on stathat response
list
Get a list of all your stats, including name and id.
stathat.list(callback, offset)
callback
- Function that will be called on stathat responseoffset
- Optional. By default list will return at most 3,000 stats at a time. If you have more than 3,000 stats, you can specify an offset in your requests to get the next batch of stats.
info
Get info about a single stat.
callback
- Function that will be called on stathat responsename
- Name of the stat to get info for
stathat.info(callback, name)
data
Get datasets for 1 or 2 stats
id0
- Stat id. Stat ids can be retrieved from web interface or using operation list.id1
- Stat id. Set to nil if not used.duration
- The duration of the timeframe for which the data set will be returned. Must be specified as string in format XY, where X is a number and Y is one of the following characters: m (minute), h (hour), d (day), w (week), M (month), y (year)interval
- The interval of which data is returned. One data point will be represented by interval. Must be specified as string in format XY, where X is a number and Y is one of the following characters: m (minute), h (hour), d (day), w (week), M (month), y (year)callback
- Function that will be called on stathat response
stathat.data(id0, id1, duration, interval, callback)
data_summary
The export API allows you to get daily summary data as well. This uses your timezone to chop the data into days separated exactly at midnight. Any data that in the current day (since midnight) is not returned.
id0
- Stat id. Stat ids can be retrieved from web interface or using operation list.id1
- Stat id. Set to nil if not used.duration
- The duration of the timeframe for which the data set will be returned. Must be specified as string in format XY, where X is a number and Y is one of the following characters: m (minute), h (hour), d (day), w (week), M (month), y (year)callback
- Function that will be called on stathat response
stathat.data_summary(id0, id1, duration, callback)
delete
Delete a stat by stat id.
id
- Stat id. Stat ids can be retrieved from web interface or using operation list.callback
- Optional. Function that will be called on stathat response
stathat.delete(id, callback)
callback function
The callback function is called when stathat responds to the operation. It can fail for various reasons or it can succeed. An argument is passed to callback function, event
of type table.
The event table will have the following parameters set
isError
- True or false. Indicates if the request was successful or not.name
-"stathatRequest"
responseMsg
- Response message. Usually"failed"
or"ok"
.responseId
- This is the id of the response. Each query returns an id. If something goes wrong,nil
is returned.responseType
- The type of request. Valid values are:"count"
,"value"
,"list"
,"info"
,"data"
,"data_summary"
,"delete"
payload
- The data returned by stathat (if any)