refactor: Simplify FrappeOAuth2Client
No need to override anything, use request.session in way it is intended.
This commit is contained in:
parent
54be05c18e
commit
4aa20c72c1
1 changed files with 5 additions and 34 deletions
|
|
@ -4,8 +4,6 @@ FrappeClient is a library that helps you connect with other frappe systems
|
|||
import base64
|
||||
import json
|
||||
|
||||
import requests
|
||||
|
||||
import frappe
|
||||
from frappe.utils.data import cstr
|
||||
|
||||
|
|
@ -37,6 +35,8 @@ class FrappeClient:
|
|||
api_secret=None,
|
||||
frappe_authorization_source=None,
|
||||
):
|
||||
import requests
|
||||
|
||||
self.headers = {
|
||||
"Accept": "application/json",
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
|
|
@ -390,42 +390,13 @@ class FrappeClient:
|
|||
|
||||
class FrappeOAuth2Client(FrappeClient):
|
||||
def __init__(self, url, access_token, verify=True):
|
||||
import requests
|
||||
|
||||
self.access_token = access_token
|
||||
self.headers = {
|
||||
"Authorization": "Bearer " + access_token,
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
}
|
||||
self.verify = verify
|
||||
self.session = OAuth2Session(self.headers)
|
||||
self.session = requests.session()
|
||||
self.url = url
|
||||
|
||||
def get_request(self, params):
|
||||
res = requests.get(
|
||||
self.url, params=self.preprocess(params), headers=self.headers, verify=self.verify
|
||||
)
|
||||
res = self.post_process(res)
|
||||
return res
|
||||
|
||||
def post_request(self, data):
|
||||
res = requests.post(
|
||||
self.url, data=self.preprocess(data), headers=self.headers, verify=self.verify
|
||||
)
|
||||
res = self.post_process(res)
|
||||
return res
|
||||
|
||||
|
||||
class OAuth2Session:
|
||||
def __init__(self, headers):
|
||||
self.headers = headers
|
||||
|
||||
def get(self, url, params, verify):
|
||||
res = requests.get(url, params=params, headers=self.headers, verify=verify)
|
||||
return res
|
||||
|
||||
def post(self, url, data, verify):
|
||||
res = requests.post(url, data=data, headers=self.headers, verify=verify)
|
||||
return res
|
||||
|
||||
def put(self, url, data, verify):
|
||||
res = requests.put(url, data=data, headers=self.headers, verify=verify)
|
||||
return res
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue