-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostmanAPI.py
175 lines (138 loc) · 4.75 KB
/
PostmanAPI.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
https://docs.api.getpostman.com/
"""
import requests
class Collections:
def __init__(self, key):
self.key = key
self.apiUrl = 'https://api.getpostman.com'
def get_all(self):
url = self.apiUrl+'/collections'
headers ={'X-Api-Key': str(self.key)}
response = requests.get(url,headers=headers)
return response.json()
def get_single(self, collection_uid):
url = self.apiUrl +'/collections/'+collection_uid
headers ={'X-Api-Key': str(self.key)}
response = requests.get(url,headers=headers)
return response.json()
def post_create(self, data):
url = self.apiUrl +'/collections/'
headers ={'X-Api-Key': str(self.key), 'Content-Type': 'application/json'}
response = requests.post(url,headers=headers, data=data)
return response.json()
def put_update(self, collection_uid, data):
url = self.apiUrl +'/collections/'+collection_uid
headers ={'X-Api-Key': str(self.key), 'Content-Type': 'application/json'}
response = requests.put(url,headers=headers, data=data)
def del_delete(self, collection_uid):
url = self.apiUrl +'/collections/'+collection_uid
headers ={'X-Api-Key': str(self.key), 'Content-Type': 'application/json'}
response = requests.delete(url,headers=headers)
class Environments:
def __init__(self, key):
self.key = key
self.apiUrl = 'https://api.getpostman.com'
def get_all(self):
url = self.apiUrl +'/environments'
headers ={'X-Api-Key': self.key}
response = requests.get(url,headers=headers)
return response.json()
def get_single(self, environment_uid):
url = self.apiUrl +'/environments/'+environment_uid
headers ={'X-Api-Key': str(self.key)}
response = requests.get(url,headers=headers)
return response.json()
def post_create(self, name, urlApi):
url = self.apiUrl +'/environments/'
headers ={'X-Api-Key': str(self.key), 'Content-Type': 'application/json'}
data = '{"environment": { "name": "'+name+'", \
"values": [ \
{"key": "apiUrl", "value": "'+urlApi+'"} \
]\
}\
}'
response = requests.post(url,headers=headers, data=data)
def put_update(self):
pass
def del_delete(self,environments_uid):
url = self.apiUrl +'/environments/'+environments_uid
headers ={'X-Api-Key': str(self.key), 'Content-Type': 'application/json'}
response = requests.delete(url,headers=headers)
class Mocks:
def __init__(self, key):
self.key = key
self.apiUrl = 'https://api.getpostman.com'
def get_all(self):
url = self.apiUrl +'/mocks'
headers ={'X-Api-Key': self.key}
response = requests.get(url,headers=headers)
return response.json()
def get_single(self, mocks_uid):
url = self.apiUrl +'/mocks/'+mocks_uid
headers ={'X-Api-Key': str(self.key)}
response = requests.get(url,headers=headers)
return response.json()
def post_create(self, name, urlApi):
pass
def put_update(self):
pass
def del_delete(self,mocks_uid):
url = self.apiUrl +'/mocks/'+mocks_uid
headers ={'X-Api-Key': str(self.key), 'Content-Type': 'application/json'}
response = requests.delete(url,headers=headers)
class Monitors:
def __init__(self, key):
self.key = key
self.apiUrl = 'https://api.getpostman.com'
def get_all(self):
url = self.apiUrl +'/monitors'
headers ={'X-Api-Key': self.key}
response = requests.get(url,headers=headers)
return response.json()
def get_single(self, monitors_uid):
url = self.apiUrl +'/monitors/'+monitors_uid
headers ={'X-Api-Key': str(self.key)}
response = requests.get(url,headers=headers)
return response.json()
def post_create(self, name, urlApi):
pass
def put_update(self):
pass
def del_delete(self,monitors_uid):
url = self.apiUrl +'/monitors/'+monitors_uid
headers ={'X-Api-Key': str(self.key), 'Content-Type': 'application/json'}
response = requests.delete(url,headers=headers)
class Workspaces:
def __init__(self, key):
self.key = key
self.apiUrl = 'https://api.getpostman.com'
def get_all(self):
url = self.apiUrl +'/workspaces'
headers ={'X-Api-Key': self.key}
response = requests.get(url,headers=headers)
return response.json()
def get_single(self, workspaces_uid):
url = self.apiUrl +'/workspaces/'+workspaces_uid
headers ={'X-Api-Key': str(self.key)}
response = requests.get(url,headers=headers)
return response.json()
def post_create(self, name, urlApi):
pass
def put_update(self):
pass
def del_delete(self,workspaces_uid):
url = self.apiUrl +'/workspaces/'+workspaces_uid
headers ={'X-Api-Key': str(self.key), 'Content-Type': 'application/json'}
response = requests.delete(url,headers=headers)
class User:
def __init__(self, key):
self.key = key
self.apiUrl = 'https://api.getpostman.com'
def get_api_key_owner(self):
url = self.apiUrl +'/me'
headers ={'X-Api-Key': self.key}
response = requests.get(url,headers=headers)
return response.json()