8000 Introduced user_agent · jakubactive/wc-api-python@fe1affb · GitHub
[go: up one dir, main page]

Skip to content

Commit fe1affb

Browse files
Introduced user_agent
Closes woocommerce#53
1 parent 2b7d894 commit fe1affb

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Options
5858
+-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+
5959
| ``query_string_auth`` | ``bool`` | no | Force Basic Authentication as query string when ``True`` and using under HTTPS, default is ``False`` |
6060
+-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+
61+
| ``user_agent`` | ``string`` | no | Set a custom User-Agent, default is ``WooCommerce-Python-REST-API/3.0.0`` |
62+
+-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+
6163
| ``oauth_timestamp`` | ``integer`` | no | Custom timestamp for requests made with oAuth1.0a |
6264
+-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+
6365
| ``wp_api`` | ``bool`` | no | Set to ``False`` in order to use the legacy WooCommerce API (deprecated) |

woocommerce/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self, url, consumer_key, consumer_secret, **kwargs):
3434
self.timeout = kwargs.get("timeout", 5)
3535
self.verify_ssl = kwargs.get("verify_ssl", True)
3636
self.query_string_auth = kwargs.get("query_string_auth", False)
37+
self.user_agent = kwargs.get("user_agent", f"WooCommerce-Python-REST-API/{__version__}")
3738

3839
def __is_ssl(self):
3940
""" Check if url use HTTPS """
@@ -72,7 +73,7 @@ def __request(self, method, endpoint, data, params=None, **kwargs):
7273
url = self.__get_url(endpoint)
7374
auth = None
7475
headers = {
75-
"user-agent": f"WooCommerce API {__version__}",
76+
"user-agent": f"{self.user_agent}",
7677
"accept": "application/json"
7778
}
7879

0 commit comments

Comments
 (0)
0