-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
85 lines (71 loc) · 2.19 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import base64
import requests
from settings import HAPPY_FOX_KEY, HAPPY_FOX_PASSWORD
key_base = HAPPY_FOX_KEY+':'+HAPPY_FOX_PASSWORD
auth_key = base64.b64encode(key_base.encode()).decode('utf8')
headers = {'Authorization': 'Basic %s' % auth_key}
def search_kb(q):
url = 'https://consensyssupport.happyfox.com/api/1.1/json/kb/search/?q=%s' % q
r = requests.get(url, headers=headers)
if r.ok:
results = r.json()
else:
results = []
return results
def read_article(id):
url = 'https://consensyssupport.happyfox.com/api/1.1/json/kb/article/%s' % id
r = requests.get(url, headers=headers)
if r.ok:
results = r.json()
else:
results = None
return results
def read_ticket(id):
url = 'https://consensyssupport.happyfox.com/api/1.1/json/ticket/%s/' % id
r = requests.get(url, headers=headers)
if r.ok:
results = r.json()
else:
results = None
return results
def add_ticket(ticket, user):
url = 'https://consensyssupport.happyfox.com/api/1.1/json/tickets/'
data = {
'assignee': 10,
'subject': ticket.subject,
'text': ticket.text,
'category': 4,
'priority': 4,
'email': user.email,
'name': user.first_name+' '+user.last_name
}
r = requests.post(url, data=data, headers=headers)
if r.ok:
results = r.json()
else:
results = None
return results
def add_message(message, ticket, user):
if user.type == 'user':
print("Hello")
url = 'https://consensyssupport.happyfox.com/api/1.1/json/ticket/%s/user_reply/' % ticket.happy_fox_id
data = {
'user': user.happy_fox_id,
'client': user.happy_fox_id,
'text': message
}
elif user.type == 'provider':
url = 'https://consensyssupport.happyfox.com/api/1.1/json/ticket/%s/staff_update/' % ticket.happy_fox_id
data = {
'staff': 10,
'notify_user': 1,
'text': message
}
r = requests.post(url, data=data, headers=headers)
if r.ok:
results = r.json()
print(results)
else:
print(r.status_code)
results = None
return results