-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp1.py
executable file
·108 lines (94 loc) · 3.51 KB
/
http1.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#Copyright (c) 2015 Yodlee, Inc. All Rights Reserved.
# This software is the confidential and proprietary information of Yodlee, Inc.
# Use is subject to license terms.
import httplib, urllib #imports all the libraries in http and url
import json #library package for the json response access
import yaml #converts unicode to byte code
import requests #requests, for requesting the response from json
#debugging python step by step
#import pdb
#pdb.set_trace()
#that's it
class HTTP:
global headers
fqcn = "HTTP"
#<summary>
#cobrand login
#<param name="url"></param>
#<param name="requestBody"></param> cobrand user name and password
#<returns></returns>
@staticmethod
def doPost(url, requestBody):
mn = "docobrandlogin(POST : " + url + ", " + requestBody+" )"
#print(HTTP.fqcn + " :: " + mn)
resp = requests.post(url=url, data=requestBody)
data = json.loads(resp.text)
list_dump = json.dumps(data)
yaml.safe_load(list_dump)
return list_dump
#<summary>
#User login
#<param name="url"></param>
#<param name="sessionTokens(data)"></param> Authorization header (cobrand session id)
#<param name="requestBody"></param>user name and password
#<returns></returns>
@staticmethod
def doPostUser(url,hdr, requestBody):
mn = "douserlogin(POST : " + url + ", " + requestBody +" )"
#print(HTTP.fqcn + " :: " + mn)
#hdr = {'Authorization':'{cobSession='+cobSession+'}'}
resp= requests.post(url, data=requestBody, headers=hdr)
result = json.loads(resp.text)
list_dump = json.dumps(result)
yaml.safe_load(list_dump)
return list_dump
#<summary>
#Get Response
#<param name="url"></param>
#<param name="headers(data)"></param> Cobrand and user logins session id
#<returns></returns>
@staticmethod
def doGet(url, hdr):
mn = "doIO(GET :" + url+ ", headers = " + str(hdr) +" )";
#print(HTTP.fqcn + " :: " + mn)
resp= requests.get(url, headers=hdr)
result = json.loads(resp.text)
list_dump = json.dumps(result)
yaml.safe_load(list_dump)
return list_dump
@staticmethod
def doPut(url, loginForm, hdr):
mn = "doIO(PUT :" + url + ", headers = " + str(hdr) +" )"
#print(HTTP.fqcn + " :: " + mn)
resp= requests.put(url, data=loginForm, headers=hdr)
result = json.loads(resp.text)
list_dump = json.dumps(result)
yaml.safe_load(list_dump)
return list_dump
@staticmethod
def doPutAddAcc(url, loginForm, hdr):
mn = "doIO(PUT :" + url + ", headers = " + str(hdr) + " )"
# print(HTTP.fqcn + " :: " + mn)
resp = requests.put(url, params=loginForm, headers=hdr)
result = json.loads(resp.text)
list_dump = json.dumps(result)
yaml.safe_load(list_dump)
return list_dump
@staticmethod
def doPutProviderAcc(url, requestBody,hdr):
mn = "doIO(PUT :" + url + ", headers = " + str(hdr) +" )"
#print(HTTP.fqcn + " :: " + mn)
resp= requests.put(url, data=requestBody, headers=hdr)
result = json.loads(resp.text)
list_dump = json.dumps(result)
yaml.safe_load(list_dump)
return list_dump
@staticmethod
def doPostAddAcc(url, loginForm, hdr):
mn = "doIO(POST :" + url + ", headers = " + str(hdr) +" )"
#print(HTTP.fqcn + " :: " + mn)
resp= requests.post(url, data=loginForm, headers=hdr)
result = json.loads(resp.text)
list_dump = json.dumps(result)
yaml.safe_load(list_dump)
return list_dump