-
Notifications
You must be signed in to change notification settings - Fork 1
/
RequestBuilder.py
38 lines (32 loc) · 1 KB
/
RequestBuilder.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
import json
import time
from urllib.parse import urlencode, quote_plus
class RequestBuilder:
def __init__(self):
pass
def buildPost(self, options, source_url='/', context=None):
return self.url_encode({
'source_url': source_url,
'data': json.dumps({
'options': options,
"context": context
}),
'_': '%s' % int(time.time() * 1000)
})
def buildGet(self, url, options, source_url='/', context=None):
data = self.url_encode({
'source_url': source_url,
'data': json.dumps({
'options': options,
"context": context
}),
'_': '%s' % int(time.time() * 1000)
})
return '{}/?{}'.format(url, data)
def url_encode(self, query):
if isinstance(query, str):
query = quote_plus(query)
else:
query = urlencode(query)
query = query.replace('+', '%20')
return query