5
5
"""
6
6
7
7
__title__ = "woocommerce-api"
8
- __version__ = "2.1.1 "
8
+ __version__ = "2.1.2 "
9
9
__author__ = "Claudio Sanches @ Automattic"
10
10
__license__ = "MIT"
11
11
12
12
from requests import request
13
13
from json import dumps as jsonencode
14
14
from time import time
15
15
from woocommerce .oauth import OAuth
16
+ from requests .auth import HTTPBasicAuth
16
17
17
18
try :
18
19
from urllib .parse import urlencode
@@ -44,12 +45,12 @@ def __get_url(self, endpoint):
44
45
api = "wc-api"
45
46
46
47
if url .endswith ("/" ) is False :
47
- url = "%s/" % url
48
+ url = f" { url } /"
48
49
49
50
if self .wp_api :
50
51
api = "wp-json"
51
52
52
- return "%s%s/%s/%s" % ( url , api , self .version , endpoint )
53
+ return f" { url } { api } / { self .version } / { endpoint } "
53
54
54
55
def __get_oauth_url (self , url , method , ** kwargs ):
55
56
""" Generate oAuth1.0a URL """
@@ -71,20 +72,20 @@ def __request(self, method, endpoint, data, params=None, **kwargs):
71
72
url = self .__get_url (endpoint )
72
73
auth = None
73
74
headers = {
74
- "user-agent" : " WooCommerce API Client-Python/%s" % __version__ ,
75
+ "user-agent" : f' WooCommerce API { __version__ } ' ,
75
76
"accept" : "application/json"
76
77
}
77
78
78
79
if self .is_ssl is True and self .query_string_auth is False :
79
- auth = (self .consumer_key , self .consumer_secret )
80
+ auth = HTTPBasicAuth (self .consumer_key , self .consumer_secret )
80
81
elif self .is_ssl is True and self .query_string_auth is True :
81
82
params .update ({
82
83
"consumer_key" : self .consumer_key ,
83
84
"consumer_secret" : self .consumer_secret
84
85
})
85
86
else :
86
87
encoded_params = urlencode (params )
87
- url = "%s?%s" % ( url , encoded_params )
88
+ url = f" { url } ? { encoded_params } "
88
89
url = self .__get_oauth_url (url , method , ** kwargs )
89
90
90
91
if data is not None :
@@ -122,4 +123,3 @@ def delete(self, endpoint, **kwargs):
122
123
def options (self , endpoint , ** kwargs ):
123
124
""" OPTIONS requests """
124
125
return self .__request ("OPTIONS" , endpoint , None , ** kwargs )
125
-
0 commit comments