pushi 0.4.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pushi/__init__.py +42 -0
- pushi/apn.py +57 -0
- pushi/app.py +49 -0
- pushi/base.py +154 -0
- pushi/event.py +47 -0
- pushi/subscription.py +55 -0
- pushi/web.py +57 -0
- pushi/web_push.py +91 -0
- pushi-0.4.3.dist-info/METADATA +38 -0
- pushi-0.4.3.dist-info/RECORD +12 -0
- pushi-0.4.3.dist-info/WHEEL +5 -0
- pushi-0.4.3.dist-info/top_level.txt +1 -0
pushi/__init__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Pushi System
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Pushi System.
|
|
8
|
+
#
|
|
9
|
+
# Hive Pushi System is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Pushi System is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Pushi System. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
23
|
+
""" The copyright for the module """
|
|
24
|
+
|
|
25
|
+
__license__ = "Apache License, Version 2.0"
|
|
26
|
+
""" The license for the module """
|
|
27
|
+
|
|
28
|
+
from . import apn
|
|
29
|
+
from . import app
|
|
30
|
+
from . import base
|
|
31
|
+
from . import event
|
|
32
|
+
from . import subscription
|
|
33
|
+
from . import web
|
|
34
|
+
from . import web_push
|
|
35
|
+
|
|
36
|
+
from .apn import APNAPI
|
|
37
|
+
from .app import AppAPI
|
|
38
|
+
from .base import BASE_URL, BASE_WS_URL, API
|
|
39
|
+
from .event import EventAPI
|
|
40
|
+
from .subscription import SubscriptionAPI
|
|
41
|
+
from .web import WebAPI
|
|
42
|
+
from .web_push import WebPushAPI
|
pushi/apn.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Pushi System
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Pushi System.
|
|
8
|
+
#
|
|
9
|
+
# Hive Pushi System is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Pushi System is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Pushi System. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class APNAPI(object):
|
|
33
|
+
def create_apn(self, token, event, auth=None, unsubscribe=True):
|
|
34
|
+
# runs the APN subscription operation for the provided
|
|
35
|
+
# token and event, this operation uses the currently
|
|
36
|
+
# defined app id for the operation, then returns the
|
|
37
|
+
# resulting dictionary to the caller method
|
|
38
|
+
result = self.post(
|
|
39
|
+
self.base_url + "apns",
|
|
40
|
+
params=dict(auth=auth, unsubscribe=unsubscribe),
|
|
41
|
+
data_j=dict(token=token, event=event),
|
|
42
|
+
)
|
|
43
|
+
return result
|
|
44
|
+
|
|
45
|
+
def delete_apn(self, token, event):
|
|
46
|
+
# runs the unsubscription operation for the provided
|
|
47
|
+
# user id and event, this operation uses the currently
|
|
48
|
+
# defined app id for the operation, then returns the
|
|
49
|
+
# resulting dictionary to the caller method
|
|
50
|
+
result = self.delete(self.base_url + "apns/%s/%s" % (token, event))
|
|
51
|
+
return result
|
|
52
|
+
|
|
53
|
+
def subscribe_apn(self, *args, **kwargs):
|
|
54
|
+
return self.create_apn(*args, **kwargs)
|
|
55
|
+
|
|
56
|
+
def unsubscribe_apn(self, *args, **kwargs):
|
|
57
|
+
return self.delete_apn(*args, **kwargs)
|
pushi/app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Pushi System
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Pushi System.
|
|
8
|
+
#
|
|
9
|
+
# Hive Pushi System is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Pushi System is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Pushi System. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class AppAPI(object):
|
|
33
|
+
def create_app(self, name):
|
|
34
|
+
# runs the post call that will create the app with the provided
|
|
35
|
+
# name then returns the returning map to the caller method, it
|
|
36
|
+
# should contain the generated information for the app
|
|
37
|
+
result = self.post(self.base_url + "apps", auth=False, data_j=dict(name=name))
|
|
38
|
+
return result
|
|
39
|
+
|
|
40
|
+
def update_app(self, app_id=None, **kwargs):
|
|
41
|
+
# retrieves the proper app id to be used defaulting to the current
|
|
42
|
+
# defined app id in case none is provided
|
|
43
|
+
app_id = app_id or self.app_id
|
|
44
|
+
|
|
45
|
+
# runs the pit call that will create the app with the provided
|
|
46
|
+
# name then returns the returning map to the caller method, it
|
|
47
|
+
# should contain the newly updated information for the app
|
|
48
|
+
result = self.put(self.base_url + "apps/%s" % app_id, data_j=kwargs)
|
|
49
|
+
return result
|
pushi/base.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Pushi System
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Pushi System.
|
|
8
|
+
#
|
|
9
|
+
# Hive Pushi System is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Pushi System is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Pushi System. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
import hmac
|
|
32
|
+
import hashlib
|
|
33
|
+
|
|
34
|
+
import appier
|
|
35
|
+
|
|
36
|
+
from . import apn
|
|
37
|
+
from . import app
|
|
38
|
+
from . import web
|
|
39
|
+
from . import web_push
|
|
40
|
+
from . import event
|
|
41
|
+
from . import subscription
|
|
42
|
+
|
|
43
|
+
BASE_URL = "https://puxiapp.com:9090/"
|
|
44
|
+
""" The base URL to be used by the API to access
|
|
45
|
+
the remote endpoints, should not be changed """
|
|
46
|
+
|
|
47
|
+
BASE_WS_URL = "wss://puxiapp.com/"
|
|
48
|
+
""" The default base websockets url that is going
|
|
49
|
+
to be used in case no other value is specified """
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class API(
|
|
53
|
+
appier.API,
|
|
54
|
+
apn.APNAPI,
|
|
55
|
+
app.AppAPI,
|
|
56
|
+
web.WebAPI,
|
|
57
|
+
web_push.WebPushAPI,
|
|
58
|
+
event.EventAPI,
|
|
59
|
+
subscription.SubscriptionAPI,
|
|
60
|
+
):
|
|
61
|
+
"""
|
|
62
|
+
Base class for the construction of the pushi
|
|
63
|
+
proxy object for interaction with the server
|
|
64
|
+
side of the pushi system.
|
|
65
|
+
|
|
66
|
+
Should provide the various methods that enable
|
|
67
|
+
the developer to make operations for both read
|
|
68
|
+
and write (create and read).
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
def __init__(self, *args, **kwargs):
|
|
72
|
+
appier.API.__init__(self, *args, **kwargs)
|
|
73
|
+
self.app_id = appier.conf("PUSHI_ID", None)
|
|
74
|
+
self.app_key = appier.conf("PUSHI_KEY", None)
|
|
75
|
+
self.app_secret = appier.conf("PUSHI_SECRET", None)
|
|
76
|
+
self.base_url = appier.conf("PUSHI_URL", BASE_URL)
|
|
77
|
+
self.app_id = kwargs.get("app_id", self.app_id)
|
|
78
|
+
self.app_key = kwargs.get("app_key", self.app_key)
|
|
79
|
+
self.app_secret = kwargs.get("app_secret", self.app_secret)
|
|
80
|
+
self.base_url = kwargs.get("base_url", self.base_url)
|
|
81
|
+
self.token = None
|
|
82
|
+
|
|
83
|
+
def build(
|
|
84
|
+
self,
|
|
85
|
+
method,
|
|
86
|
+
url,
|
|
87
|
+
data=None,
|
|
88
|
+
data_j=None,
|
|
89
|
+
data_m=None,
|
|
90
|
+
headers=None,
|
|
91
|
+
params=None,
|
|
92
|
+
mime=None,
|
|
93
|
+
kwargs=None,
|
|
94
|
+
):
|
|
95
|
+
auth = kwargs.pop("auth", True)
|
|
96
|
+
if auth:
|
|
97
|
+
kwargs["sid"] = self.get_token()
|
|
98
|
+
|
|
99
|
+
def get_token(self):
|
|
100
|
+
if self.token:
|
|
101
|
+
return self.token
|
|
102
|
+
return self.login()
|
|
103
|
+
|
|
104
|
+
def auth_callback(self, params, headers):
|
|
105
|
+
token = self.login()
|
|
106
|
+
params["sid"] = token
|
|
107
|
+
|
|
108
|
+
def login(self):
|
|
109
|
+
# tries to login in the pushi infra-structure using the
|
|
110
|
+
# login route together with the full set of auth info
|
|
111
|
+
# retrieving the result map that should contain the
|
|
112
|
+
# session token, to be used in further calls
|
|
113
|
+
result = self.get(
|
|
114
|
+
self.base_url + "login",
|
|
115
|
+
callback=False,
|
|
116
|
+
auth=False,
|
|
117
|
+
app_id=self.app_id,
|
|
118
|
+
app_key=self.app_key,
|
|
119
|
+
app_secret=self.app_secret,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
# unpacks the token value from the result map and then
|
|
123
|
+
# returns the token to the caller method
|
|
124
|
+
self.token = result["token"]
|
|
125
|
+
return self.token
|
|
126
|
+
|
|
127
|
+
def logout(self):
|
|
128
|
+
# runs the "simplistic" call to the logout operation so
|
|
129
|
+
# that the session is invalidated from the server side
|
|
130
|
+
self.get(self.base_url + "logout")
|
|
131
|
+
|
|
132
|
+
# invalidates the currently set token so that it's no longer
|
|
133
|
+
# going to be used for any kind of operation
|
|
134
|
+
self.token = None
|
|
135
|
+
|
|
136
|
+
def authenticate(self, channel, socket_id):
|
|
137
|
+
# in case the app key is not defined for the current
|
|
138
|
+
# instance an exception must be raised as it's not possible
|
|
139
|
+
# to run the authentication process without an app key
|
|
140
|
+
if not self.app_key:
|
|
141
|
+
raise RuntimeError("No app key defined")
|
|
142
|
+
|
|
143
|
+
# creates the string to hashed using both the provided
|
|
144
|
+
# socket id and channel (concatenation)
|
|
145
|
+
string = "%s:%s" % (socket_id, channel)
|
|
146
|
+
string = appier.legacy.bytes(string)
|
|
147
|
+
|
|
148
|
+
# runs the HMAC encryption in the provided secret and
|
|
149
|
+
# the constructed string and returns a string containing
|
|
150
|
+
# both the key and the hexadecimal digest
|
|
151
|
+
app_secret = appier.legacy.bytes(str(self.app_secret))
|
|
152
|
+
structure = hmac.new(app_secret, string, hashlib.sha256)
|
|
153
|
+
digest = structure.hexdigest()
|
|
154
|
+
return "%s:%s" % (self.app_key, digest)
|
pushi/event.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Pushi System
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Pushi System.
|
|
8
|
+
#
|
|
9
|
+
# Hive Pushi System is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Pushi System is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Pushi System. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class EventAPI(object):
|
|
33
|
+
def create_event(self, channel, data, event="message", persist=True, **kwargs):
|
|
34
|
+
# creates the initial JSON data structure to be used as the message
|
|
35
|
+
# and then "extends" it with the extra key word arguments passed
|
|
36
|
+
# to this methods as a method of extension
|
|
37
|
+
data_j = dict(data=data, event=event, channel=channel, persist=persist)
|
|
38
|
+
for key in kwargs:
|
|
39
|
+
data_j[key] = kwargs[key]
|
|
40
|
+
|
|
41
|
+
# performs the concrete event trigger operation creating an event
|
|
42
|
+
# with the provided information using a secure channel
|
|
43
|
+
result = self.post(self.base_url + "events", data_j=data_j)
|
|
44
|
+
return result
|
|
45
|
+
|
|
46
|
+
def trigger_event(self, *args, **kwargs):
|
|
47
|
+
return self.create_event(*args, **kwargs)
|
pushi/subscription.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Pushi System
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Pushi System.
|
|
8
|
+
#
|
|
9
|
+
# Hive Pushi System is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Pushi System is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Pushi System. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class SubscriptionAPI(object):
|
|
33
|
+
def create_subscription(self, user_id, event):
|
|
34
|
+
# runs the subscription operation for the provided
|
|
35
|
+
# user id and event, this operation uses the currently
|
|
36
|
+
# defined app id for the operation, then returns the
|
|
37
|
+
# resulting dictionary to the caller method
|
|
38
|
+
result = self.post(
|
|
39
|
+
self.base_url + "subscriptions", data_j=dict(user_id=user_id, event=event)
|
|
40
|
+
)
|
|
41
|
+
return result
|
|
42
|
+
|
|
43
|
+
def delete_subscription(self, user_id, event):
|
|
44
|
+
# runs the unsubscription operation for the provided
|
|
45
|
+
# user id and event, this operation uses the currently
|
|
46
|
+
# defined app id for the operation, then returns the
|
|
47
|
+
# resulting dictionary to the caller method
|
|
48
|
+
result = self.delete(self.base_url + "subscriptions/%s/%s" % (user_id, event))
|
|
49
|
+
return result
|
|
50
|
+
|
|
51
|
+
def subscribe(self, *args, **kwargs):
|
|
52
|
+
return self.create_subscription(*args, **kwargs)
|
|
53
|
+
|
|
54
|
+
def unsubscribe(self, *args, **kwargs):
|
|
55
|
+
return self.delete_subscription(*args, **kwargs)
|
pushi/web.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Pushi System
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Pushi System.
|
|
8
|
+
#
|
|
9
|
+
# Hive Pushi System is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Pushi System is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Pushi System. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class WebAPI(object):
|
|
33
|
+
def create_web(self, url, event, auth=None, unsubscribe=True):
|
|
34
|
+
# runs the Web (Hook) subscription operation for the provided
|
|
35
|
+
# url and event, this operation uses the currently
|
|
36
|
+
# defined app id for the operation, then returns the
|
|
37
|
+
# resulting dictionary to the caller method
|
|
38
|
+
result = self.post(
|
|
39
|
+
self.base_url + "webs",
|
|
40
|
+
params=dict(auth=auth, unsubscribe=unsubscribe),
|
|
41
|
+
data_j=dict(url=url, event=event),
|
|
42
|
+
)
|
|
43
|
+
return result
|
|
44
|
+
|
|
45
|
+
def delete_web(self, url, event):
|
|
46
|
+
# runs the unsubscription operation for the provided
|
|
47
|
+
# user id and event, this operation uses the currently
|
|
48
|
+
# defined app id for the operation, then returns the
|
|
49
|
+
# resulting dictionary to the caller method
|
|
50
|
+
result = self.delete(self.base_url + "webs/%s/%s" % (url, event))
|
|
51
|
+
return result
|
|
52
|
+
|
|
53
|
+
def subscribe_web(self, *args, **kwargs):
|
|
54
|
+
return self.create_web(*args, **kwargs)
|
|
55
|
+
|
|
56
|
+
def unsubscribe_web(self, *args, **kwargs):
|
|
57
|
+
return self.delete_web(*args, **kwargs)
|
pushi/web_push.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Hive Pushi System
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
|
+
#
|
|
7
|
+
# This file is part of Hive Pushi System.
|
|
8
|
+
#
|
|
9
|
+
# Hive Pushi System is free software: you can redistribute it and/or modify
|
|
10
|
+
# it under the terms of the Apache License as published by the Apache
|
|
11
|
+
# Foundation, either version 2.0 of the License, or (at your option) any
|
|
12
|
+
# later version.
|
|
13
|
+
#
|
|
14
|
+
# Hive Pushi System is distributed in the hope that it will be useful,
|
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
# Apache License for more details.
|
|
18
|
+
#
|
|
19
|
+
# You should have received a copy of the Apache License along with
|
|
20
|
+
# Hive Pushi System. If not, see <http://www.apache.org/licenses/>.
|
|
21
|
+
|
|
22
|
+
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
|
+
""" The author(s) of the module """
|
|
24
|
+
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
26
|
+
""" The copyright for the module """
|
|
27
|
+
|
|
28
|
+
__license__ = "Apache License, Version 2.0"
|
|
29
|
+
""" The license for the module """
|
|
30
|
+
|
|
31
|
+
import appier
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class WebPushAPI(object):
|
|
35
|
+
def create_web_push(
|
|
36
|
+
self, endpoint, p256dh, auth, event, auth_token=None, unsubscribe=True
|
|
37
|
+
):
|
|
38
|
+
# runs the Web Push subscription operation for the provided
|
|
39
|
+
# endpoint and event, this operation uses the currently
|
|
40
|
+
# defined app id for the operation, then returns the
|
|
41
|
+
# resulting dictionary to the caller method
|
|
42
|
+
result = self.post(
|
|
43
|
+
self.base_url + "web_pushes",
|
|
44
|
+
params=dict(auth=auth_token, unsubscribe=unsubscribe),
|
|
45
|
+
data_j=dict(endpoint=endpoint, p256dh=p256dh, auth=auth, event=event),
|
|
46
|
+
)
|
|
47
|
+
return result
|
|
48
|
+
|
|
49
|
+
def delete_web_push(self, endpoint, event=None):
|
|
50
|
+
# runs the unsubscription operation for the provided
|
|
51
|
+
# endpoint, optionally filtered by event; this operation
|
|
52
|
+
# uses the currently defined app id for the operation,
|
|
53
|
+
# then returns the resulting dictionary to the caller method
|
|
54
|
+
endpoint_encoded = appier.legacy.quote(endpoint, safe="")
|
|
55
|
+
params = dict()
|
|
56
|
+
if event:
|
|
57
|
+
params["event"] = event
|
|
58
|
+
result = self.delete(
|
|
59
|
+
self.base_url + "web_pushes/%s" % endpoint_encoded, params=params
|
|
60
|
+
)
|
|
61
|
+
return result
|
|
62
|
+
|
|
63
|
+
def delete_web_pushes(self, endpoint):
|
|
64
|
+
# runs the unsubscription operation for all subscriptions
|
|
65
|
+
# associated with the provided endpoint, this is an alias
|
|
66
|
+
# for delete_web_push without an event filter
|
|
67
|
+
return self.delete_web_push(endpoint)
|
|
68
|
+
|
|
69
|
+
def list_web_pushes(self, endpoint=None, event=None):
|
|
70
|
+
# runs the list operation for the Web Push subscriptions
|
|
71
|
+
# with optional filtering by endpoint and/or event
|
|
72
|
+
params = dict()
|
|
73
|
+
if endpoint:
|
|
74
|
+
params["endpoint"] = endpoint
|
|
75
|
+
if event:
|
|
76
|
+
params["event"] = event
|
|
77
|
+
result = self.get(self.base_url + "web_pushes", params=params)
|
|
78
|
+
return result
|
|
79
|
+
|
|
80
|
+
def get_vapid_public_key(self):
|
|
81
|
+
# retrieves the VAPID public key for the current app,
|
|
82
|
+
# this key is needed by browsers to subscribe to push
|
|
83
|
+
# notifications using the Web Push API
|
|
84
|
+
result = self.get(self.base_url + "apps/vapid_key")
|
|
85
|
+
return result
|
|
86
|
+
|
|
87
|
+
def subscribe_web_push(self, *args, **kwargs):
|
|
88
|
+
return self.create_web_push(*args, **kwargs)
|
|
89
|
+
|
|
90
|
+
def unsubscribe_web_push(self, *args, **kwargs):
|
|
91
|
+
return self.delete_web_push(*args, **kwargs)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pushi
|
|
3
|
+
Version: 0.4.3
|
|
4
|
+
Summary: Pushi System API
|
|
5
|
+
Home-page: http://pushi.hive.pt
|
|
6
|
+
Author: Hive Solutions Lda.
|
|
7
|
+
Author-email: development@hive.pt
|
|
8
|
+
License: Apache License, Version 2.0
|
|
9
|
+
Keywords: pushi websocket
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Topic :: Utilities
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 2.6
|
|
16
|
+
Classifier: Programming Language :: Python :: 2.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.0
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.1
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.2
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.4
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.5
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
30
|
+
Requires-Dist: appier
|
|
31
|
+
Dynamic: author
|
|
32
|
+
Dynamic: author-email
|
|
33
|
+
Dynamic: classifier
|
|
34
|
+
Dynamic: home-page
|
|
35
|
+
Dynamic: keywords
|
|
36
|
+
Dynamic: license
|
|
37
|
+
Dynamic: requires-dist
|
|
38
|
+
Dynamic: summary
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
pushi/__init__.py,sha256=IQvc_g5jNMIhk4zVKriXmkiX1KDFPeEgbKLbVALLs4k,1351
|
|
2
|
+
pushi/apn.py,sha256=4puKNSPelGYiJx1FFTdvXgYXD-WNS4RPeyXWu3R3CDs,2193
|
|
3
|
+
pushi/app.py,sha256=QYED1UOjEV0wTeXUb65-Or8VgQKBCMJ4Md98DU1NeiQ,1973
|
|
4
|
+
pushi/base.py,sha256=jcSRW50x6eryJ94aYNGQgBrv5eVskCryT9hL3cMWnAA,5111
|
|
5
|
+
pushi/event.py,sha256=NGwyofq6aYpCWDPQUrnkcu6jUz5pL3aVprOORbBavIc,1857
|
|
6
|
+
pushi/subscription.py,sha256=eEWeVPcEKKIkKWPxquriTuSL0nhtjgrAl70OR1jcmPA,2151
|
|
7
|
+
pushi/web.py,sha256=KHGky4uea2IrfrLejYodYMrfw2KUN1sSm_YLgI4c6mw,2188
|
|
8
|
+
pushi/web_push.py,sha256=jTQfQFfLfs8_Z8wYMQiTiifEBN7kpfWpkYr761zauoQ,3563
|
|
9
|
+
pushi-0.4.3.dist-info/METADATA,sha256=ZjoXhR7rhNjJ38Rv_3VzcD0SLvnz6YRRgVXNhDalwx0,1399
|
|
10
|
+
pushi-0.4.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
+
pushi-0.4.3.dist-info/top_level.txt,sha256=EuDOnv7scnscLwsRnfhIJQcAP48nyBdbzYbrGNFT-3w,6
|
|
12
|
+
pushi-0.4.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pushi
|