Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: f97f3e8ff2
Fetching contributors…

Cannot retrieve contributors at this time

49 lines (33 sloc) 1.088 kB
# -*- coding: utf-8 -*-
"""
stathat.py
~~~~~~~~~~
A minimalistic API wrapper for StatHat.com, powered by Requests.
Usage::
>>> from stathat import StatHat
>>> stats = StatHat('me@kennethreitz.com')
>>> stats.count('wtfs/minute', 10)
True
>>> stats.count('connections.active', 85092)
True
Enjoy.
"""
import requests
DEFAULT_STATHAT_URL = 'http://api.stathat.com'
class StatHat(object):
"""The StatHat API wrapper."""
STATHAT_URL = DEFAULT_STATHAT_URL
def __init__(self, email=None):
self.email = email
# Enable keep-alive and connection-pooling.
self.session = requests.session()
def _http_post(self, path, data):
url = self.STATHAT_URL + path
r = self.session.post(url, data=data, prefetch=True)
return r
def value(self, key, value):
r = self._http_post('/ez', {'email': self.email, 'stat': key, 'value': value})
return r.ok
def count(self, key, count):
r = self._http_post('/ez', {'email': self.email, 'stat': key, 'count': count})
return r.ok
Jump to Line
Something went wrong with that request. Please try again.