8000 Allow custom timestamps · RjGreens/wc-api-python@782a822 · GitHub
[go: up one dir, main page]

Skip to content

Commit 782a822

Browse files
Allow custom timestamps
Closes woocommerce#25
1 parent 4d79b1f commit 782a822

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

woocommerce/api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
"""
66

77
__title__ = "woocommerce-api"
8-
__version__ = "1.2.1"
9-
__author__ = "Claudio Sanches @ WooThemes"
8+
__version__ = "2.0.0"
9+
__author__ = "Claudio Sanches @ Automattic"
1010
__license__ = "MIT"
1111

1212
from requests import request
1313
from json import dumps as jsonencode
14+
from time import time
1415
from woocommerce.oauth import OAuth
1516

1617
try:
@@ -50,14 +51,15 @@ def __get_url(self, endpoint):
5051

5152
return "%s%s/%s/%s" % (url, api, self.version, endpoint)
5253

53-
def __get_oauth_url(self, url, method):
54+
def __get_oauth_url(self, url, method, **kwargs):
5455
""" Generate oAuth1.0a URL """
5556
oauth = OAuth(
5657
url=url,
5758
consumer_key=self.consumer_key,
5859
consumer_secret=self.consumer_secret,
5960
version=self.version,
60-
method=method
61+
method=method,
62+
oauth_timestamp=kwargs.get("oauth_timestamp", int(time()))
6163
)
6264

6365
return oauth.get_oauth_url()
@@ -83,7 +85,7 @@ def __request(self, method, endpoint, data, params=None, **kwargs):
8385
else:
8486
encoded_params = urlencode(params)
8587
url = "%s?%s" % (url, encoded_params)
86-
url = self.__get_oauth_url(url, method)
88+
url = self.__get_oauth_url(url, method, **kwargs)
8789

8890
if data is not None:
8991
data = jsonencode(data, ensure_ascii=False).encode('utf-8')

woocommerce/oauth.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"""
66

77
__title__ = "woocommerce-oauth"
8-
__version__ = "1.2.1"
9-
__author__ = "Claudio Sanches @ WooThemes"
8+
__version__ = "2.0.0"
9+
__author__ = "Claudio Sanches @ Automattic"
1010
__license__ = "MIT"
1111

1212
from time import time
@@ -36,6 +36,7 @@ def __init__(self, url, consumer_key, consumer_secret, **kwargs):
3636
self.consumer_secret = consumer_secret
3737
self.version = kwargs.get("version", "v3")
3838
self.method = kwargs.get("method", "GET")
39+
self.timestamp = kwargs.get("oauth_timestamp", int(time()))
3940

4041
def get_oauth_url(self):
4142
""" Returns the URL with OAuth params """
@@ -49,7 +50,7 @@ def get_oauth_url(self):
4950
url = self.url
5051

5152
params["oauth_consumer_key"] = self.consumer_key
52-
params["oauth_timestamp"] = int(time())
53+
params["oauth_timestamp"] = self.timestamp
5354
params["oauth_nonce"] = self.generate_nonce()
5455
params["oauth_signature_method"] = "HMAC-SHA256"
5556
params["oauth_signature"] = self.generate_oauth_signature(params, url)

0 commit comments

Comments
 (0)
0