Permalink
Browse files

Add custom metrics

  • Loading branch information...
collimarco committed Nov 3, 2017
1 parent e8f6c74 commit 55d9a557eb3b8b2b548e7249cff268bedca066c1
Showing with 13 additions and 3 deletions.
  1. +4 −1 README.md
  2. +4 −1 pushpad/notification.py
  3. +1 −1 setup.py
  4. +4 −0 tests/test_notification.py
@@ -102,7 +102,10 @@ notification = pushpad.Notification(
starred=True, # optional, bookmark the notification in the Pushpad dashboard (e.g. to highlight manual notifications)
# optional, use this option only if you need to create scheduled notifications (max 5 days)
# see https://pushpad.xyz/docs/schedule_notifications
send_at=datetime.datetime(2016, 7, 25, 10, 9, 0, 0) # you need to import datetime and use UTC
send_at=datetime.datetime(2016, 7, 25, 10, 9, 0, 0), # you need to import datetime and use UTC
# optional, add the notification to custom categories for stats aggregation
# see https://pushpad.xyz/docs/monitoring
custom_metrics=('examples', 'another_metric') # up to 3 metrics per notification
)
# deliver to a user
@@ -5,7 +5,7 @@
class Notification(object):
def __init__(self, project, body=None, title=None, target_url=None, icon_url=None, ttl=None, require_interaction=None, image_url=None, custom_data=None, actions=None, starred=None, send_at=None):
def __init__(self, project, body=None, title=None, target_url=None, icon_url=None, ttl=None, require_interaction=None, image_url=None, custom_data=None, custom_metrics=None, actions=None, starred=None, send_at=None):
self._project = project
self._body = body
self._title = title
@@ -15,6 +15,7 @@ def __init__(self, project, body=None, title=None, target_url=None, icon_url=Non
self._require_interaction = require_interaction
self._image_url = image_url
self._custom_data = custom_data
self._custom_metrics = custom_metrics
self._actions = actions
self._starred = starred
self._send_at = send_at
@@ -46,6 +47,8 @@ def _req_body(self, uids=None, tags=None):
res['notification']['image_url'] = self._image_url
if self._custom_data:
res['notification']['custom_data'] = self._custom_data
if self._custom_metrics:
res['notification']['custom_metrics'] = self._custom_metrics
if self._actions:
res['notification']['actions'] = self._actions
if self._starred is not None:
@@ -12,7 +12,7 @@
setup(
name='pushpad',
version='0.5.0',
version='0.6.0',
description='Pushpad: real push notifications for websites',
url='https://pushpad.xyz',
author='Pushpad',
@@ -30,6 +30,7 @@ def test_instantiate(self):
require_interaction=True,
image_url="http://example.com/assets/image.png",
custom_data="123",
custom_metrics=('examples', 'another_metric'),
actions=(
{
'title': "My Button 1",
@@ -50,6 +51,7 @@ def test_instantiate(self):
self.assertEqual(notification._require_interaction, True)
self.assertEqual(notification._image_url, "http://example.com/assets/image.png")
self.assertEqual(notification._custom_data, "123")
self.assertEqual(notification._custom_metrics, ('examples', 'another_metric'))
self.assertEqual(notification._actions, (
{
'title': "My Button 1",
@@ -87,6 +89,7 @@ def test_req_body_with_optional_fields(self):
'require_interaction': True,
'image_url': 'http://example.com/assets/image.png',
'custom_data': '123',
'custom_metrics': ('examples', 'another_metric'),
'actions': (
{
'title': 'My Button 1',
@@ -109,6 +112,7 @@ def test_req_body_with_optional_fields(self):
require_interaction=True,
image_url="http://example.com/assets/image.png",
custom_data="123",
custom_metrics=('examples', 'another_metric'),
actions=(
{
'title': "My Button 1",

0 comments on commit 55d9a55

Please sign in to comment.