Skip to content
This repository was archived by the owner on Jun 24, 2021. It is now read-only.

Commit 69a0e01

Browse files
author
Josh Wolff
committed
Testing releasEg
1 parent 1de06e7 commit 69a0e01

16 files changed

+179
-48
lines changed

.idea/workspace.xml

Lines changed: 60 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :vibration_mode: SPONTIT :vibration_mode:
1+
# SPONTIT :vibration_mode:
22
## Send push notifications without your own app. :punch:
33
Using the Spontit API and Spontit app/webapp, you can send your own push notifications programmatically to Android, iOS, and Desktop devices. You can send your own in less than 5 minutes. :sunglasses: :trophy: (Without touching Swift, Objective-C, Java, XCode, Android Studio, the App Store approval process... :dizzy_face:).
44

build/lib/spontit/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from spontit.resource import SpontitResource

build/lib/spontit/resource.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from spontit import util
2+
from enum import Enum
3+
import json
4+
5+
6+
class SpontitResource:
7+
"""
8+
Use this resource to access your account and related functions.
9+
"""
10+
class FunctionStrings(Enum):
11+
"""
12+
An mapping of function to string. For internal use.
13+
"""
14+
GET_TOPIC_ID_TO_DISPLAY_NAME_MAPPING = "get_topic_id_to_display_name_mapping"
15+
PUSH = "push"
16+
17+
def __init__(self, user_id, secret_key):
18+
"""
19+
Initializes the resource.
20+
:param user_id: Your user ID.
21+
:param secret_key: A secret key you generated on spontit.com/secret_keys
22+
"""
23+
if type(user_id) is not str:
24+
raise Exception("User ID must be a string.")
25+
if type(secret_key) is not str:
26+
raise Exception("Secret key must be a string.")
27+
self.user_id = user_id
28+
self.secret_key = secret_key
29+
30+
def __get_payload_dict(self, method_str):
31+
"""
32+
Constructs a basic payload dictionary for the method string passed. To be sent with the put request.
33+
:param method_str: The string representing the method in consideration.
34+
:return: The payload dictionary
35+
"""
36+
if type(method_str) is SpontitResource.FunctionStrings:
37+
method_str = method_str.value
38+
print(type(method_str))
39+
assert type(method_str) is str
40+
return {
41+
'user_id': self.user_id,
42+
'secret_key': self.secret_key,
43+
'method': method_str
44+
}
45+
46+
def get_topic_id_to_display_name_mapping(self):
47+
"""
48+
Sends a put request requesting the topic IDs associated with the user account. You can access the list of topic
49+
IDs by getting the .keys() of the dictionary returned.
50+
:return: Returns either a mapping or an error description (with the key "Error")
51+
"""
52+
return util.put_request(self.__get_payload_dict(self.FunctionStrings.GET_TOPIC_ID_TO_DISPLAY_NAME_MAPPING))
53+
54+
def push(self,
55+
call_to_action,
56+
link=None,
57+
to_topic_ids=None):
58+
"""
59+
Use this method to send your own push notification!
60+
:param call_to_action: The message that you would like to push.
61+
:param link: [OPTIONAL] A link for content you would like to attach to the push notification
62+
:param to_topic_ids: [OPTIONAL] A list of topic IDS you would like to push to. If to_topic_ids is not specified,
63+
then the push notification will be sent to the main channel.
64+
:return: Returns either a success response or an error description (with the key "Error")
65+
"""
66+
# Construct the payload.
67+
payload = self.__get_payload_dict(self.FunctionStrings.PUSH)
68+
69+
# Type check call_to_action and add to payload.
70+
if type(call_to_action) is not str:
71+
raise Exception("Content must be a string.")
72+
payload["call_to_action"] = call_to_action
73+
74+
# If link exists, type check and add to payload.
75+
if link is not None:
76+
if type(link) is not str:
77+
raise Exception("URL must be formatted as a string.")
78+
payload["link"] = link
79+
80+
# If topic IDs exist, type check and add to payload.
81+
if to_topic_ids is not None:
82+
if type(to_topic_ids) is set:
83+
to_topic_ids = list(to_topic_ids)
84+
if type(to_topic_ids) is not list:
85+
raise Exception("The list of topic IDs passed must be a set or a list.")
86+
payload["to_topic_ids"] = json.dumps(to_topic_ids)
87+
# Send the put request and return the content.
88+
return util.put_request(payload)

build/lib/spontit/util.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import requests
2+
import json
3+
4+
5+
def put_request(payload):
6+
"""
7+
8+
:param payload:
9+
:return:
10+
"""
11+
r = requests.post("https://www.spontit.com/api", data=payload, json=payload)
12+
print(r.status_code)
13+
if str(r.status_code) != "200":
14+
return {
15+
"Error": "Internal Server Error"
16+
}
17+
json_content = json.loads(r.content)
18+
print(json_content)
19+
return json_content

dist/spontit-0.0.1-py3-none-any.whl

-6.38 KB
Binary file not shown.

dist/spontit-0.0.1.tar.gz

-5.19 KB
Binary file not shown.

dist/spontit-0.0.3-py3-none-any.whl

8.16 KB
Binary file not shown.

dist/spontit-0.0.3.tar.gz

5.31 KB
Binary file not shown.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setuptools.setup(
99
name="spontit",
10-
version="0.0.1",
10+
version="0.0.3",
1111
author="Spontit Inc",
1212
author_email="info@spontit.io",
1313
description="Send your own mobile push notifications.",

0 commit comments

Comments
 (0)