ServiceInstapush   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 43
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A read_data() 0 14 1
A __init__() 0 3 1
A save_data() 0 20 1
1
# coding: utf-8
2
from instapush import Instapush, App
3
4
# django classes
5
from logging import getLogger
6
7
# django_th classes
8
from django_th.services.services import ServicesMgr
9
from th_instapush.models import Instapush as InstapushModel
10
11
"""
12
    handle process with instapush
13
    put the following in settings.py
14
15
    TH_SERVICES = (
16
        ...
17
        'th_instapush.my_instapush.ServiceInstapush',
18
        ...
19
    )
20
"""
21
22
logger = getLogger('django_th.trigger_happy')
23
24
25
class ServiceInstapush(ServicesMgr):
26
    """
27
        Service Instapush
28
    """
29
    def __init__(self, token=None, **kwargs):
30
        super(ServiceInstapush, self).__init__(token, **kwargs)
31
        self.token = token
32
33
    def read_data(self, **kwargs):
34
        """
35
            get the data from the service
36
            as the pocket service does not have any date
37
            in its API linked to the note,
38
            add the triggered date to the dict data
39
            thus the service will be triggered when data will be found
40
41
            :param kwargs: contain keyword args : trigger_id at least
42
            :type kwargs: dict
43
44
            :rtype: list
45
        """
46
        pass
47
48
    def save_data(self, trigger_id, **data):
49
        """
50
            let's save the data
51
52
            :param trigger_id: trigger ID from which to save data
53
            :param data: the data to check to be used and save
54
            :type trigger_id: int
55
            :type data:  dict
56
            :return: the status of the save statement
57
            :rtype: boolean
58
        """
59
        title, content = super(ServiceInstapush, self).save_data(trigger_id,
60
                                                                 **data)
61
        instance = InstapushModel.objects.get(trigger_id=trigger_id)
62
        Instapush(user_token=self.token)
63
        app = App(appid=instance.app_id, secret=instance.app_secret)
64
        trackers = {instance.tracker_name: content}
65
        status = app.notify(event_name=instance.event_name,
66
                            trackers=trackers)
67
        return status
68