From bb7d82aa54ff7a2e30f233d54de05f912b6bfa0e Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 9 May 2016 19:37:34 -0300 Subject: [PATCH 01/63] Added method for HTTP OPTIONS requests --- README.rst | 2 +- woocommerce/api.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 034a9cb..d755c34 100644 --- a/README.rst +++ b/README.rst @@ -54,7 +54,7 @@ Options +--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``timeout`` | ``integer`` | no | Connection timeout, default is ``5`` | +--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``verify_ssl`` | ``bool`` | no | Verify SSL when connect, use this option as ``false`` when need to test with self-signed certificates | +| ``verify_ssl`` | ``bool`` | no | Verify SSL when connect, use this option as ``False`` when need to test with self-signed certificates | +--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ Methods diff --git a/woocommerce/api.py b/woocommerce/api.py index f5d6e80..7bbc41f 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -94,3 +94,7 @@ def put(self, endpoint, data): def delete(self, endpoint): """ DELETE requests """ return self.__request("DELETE", endpoint, None) + + def options(self, endpoint): + """ OPTIONS requests """ + return self.__request("OPTIONS", endpoint, None) From 9202c44034c01be98b77ee7c28bd1b4eac4884bc Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 9 May 2016 19:40:10 -0300 Subject: [PATCH 02/63] Added support for WP REST API --- woocommerce/api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index 7bbc41f..2831d57 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -21,6 +21,7 @@ def __init__(self, url, consumer_key, consumer_secret, **kwargs): self.url = url self.consumer_key = consumer_key self.consumer_secret = consumer_secret + self.wp_api = kwargs.get("wp_api", False) self.version = kwargs.get("version", "v3") self.is_ssl = self.__is_ssl() self.timeout = kwargs.get("timeout", 5) @@ -33,11 +34,15 @@ def __is_ssl(self): def __get_url(self, endpoint): """ Get URL for requests """ url = self.url + api = "wc-api" if url.endswith("/") is False: url = "%s/" % url - return "%swc-api/%s/%s" % (url, self.version, endpoint) + if self.wp_api: + api = "wp-json" + + return "%s%s/%s/%s" % (url, api, self.version, endpoint) def __get_oauth_url(self, url, method): """ Generate oAuth1.0a URL """ From bbc2574b7f916cf5783266362415c04efecfbcd5 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 9 May 2016 19:45:22 -0300 Subject: [PATCH 03/63] Version 1.1.0 --- README.rst | 28 ++++++++++++++++++++++++++++ woocommerce/__init__.py | 2 +- woocommerce/api.py | 2 +- woocommerce/oauth.py | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index d755c34..6324de5 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,8 @@ Check out the WooCommerce API endpoints and data that can be manipulated in http Setup ----- +Setup for the old WooCommerce API v3: + .. code-block:: python from woocommerce import API @@ -37,6 +39,19 @@ Setup consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ) +Setup for the new WP REST API integration: + +.. code-block:: python + + from woocommerce import API + + wcapi = API( + url="http://example.com", + consumer_key="ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + wp_api=True, + version="wc/v1" + ) Options ~~~~~~~ @@ -50,6 +65,8 @@ Options +--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``consumerSecret`` | ``string`` | yes | Your API consumer secret | +--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``wp_api`` | ``bool`` | no | Allow requests to the WP REST API | ++--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``version`` | ``string`` | no | API version, default is ``v3`` | +--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``timeout`` | ``integer`` | no | Connection timeout, default is ``5`` | @@ -88,6 +105,11 @@ DELETE - ``.delete(endpoint)`` +OPTIONS +~~~~~~~ + +- ``.options(endpoint)`` + Response -------- @@ -113,6 +135,12 @@ Example of returned data: Changelog --------- +1.1.0 - 2016/05/09 +~~~~~~~~~~~~~~~~~~ + +- Added support for WP REST API. +- Added method to do HTTP OPTIONS requests. + 1.0.5 - 2015/12/07 ~~~~~~~~~~~~~~~~~~ diff --git a/woocommerce/__init__.py b/woocommerce/__init__.py index 82d09b8..284b445 100644 --- a/woocommerce/__init__.py +++ b/woocommerce/__init__.py @@ -10,7 +10,7 @@ """ __title__ = "woocommerce" -__version__ = "1.0.5" +__version__ = "1.1.0" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" diff --git a/woocommerce/api.py b/woocommerce/api.py index 2831d57..4ed690e 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-api" -__version__ = "1.0.5" +__version__ = "1.1.0" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" diff --git a/woocommerce/oauth.py b/woocommerce/oauth.py index da49259..79aa4e9 100644 --- a/woocommerce/oauth.py +++ b/woocommerce/oauth.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-oauth" -__version__ = "1.0.5" +__version__ = "1.1.0" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" From 9a9192440225e6a641c913302c218a6a0995c87c Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 3 Jun 2016 13:41:23 -0300 Subject: [PATCH 04/63] Fixed oAuth signature for WP REST API --- woocommerce/oauth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce/oauth.py b/woocommerce/oauth.py index 79aa4e9..4e62779 100644 --- a/woocommerce/oauth.py +++ b/woocommerce/oauth.py @@ -73,7 +73,7 @@ def generate_oauth_signature(self, params, url): string_to_sign = "%s&%s&%s" % (self.method, base_request_uri, query_string) consumer_secret = str(self.consumer_secret) - if self.version == "v3": + if self.version not in ["v1", "v2"]: consumer_secret += "&" hash_signature = HMAC( From 429705854304b1cef247713d2ed468dc1cb62e08 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 3 Jun 2016 13:43:08 -0300 Subject: [PATCH 05/63] Version 1.1.1 --- README.rst | 5 +++++ woocommerce/__init__.py | 2 +- woocommerce/api.py | 2 +- woocommerce/oauth.py | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 6324de5..bae61a7 100644 --- a/README.rst +++ b/README.rst @@ -135,6 +135,11 @@ Example of returned data: Changelog --------- +1.1.1 - 2016/06/03 +~~~~~~~~~~~~~~~~~~ + +- Fixed oAuth signature for WP REST API. + 1.1.0 - 2016/05/09 ~~~~~~~~~~~~~~~~~~ diff --git a/woocommerce/__init__.py b/woocommerce/__init__.py index 284b445..06d22e8 100644 --- a/woocommerce/__init__.py +++ b/woocommerce/__init__.py @@ -10,7 +10,7 @@ """ __title__ = "woocommerce" -__version__ = "1.1.0" +__version__ = "1.1.1" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" diff --git a/woocommerce/api.py b/woocommerce/api.py index 4ed690e..f7cd0f4 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-api" -__version__ = "1.1.0" +__version__ = "1.1.1" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" diff --git a/woocommerce/oauth.py b/woocommerce/oauth.py index 4e62779..1a73fa0 100644 --- a/woocommerce/oauth.py +++ b/woocommerce/oauth.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-oauth" -__version__ = "1.1.0" +__version__ = "1.1.1" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" From 08d51977f3ab54aa26760ab466ca587ed6c68e5f Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 8 Jun 2016 17:02:08 -0300 Subject: [PATCH 06/63] Added note about wp_api is only for 2.6 or later --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index bae61a7..2099f4a 100644 --- a/README.rst +++ b/README.rst @@ -39,7 +39,7 @@ Setup for the old WooCommerce API v3: consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ) -Setup for the new WP REST API integration: +Setup for the new WP REST API integration (WooCommerce 2.6 or later): .. code-block:: python @@ -65,7 +65,7 @@ Options +--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``consumerSecret`` | ``string`` | yes | Your API consumer secret | +--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``wp_api`` | ``bool`` | no | Allow requests to the WP REST API | +| ``wp_api`` | ``bool`` | no | Allow requests to the WP REST API (WooCommerce 2.6 or later) | +--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``version`` | ``string`` | no | API version, default is ``v3`` | +--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ From 83921db6cb58c637475798b22083e1037f187f84 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 22 Jun 2016 20:24:58 -0300 Subject: [PATCH 07/63] Allow basic auth as query strings --- woocommerce/api.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index f7cd0f4..4cd4eaf 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -26,6 +26,7 @@ def __init__(self, url, consumer_key, consumer_secret, **kwargs): self.is_ssl = self.__is_ssl() self.timeout = kwargs.get("timeout", 5) self.verify_ssl = kwargs.get("verify_ssl", True) + self.query_string_auth = kwargs.get("query_string_auth", False) def __is_ssl(self): """ Check if url use HTTPS """ @@ -60,14 +61,20 @@ def __request(self, method, endpoint, data): """ Do requests """ url = self.__get_url(endpoint) auth = None + params = {} headers = { "user-agent": "WooCommerce API Client-Python/%s" % __version__, "content-type": "application/json;charset=utf-8", "accept": "application/json" } - if self.is_ssl is True: + if self.is_ssl is True and self.query_string_auth is False: auth = (self.consumer_key, self.consumer_secret) + elif self.is_ssl is True and self.query_string_auth is True: + params = { + "consumer_key": self.consumer_key, + "consumer_secret": self.consumer_secret + } else: url = self.__get_oauth_url(url, method) @@ -79,6 +86,7 @@ def __request(self, method, endpoint, data): url=url, verify=self.verify_ssl, auth=auth, + params=params, data=data, timeout=self.timeout, headers=headers From bf75d38ea2b7b2c4b918bf68a9fb42847e0f5a6f Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 22 Jun 2016 20:29:50 -0300 Subject: [PATCH 08/63] Version 1.2.0 --- README.rst | 41 ++++++++++++++++++++++++----------------- woocommerce/__init__.py | 2 +- woocommerce/api.py | 2 +- woocommerce/oauth.py | 2 +- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/README.rst b/README.rst index 2099f4a..052331c 100644 --- a/README.rst +++ b/README.rst @@ -56,23 +56,25 @@ Setup for the new WP REST API integration (WooCommerce 2.6 or later): Options ~~~~~~~ -+--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| Option | Type | Required | Description | -+====================+=============+==========+=======================================================================================================+ -| ``url`` | ``string`` | yes | Your Store URL, example: http://woo.dev/ | -+--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``consumerKey`` | ``string`` | yes | Your API consumer key | -+--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``consumerSecret`` | ``string`` | yes | Your API consumer secret | -+--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``wp_api`` | ``bool`` | no | Allow requests to the WP REST API (WooCommerce 2.6 or later) | -+--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``version`` | ``string`` | no | API version, default is ``v3`` | -+--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``timeout`` | ``integer`` | no | Connection timeout, default is ``5`` | -+--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``verify_ssl`` | ``bool`` | no | Verify SSL when connect, use this option as ``False`` when need to test with self-signed certificates | -+--------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| Option | Type | Required | Description | ++=======================+=============+==========+=======================================================================================================+ +| ``url`` | ``string`` | yes | Your Store URL, example: http://woo.dev/ | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``consumerKey`` | ``string`` | yes | Your API consumer key | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``consumerSecret`` | ``string`` | yes | Your API consumer secret | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``wp_api`` | ``bool`` | no | Allow requests to the WP REST API (WooCommerce 2.6 or later) | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``version`` | ``string`` | no | API version, default is ``v3`` | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``timeout`` | ``integer`` | no | Connection timeout, default is ``5`` | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``verify_ssl`` | ``bool`` | no | Verify SSL when connect, use this option as ``False`` when need to test with self-signed certificates | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``query_string_auth`` | ``bool`` | no | Force Basic Authentication as query string when ``True`` and using under HTTPS, default is ``False`` | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ Methods ------- @@ -135,6 +137,11 @@ Example of returned data: Changelog --------- +1.2.0 - 2016/06/22 +~~~~~~~~~~~~~~~~~~ + +- Added option ``query_string_auth`` to allow Basic Auth as query strings. + 1.1.1 - 2016/06/03 ~~~~~~~~~~~~~~~~~~ diff --git a/woocommerce/__init__.py b/woocommerce/__init__.py index 06d22e8..76fd0f3 100644 --- a/woocommerce/__init__.py +++ b/woocommerce/__init__.py @@ -10,7 +10,7 @@ """ __title__ = "woocommerce" -__version__ = "1.1.1" +__version__ = "1.2.0" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" diff --git a/woocommerce/api.py b/woocommerce/api.py index 4cd4eaf..31d0e49 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-api" -__version__ = "1.1.1" +__version__ = "1.2.0" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" diff --git a/woocommerce/oauth.py b/woocommerce/oauth.py index 1a73fa0..a53739f 100644 --- a/woocommerce/oauth.py +++ b/woocommerce/oauth.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-oauth" -__version__ = "1.1.1" +__version__ = "1.2.0" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" From b248bb8b718907a80eb911b06832fe6fc650fd5c Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 28 Sep 2016 09:14:28 -0300 Subject: [PATCH 09/63] woothemes to woocommerce --- LICENSE.txt | 2 +- README.rst | 8 ++++---- setup.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 0ac4ac5..8b3652e 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015, WooThemes (http://www.woothemes.com/) +Copyright (c) 2015, WooThemes (https://woocommerce.com/) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.rst b/README.rst index 052331c..eed4df7 100644 --- a/README.rst +++ b/README.rst @@ -3,8 +3,8 @@ WooCommerce API - Python Client A Python wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library. -.. image:: https://secure.travis-ci.org/woothemes/wc-api-python.svg - :target: http://travis-ci.org/woothemes/wc-api-python +.. image:: https://secure.travis-ci.org/woocommerce/wc-api-python.svg + :target: http://travis-ci.org/woocommerce/wc-api-python .. image:: https://img.shields.io/pypi/v/woocommerce.svg :target: https://pypi.python.org/pypi/WooCommerce @@ -20,9 +20,9 @@ Installation Getting started --------------- -Generate API credentials (Consumer Key & Consumer Secret) following this instructions http://docs.woothemes.com/document/woocommerce-rest-api/. +Generate API credentials (Consumer Key & Consumer Secret) following this instructions http://docs.woocommerce.com/document/woocommerce-rest-api/. -Check out the WooCommerce API endpoints and data that can be manipulated in http://woothemes.github.io/woocommerce-rest-api-docs/. +Check out the WooCommerce API endpoints and data that can be manipulated in http://woocommerce.github.io/woocommerce-rest-api-docs/. Setup ----- diff --git a/setup.py b/setup.py index 169e6df..5901b0b 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ description="A Python wrapper for the WooCommerce REST API", long_description=README, author="Claudio Sanches @ WooThemes", - url="https://github.com/woothemes/wc-api-python", + url="https://github.com/woocommerce/wc-api-python", license="MIT License", packages=[ "woocommerce" From 01b5000f58b262e79af0f37ec38730f4a1a0e9f0 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 14 Dec 2016 16:35:15 -0200 Subject: [PATCH 10/63] Fixed WordPress 4.7 compatibility, closes #23 --- woocommerce/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index 31d0e49..218f164 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -64,7 +64,6 @@ def __request(self, method, endpoint, data): params = {} headers = { "user-agent": "WooCommerce API Client-Python/%s" % __version__, - "content-type": "application/json;charset=utf-8", "accept": "application/json" } @@ -80,6 +79,7 @@ def __request(self, method, endpoint, data): if data is not None: data = jsonencode(data, ensure_ascii=False).encode('utf-8') + headers["content-type"] = "application/json;charset=utf-8" return request( method=method, From bffe8d72d210826e1852efc6037d9560f716f514 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 14 Dec 2016 16:55:42 -0200 Subject: [PATCH 11/63] Version 1.2.1 --- README.rst | 5 +++++ setup.py | 6 +++--- woocommerce/__init__.py | 2 +- woocommerce/api.py | 2 +- woocommerce/oauth.py | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index eed4df7..5033d80 100644 --- a/README.rst +++ b/README.rst @@ -137,6 +137,11 @@ Example of returned data: Changelog --------- +1.2.1 - 2016/12/14 +~~~~~~~~~~~~~~~~~~ + +- Fixed WordPress 4.7 compatibility. + 1.2.0 - 2016/06/22 ~~~~~~~~~~~~~~~~~~ diff --git a/setup.py b/setup.py index 5901b0b..5712291 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ version=VERSION, description="A Python wrapper for the WooCommerce REST API", long_description=README, - author="Claudio Sanches @ WooThemes", + author="Claudio Sanches @ Automattic", url="https://github.com/woocommerce/wc-api-python", license="MIT License", packages=[ @@ -38,7 +38,7 @@ "requests", "ordereddict" ], - classifiers=( + classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Natural Language :: English", @@ -50,5 +50,5 @@ "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules" - ), + ], ) diff --git a/woocommerce/__init__.py b/woocommerce/__init__.py index 76fd0f3..7c4b16d 100644 --- a/woocommerce/__init__.py +++ b/woocommerce/__init__.py @@ -10,7 +10,7 @@ """ __title__ = "woocommerce" -__version__ = "1.2.0" +__version__ = "1.2.1" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" diff --git a/woocommerce/api.py b/woocommerce/api.py index 218f164..d15a179 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-api" -__version__ = "1.2.0" +__version__ = "1.2.1" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" diff --git a/woocommerce/oauth.py b/woocommerce/oauth.py index a53739f..2dd4696 100644 --- a/woocommerce/oauth.py +++ b/woocommerce/oauth.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-oauth" -__version__ = "1.2.0" +__version__ = "1.2.1" __author__ = "Claudio Sanches @ WooThemes" __license__ = "MIT" From f1bee0dcf8a698b75f5dfd9dffe9bf55ae6abfca Mon Sep 17 00:00:00 2001 From: Timothy Date: Sun, 28 Jan 2018 16:55:50 -0500 Subject: [PATCH 12/63] api accepts url params and additional keyword args for requests module Currently the url params that are sent to Woo-Commerce are a closed box. They should be exposed outside of the function. Additionally, there are cases where a developer needs to pass additional parameters to the requests library. These should also be exposed outside of the function. This pull request simply achieves these things. --- woocommerce/api.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index d15a179..83f3579 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -57,11 +57,12 @@ def __get_oauth_url(self, url, method): return oauth.get_oauth_url() - def __request(self, method, endpoint, data): + def __request(self, method, endpoint, data, params: dict=None, **kwargs): """ Do requests """ + if params is None: + params = {} url = self.__get_url(endpoint) auth = None - params = {} headers = { "user-agent": "WooCommerce API Client-Python/%s" % __version__, "accept": "application/json" @@ -70,10 +71,10 @@ def __request(self, method, endpoint, data): if self.is_ssl is True and self.query_string_auth is False: auth = (self.consumer_key, self.consumer_secret) elif self.is_ssl is True and self.query_string_auth is True: - params = { + params.update({ "consumer_key": self.consumer_key, "consumer_secret": self.consumer_secret - } + }) else: url = self.__get_oauth_url(url, method) @@ -89,25 +90,26 @@ def __request(self, method, endpoint, data): params=params, data=data, timeout=self.timeout, - headers=headers + headers=headers, + **kwargs ) - def get(self, endpoint): + def get(self, endpoint, **kwargs): """ Get requests """ - return self.__request("GET", endpoint, None) + return self.__request("GET", endpoint, None, **kwargs) - def post(self, endpoint, data): + def post(self, endpoint, data, **kwargs): """ POST requests """ - return self.__request("POST", endpoint, data) + return self.__request("POST", endpoint, data, **kwargs) - def put(self, endpoint, data): + def put(self, endpoint, data, **kwargs): """ PUT requests """ - return self.__request("PUT", endpoint, data) + return self.__request("PUT", endpoint, data, **kwargs) - def delete(self, endpoint): + def delete(self, endpoint, **kwargs): """ DELETE requests """ - return self.__request("DELETE", endpoint, None) + return self.__request("DELETE", endpoint, None, **kwargs) - def options(self, endpoint): + def options(self, endpoint, **kwargs): """ OPTIONS requests """ - return self.__request("OPTIONS", endpoint, None) + return self.__request("OPTIONS", endpoint, None, **kwargs) From c1b1cddb0a3776528ee2d468514d9b1fd06770de Mon Sep 17 00:00:00 2001 From: Timothy Date: Wed, 31 Jan 2018 22:57:34 -0500 Subject: [PATCH 13/63] removed type hint --- woocommerce/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index 83f3579..4b704b2 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -57,7 +57,7 @@ def __get_oauth_url(self, url, method): return oauth.get_oauth_url() - def __request(self, method, endpoint, data, params: dict=None, **kwargs): + def __request(self, method, endpoint, data, params=None, **kwargs): """ Do requests """ if params is None: params = {} From ee9a974c9a9c02f15664215d6c23dd9a60b88de4 Mon Sep 17 00:00:00 2001 From: Timothy Date: Wed, 31 Jan 2018 23:20:11 -0500 Subject: [PATCH 14/63] added tests for pull request --- tests.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests.py b/tests.py index ddae9df..8ab9ddb 100644 --- a/tests.py +++ b/tests.py @@ -79,6 +79,31 @@ def woo_test_mock(*args, **kwargs): status = self.api.get("products").status_code self.assertEqual(status, 200) + def test_get_with_parameters(self): + """ Test GET requests w/ url params """ + @all_requests + def woo_test_mock(*args, **kwargs): + return {'status_code': 200, + 'content': 'OK'} + + with HTTMock(woo_test_mock): + # call requests + status = self.api.get("products", params={'sku': 10001}).status_code + self.assertEqual(status, 200) + + def test_get_with_requests_kwargs(self): + """ Test GET requests w/ optional requests-module kwargs """ + + @all_requests + def woo_test_mock(*args, **kwargs): + return {'status_code': 200, + 'content': 'OK'} + + with HTTMock(woo_test_mock): + # call requests + status = self.api.get("products", timeout=60, allow_redirects=True).status_code + self.assertEqual(status, 200) + def test_post(self): """ Test POST requests """ @all_requests From c5d32a5aca9121763d168bdb21464fac2f6a8831 Mon Sep 17 00:00:00 2001 From: Timothy Date: Wed, 31 Jan 2018 23:38:05 -0500 Subject: [PATCH 15/63] timeout param is passed by default so this test breaks! --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index 8ab9ddb..57615b1 100644 --- a/tests.py +++ b/tests.py @@ -101,7 +101,7 @@ def woo_test_mock(*args, **kwargs): with HTTMock(woo_test_mock): # call requests - status = self.api.get("products", timeout=60, allow_redirects=True).status_code + status = self.api.get("products", allow_redirects=True).status_code self.assertEqual(status, 200) def test_post(self): From fb26c3a3bff83bb8b181ddbc7d3cd2cc3963bd8c Mon Sep 17 00:00:00 2001 From: Timothy Date: Wed, 31 Jan 2018 23:38:50 -0500 Subject: [PATCH 16/63] better example of using params for real-world usage --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index 57615b1..6c93b85 100644 --- a/tests.py +++ b/tests.py @@ -88,7 +88,7 @@ def woo_test_mock(*args, **kwargs): with HTTMock(woo_test_mock): # call requests - status = self.api.get("products", params={'sku': 10001}).status_code + status = self.api.get("products", params={"per_page": 10, "page": 1, "offset": 0}).status_code self.assertEqual(status, 200) def test_get_with_requests_kwargs(self): From 75184c57e63110c0a6979f83fd0a134fa80ececc Mon Sep 17 00:00:00 2001 From: "timjen3@gmail.com" Date: Mon, 16 Apr 2018 22:12:25 -0400 Subject: [PATCH 17/63] query string prepared for oauth sig --- .idea/workspace.xml | 148 ++++++++++++++++++++++++++++++++++++++++++++ woocommerce/api.py | 4 ++ 2 files changed, 152 insertions(+) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..cff0feb --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - 1523928868643 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 7c8ef2fef59f11ea20ad08fe961640f8a7ac344a Mon Sep 17 00:00:00 2001 From: "timjen3@gmail.com" Date: Mon, 16 Apr 2018 22:26:29 -0400 Subject: [PATCH 20/63] changed string format for python 2 compat --- woocommerce/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index 1a482c3..9886d5c 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -78,7 +78,7 @@ def __request(self, method, endpoint, data, params=None, **kwargs): }) else: encoded_params = urlencode(params) - url = "{url}?{params}".format(url=url, params=encoded_params) + url = "%s?%s" % (url, encoded_params) url = self.__get_oauth_url(url, method) if data is not None: From 787391250c3fd7d7446ecf830a2ab095b4697a75 Mon Sep 17 00:00:00 2001 From: "timjen3@gmail.com" Date: Mon, 16 Apr 2018 22:40:36 -0400 Subject: [PATCH 21/63] python 2 compat urlencode --- woocommerce/api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index 9886d5c..a9c1cb5 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -11,9 +11,13 @@ from requests import request from json import dumps as jsonencode -from urllib.parse import urlencode from woocommerce.oauth import OAuth +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode + class API(object): """ API Class """ From 4d79b1f6435b70d155aec90389a0682783825e1d Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 15 Jan 2019 16:42:53 -0200 Subject: [PATCH 22/63] Updated "Requests" version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d090df9..f337d8b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -requests==2.7.0 +requests==2.20.0 ordereddict==1.1 From 782a822be316a862ca7311405443793b38fc5dbd Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 15 Jan 2019 16:57:53 -0200 Subject: [PATCH 23/63] Allow custom timestamps Closes #25 --- woocommerce/api.py | 12 +++++++----- woocommerce/oauth.py | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index a9c1cb5..b6345fe 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -5,12 +5,13 @@ """ __title__ = "woocommerce-api" -__version__ = "1.2.1" -__author__ = "Claudio Sanches @ WooThemes" +__version__ = "2.0.0" +__author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" from requests import request from json import dumps as jsonencode +from time import time from woocommerce.oauth import OAuth try: @@ -50,14 +51,15 @@ def __get_url(self, endpoint): return "%s%s/%s/%s" % (url, api, self.version, endpoint) - def __get_oauth_url(self, url, method): + def __get_oauth_url(self, url, method, **kwargs): """ Generate oAuth1.0a URL """ oauth = OAuth( url=url, consumer_key=self.consumer_key, consumer_secret=self.consumer_secret, version=self.version, - method=method + method=method, + oauth_timestamp=kwargs.get("oauth_timestamp", int(time())) ) return oauth.get_oauth_url() @@ -83,7 +85,7 @@ def __request(self, method, endpoint, data, params=None, **kwargs): else: encoded_params = urlencode(params) url = "%s?%s" % (url, encoded_params) - url = self.__get_oauth_url(url, method) + url = self.__get_oauth_url(url, method, **kwargs) if data is not None: data = jsonencode(data, ensure_ascii=False).encode('utf-8') diff --git a/woocommerce/oauth.py b/woocommerce/oauth.py index 2dd4696..7e8877c 100644 --- a/woocommerce/oauth.py +++ b/woocommerce/oauth.py @@ -5,8 +5,8 @@ """ __title__ = "woocommerce-oauth" -__version__ = "1.2.1" -__author__ = "Claudio Sanches @ WooThemes" +__version__ = "2.0.0" +__author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" from time import time @@ -36,6 +36,7 @@ def __init__(self, url, consumer_key, consumer_secret, **kwargs): self.consumer_secret = consumer_secret self.version = kwargs.get("version", "v3") self.method = kwargs.get("method", "GET") + self.timestamp = kwargs.get("oauth_timestamp", int(time())) def get_oauth_url(self): """ Returns the URL with OAuth params """ @@ -49,7 +50,7 @@ def get_oauth_url(self): url = self.url params["oauth_consumer_key"] = self.consumer_key - params["oauth_timestamp"] = int(time()) + params["oauth_timestamp"] = self.timestamp params["oauth_nonce"] = self.generate_nonce() params["oauth_signature_method"] = "HMAC-SHA256" params["oauth_signature"] = self.generate_oauth_signature(params, url) From d6983dc5d86894ec47e709d0e6cd7ca79c7825c7 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 15 Jan 2019 17:07:08 -0200 Subject: [PATCH 24/63] Version 2.0.0 --- LICENSE.txt | 2 +- README.rst | 39 ++++++++++++++++++--------------------- woocommerce/__init__.py | 6 +++--- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 8b3652e..e6768bc 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015, WooThemes (https://woocommerce.com/) +Copyright (c) 2019, Automattic (https://woocommerce.com/) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.rst b/README.rst index 5033d80..39cb11e 100644 --- a/README.rst +++ b/README.rst @@ -20,27 +20,13 @@ Installation Getting started --------------- -Generate API credentials (Consumer Key & Consumer Secret) following this instructions http://docs.woocommerce.com/document/woocommerce-rest-api/. +Generate API credentials (Consumer Key & Consumer Secret) following this instructions http://woocommerce.github.io/woocommerce-rest-api-docs/#rest-api-keys. Check out the WooCommerce API endpoints and data that can be manipulated in http://woocommerce.github.io/woocommerce-rest-api-docs/. Setup ----- -Setup for the old WooCommerce API v3: - -.. code-block:: python - - from woocommerce import API - - wcapi = API( - url="http://example.com", - consumer_key="ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", - consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - ) - -Setup for the new WP REST API integration (WooCommerce 2.6 or later): - .. code-block:: python from woocommerce import API @@ -50,7 +36,7 @@ Setup for the new WP REST API integration (WooCommerce 2.6 or later): consumer_key="ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", wp_api=True, - version="wc/v1" + version="wc/v3" ) Options @@ -75,6 +61,8 @@ Options +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``query_string_auth`` | ``bool`` | no | Force Basic Authentication as query string when ``True`` and using under HTTPS, default is ``False`` | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``oauth_timestamp`` | ``integer`` | no | Custom timestamp for requests made with oAuth1.0a | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ Methods ------- @@ -86,31 +74,33 @@ Methods +--------------+----------------+------------------------------------------------------------------+ | ``data`` | ``dictionary`` | Data that will be converted to JSON | +--------------+----------------+------------------------------------------------------------------+ +| ``**kwargs`` | ``dictionary`` | Accepts ``params``, also other Requests arguments | ++--------------+----------------+------------------------------------------------------------------+ GET ~~~ -- ``.get(endpoint)`` +- ``.get(endpoint, **kwargs)`` POST ~~~~ -- ``.post(endpoint, data)`` +- ``.post(endpoint, data, **kwargs)`` PUT ~~~ -- ``.put(endpoint, data)`` +- ``.put(endpoint, data), **kwargs`` DELETE ~~~~~~ -- ``.delete(endpoint)`` +- ``.delete(endpoint, **kwargs)`` OPTIONS ~~~~~~~ -- ``.options(endpoint)`` +- ``.options(endpoint, **kwargs)`` Response -------- @@ -137,6 +127,13 @@ Example of returned data: Changelog --------- +2.0.0 - 2019/01/15 +~~~~~~~~~~~~~~~~~~ + +- Updated "Requests" library to version 2.20.0. +- Added support for custom timestamps in oAuth1.0a requests with ``oauth_timestamp``. +- Allow pass custom arguments to "Requests" library. + 1.2.1 - 2016/12/14 ~~~~~~~~~~~~~~~~~~ diff --git a/woocommerce/__init__.py b/woocommerce/__init__.py index 7c4b16d..86ddc6e 100644 --- a/woocommerce/__init__.py +++ b/woocommerce/__init__.py @@ -5,13 +5,13 @@ ~~~~~~~~~~~~~~~ A Python wrapper for WooCommerce API. -:copyright: (c) 2015 by WooThemes. +:copyright: (c) 2019 by Automattic. :license: MIT, see LICENSE for details. """ __title__ = "woocommerce" -__version__ = "1.2.1" -__author__ = "Claudio Sanches @ WooThemes" +__version__ = "2.0.0" +__author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" from woocommerce.api import API From 91e8ad7258a33c9d7d9a1228a71c02f3be5b798f Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 15 Jan 2019 17:25:26 -0200 Subject: [PATCH 25/63] Fixed readme.txt --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 39cb11e..042ce5c 100644 --- a/README.rst +++ b/README.rst @@ -61,7 +61,7 @@ Options +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``query_string_auth`` | ``bool`` | no | Force Basic Authentication as query string when ``True`` and using under HTTPS, default is ``False`` | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``oauth_timestamp`` | ``integer`` | no | Custom timestamp for requests made with oAuth1.0a | +| ``oauth_timestamp`` | ``integer`` | no | Custom timestamp for requests made with oAuth1.0a | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ Methods From 9be235831424140607bfe85092160731be999c7f Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 15 Jan 2019 17:36:47 -0200 Subject: [PATCH 26/63] Use WooCommerce REST API v3 by default --- woocommerce/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index b6345fe..da81e81 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-api" -__version__ = "2.0.0" +__version__ = "2.1.0" __author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" @@ -27,8 +27,8 @@ def __init__(self, url, consumer_key, consumer_secret, **kwargs): self.url = url self.consumer_key = consumer_key self.consumer_secret = consumer_secret - self.wp_api = kwargs.get("wp_api", False) - self.version = kwargs.get("version", "v3") + self.wp_api = kwargs.get("wp_api", True) + self.version = kwargs.get("version", "wc/v3") self.is_ssl = self.__is_ssl() self.timeout = kwargs.get("timeout", 5) self.verify_ssl = kwargs.get("verify_ssl", True) From 82316ee95689d58bc50fec1da60b809d4a2013f5 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 15 Jan 2019 17:38:09 -0200 Subject: [PATCH 27/63] Version 2.1.0 --- README.rst | 17 +++++++++++------ woocommerce/__init__.py | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 042ce5c..f80a63f 100644 --- a/README.rst +++ b/README.rst @@ -35,7 +35,6 @@ Setup url="http://example.com", consumer_key="ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", - wp_api=True, version="wc/v3" ) @@ -47,13 +46,11 @@ Options +=======================+=============+==========+=======================================================================================================+ | ``url`` | ``string`` | yes | Your Store URL, example: http://woo.dev/ | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``consumerKey`` | ``string`` | yes | Your API consumer key | +| ``consumer_key`` | ``string`` | yes | Your API consumer key | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``consumerSecret`` | ``string`` | yes | Your API consumer secret | +| ``consumer_secret`` | ``string`` | yes | Your API consumer secret | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``wp_api`` | ``bool`` | no | Allow requests to the WP REST API (WooCommerce 2.6 or later) | -+-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``version`` | ``string`` | no | API version, default is ``v3`` | +| ``version`` | ``string`` | no | API version, default is ``wc/v3`` | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``timeout`` | ``integer`` | no | Connection timeout, default is ``5`` | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ @@ -63,6 +60,8 @@ Options +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``oauth_timestamp`` | ``integer`` | no | Custom timestamp for requests made with oAuth1.0a | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``wp_api`` | ``bool`` | no | Set to false in order to use the legacy WooCommerce API (deprecated) | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ Methods ------- @@ -127,6 +126,12 @@ Example of returned data: Changelog --------- +2.1.0 - 2019/01/15 +~~~~~~~~~~~~~~~~~~ + +- Uses WP REST API by default, need to force ``wp_api`` as ``False`` to in order to use the legacy WooCommerce API. +- Updated default REST API version to ``wc/v3``. + 2.0.0 - 2019/01/15 ~~~~~~~~~~~~~~~~~~ diff --git a/woocommerce/__init__.py b/woocommerce/__init__.py index 86ddc6e..3d2bc17 100644 --- a/woocommerce/__init__.py +++ b/woocommerce/__init__.py @@ -10,7 +10,7 @@ """ __title__ = "woocommerce" -__version__ = "2.0.0" +__version__ = "2.1.0" __author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" From 4f8932b158f1ab9ff83d98e6bf6eeb10f0935bda Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 15 Jan 2019 17:39:02 -0200 Subject: [PATCH 28/63] Updated readme --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index f80a63f..fd17bd4 100644 --- a/README.rst +++ b/README.rst @@ -60,7 +60,7 @@ Options +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``oauth_timestamp`` | ``integer`` | no | Custom timestamp for requests made with oAuth1.0a | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ -| ``wp_api`` | ``bool`` | no | Set to false in order to use the legacy WooCommerce API (deprecated) | +| ``wp_api`` | ``bool`` | no | Set to ``False`` in order to use the legacy WooCommerce API (deprecated) | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ Methods From a36cbd88e445ec5ddb4b1d43882aa03459098ff1 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 15 Jan 2019 17:41:33 -0200 Subject: [PATCH 29/63] Fixed a typo --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index fd17bd4..6b7da2c 100644 --- a/README.rst +++ b/README.rst @@ -129,7 +129,7 @@ Changelog 2.1.0 - 2019/01/15 ~~~~~~~~~~~~~~~~~~ -- Uses WP REST API by default, need to force ``wp_api`` as ``False`` to in order to use the legacy WooCommerce API. +- Uses WP REST API by default, need to force ``wp_api`` as ``False`` in order to use the legacy WooCommerce API. - Updated default REST API version to ``wc/v3``. 2.0.0 - 2019/01/15 From 8bb57b7382c4900b7852a6a6a83750c93dc11883 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 16 Jan 2019 18:52:30 -0200 Subject: [PATCH 30/63] Fixed tests --- tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests.py b/tests.py index 6c93b85..c11759e 100644 --- a/tests.py +++ b/tests.py @@ -25,7 +25,7 @@ def test_version(self): consumer_secret=self.consumer_secret ) - self.assertEqual(api.version, "v3") + self.assertEqual(api.version, "wc/v3") def test_non_ssl(self): """ Test non-ssl """ @@ -37,7 +37,7 @@ def test_non_ssl(self): self.assertFalse(api.is_ssl) def test_with_ssl(self): - """ Test non-ssl """ + """ Test ssl """ api = woocommerce.API( url="https://woo.test", consumer_key=self.consumer_key, @@ -46,7 +46,7 @@ def test_with_ssl(self): self.assertTrue(api.is_ssl, True) def test_with_timeout(self): - """ Test non-ssl """ + """ Test timeout """ api = woocommerce.API( url="https://woo.test", consumer_key=self.consumer_key, From dee5065eaff2d200ef9883c25799ff605fe5e667 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 16 Jan 2019 18:53:05 -0200 Subject: [PATCH 31/63] Include python 2.6 from travis builds --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0a4416f..34dddca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - "2.6" - "2.7" - "3.2" - "3.3" From b7138db005b4c96fa07fa90c568bd4675fbdc730 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 22 Jul 2019 20:32:11 -0300 Subject: [PATCH 32/63] Ignore .vscode --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5b78e25..b542cee 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ dist/ *.egg-info/ run.py run3.py +.vscode/ From 0b67ae71761e63af286b0785a267c1799bc76173 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 22 Jul 2019 20:32:21 -0300 Subject: [PATCH 33/63] Added examples of doing requests with query params Closes #44 --- README.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.rst b/README.rst index 6b7da2c..ecd4f27 100644 --- a/README.rst +++ b/README.rst @@ -122,6 +122,26 @@ Example of returned data: >>> r.json() {u'products': [{u'sold_individually': False,... // Dictionary data +Request with `params` example +----------------------------- + +.. code-block:: python + + from woocommerce import API + + wcapi = API( + url="http://example.com", + consumer_key="ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + version="wc/v3" + ) + + # Force delete example. + print(wcapi.delete("products/100", params={"force": True}).json()) + + # Query example. + print(wcapi.get("products", params={"per_page": 20}).json()) + Changelog --------- From 1832a82d06e82c492850f952115c36e28ab65023 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 22 Jul 2019 20:37:22 -0300 Subject: [PATCH 34/63] Updated Python versions of Travis --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 34dddca..aa38de6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: python python: - "2.7" - - "3.2" - - "3.3" - - "3.4" + - "3.5" + - "3.6" + - "3.7" - "nightly" # command to install dependencies install: From d1f3fe12fe2dc0ea366ee583686a4fb5883ce38d Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 22 Jul 2019 20:39:54 -0300 Subject: [PATCH 35/63] Fix Travis Python versions --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aa38de6..d64c317 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: python python: - "2.7" + - "3.4" - "3.5" - "3.6" - - "3.7" - "nightly" # command to install dependencies install: From bc4a507a468ffe997599f50334ed411ba761adb8 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 22 Jul 2019 20:52:44 -0300 Subject: [PATCH 36/63] Updated dependencies --- requirements-test.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-test.txt b/requirements-test.txt index 5f4dc7e..00b7a73 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,3 +1,3 @@ -r requirements.txt -httmock==1.2.3 +httmock==1.3.0 nose==1.3.7 diff --git a/requirements.txt b/requirements.txt index f337d8b..93cf612 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -requests==2.20.0 +requests==2.22.0 ordereddict==1.1 From ddd613e98da0c1efc9ca2d614561e1715e44c141 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 22 Jul 2019 20:55:55 -0300 Subject: [PATCH 37/63] Drop support for Python 3.4 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d64c317..a8155d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: python python: - "2.7" - - "3.4" - "3.5" - "3.6" - "nightly" From e158f19ec8950e3e1b2b8032235e2051b6afd75f Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 22 Jul 2019 20:56:51 -0300 Subject: [PATCH 38/63] Version 2.1.1 --- setup.py | 7 +++---- woocommerce/__init__.py | 2 +- woocommerce/api.py | 2 +- woocommerce/oauth.py | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 5712291..04115ad 100644 --- a/setup.py +++ b/setup.py @@ -44,11 +44,10 @@ "Natural Language :: English", "License :: OSI Approved :: MIT License", "Programming Language :: Python", - "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3.2", - "Programming Language :: Python :: 3.3", - "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], ) diff --git a/woocommerce/__init__.py b/woocommerce/__init__.py index 3d2bc17..b1d6ec8 100644 --- a/woocommerce/__init__.py +++ b/woocommerce/__init__.py @@ -10,7 +10,7 @@ """ __title__ = "woocommerce" -__version__ = "2.1.0" +__version__ = "2.1.1" __author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" diff --git a/woocommerce/api.py b/woocommerce/api.py index da81e81..f0f4206 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-api" -__version__ = "2.1.0" +__version__ = "2.1.1" __author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" diff --git a/woocommerce/oauth.py b/woocommerce/oauth.py index 7e8877c..6b5538e 100644 --- a/woocommerce/oauth.py +++ b/woocommerce/oauth.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-oauth" -__version__ = "2.0.0" +__version__ = "2.1.1" __author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" From 933a0fab3018f4ef89d2708cb8f7e6d64808b630 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 22 Jul 2019 20:59:29 -0300 Subject: [PATCH 39/63] 2.1.1 changelog --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index ecd4f27..8d30583 100644 --- a/README.rst +++ b/README.rst @@ -146,6 +146,12 @@ Request with `params` example Changelog --------- +2.1.1 - 2019/07/22 +~~~~~~~~~~~~~~~~~~ + +- Updated Request library to 2.22.0. +- Updated examples. + 2.1.0 - 2019/01/15 ~~~~~~~~~~~~~~~~~~ From b6d08cf245c3b9aabe71e03baaa501734bb06114 Mon Sep 17 00:00:00 2001 From: Evert Arends Date: Tue, 6 Oct 2020 14:44:38 +0200 Subject: [PATCH 40/63] Updated standards and fixed problems with python 3.8 - Updated version - Removed percentage operator in favor of f-strings - Added HTTPBasicAuth to auth for stricter reading - Removed python from HTTPBasicAuth header, to make this API work with the latest version of python. --- woocommerce/api.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index f0f4206..f16642f 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-api" -__version__ = "2.1.1" +__version__ = "2.1.2" __author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" @@ -13,6 +13,7 @@ from json import dumps as jsonencode from time import time from woocommerce.oauth import OAuth +from requests.auth import HTTPBasicAuth try: from urllib.parse import urlencode @@ -44,12 +45,12 @@ def __get_url(self, endpoint): api = "wc-api" if url.endswith("/") is False: - url = "%s/" % url + url = f"{url}/" if self.wp_api: api = "wp-json" - return "%s%s/%s/%s" % (url, api, self.version, endpoint) + return f"{url}{api}/{self.version}/{endpoint}" def __get_oauth_url(self, url, method, **kwargs): """ Generate oAuth1.0a URL """ @@ -71,12 +72,12 @@ def __request(self, method, endpoint, data, params=None, **kwargs): url = self.__get_url(endpoint) auth = None headers = { - "user-agent": "WooCommerce API Client-Python/%s" % __version__, + "user-agent": f'WooCommerce API {__version__}', "accept": "application/json" } if self.is_ssl is True and self.query_string_auth is False: - auth = (self.consumer_key, self.consumer_secret) + auth = HTTPBasicAuth(self.consumer_key, self.consumer_secret) elif self.is_ssl is True and self.query_string_auth is True: params.update({ "consumer_key": self.consumer_key, @@ -84,7 +85,7 @@ def __request(self, method, endpoint, data, params=None, **kwargs): }) else: encoded_params = urlencode(params) - url = "%s?%s" % (url, encoded_params) + url = f"{url}?{encoded_params}" url = self.__get_oauth_url(url, method, **kwargs) if data is not None: @@ -122,4 +123,3 @@ def delete(self, endpoint, **kwargs): def options(self, endpoint, **kwargs): """ OPTIONS requests """ return self.__request("OPTIONS", endpoint, None, **kwargs) - From a21677623bfc3f6a1a3e6d3117dd12f949a1e3ff Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 14:27:48 -0300 Subject: [PATCH 41/63] Version 3.0.0 --- .gitignore | 4 ++-- requirements-test.txt | 2 +- requirements.txt | 3 +-- woocommerce/__init__.py | 2 +- woocommerce/api.py | 4 ++-- woocommerce/oauth.py | 20 +++++--------------- 6 files changed, 12 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index b542cee..d96eb55 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,6 @@ __pycache__ build/ dist/ *.egg-info/ -run.py -run3.py +sample.py .vscode/ +env/ diff --git a/requirements-test.txt b/requirements-test.txt index 00b7a73..4255091 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,3 +1,3 @@ -r requirements.txt -httmock==1.3.0 +httmock==1.4.0 nose==1.3.7 diff --git a/requirements.txt b/requirements.txt index 93cf612..9d84d35 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -requests==2.22.0 -ordereddict==1.1 +requests==2.25.1 diff --git a/woocommerce/__init__.py b/woocommerce/__init__.py index b1d6ec8..15edcc8 100644 --- a/woocommerce/__init__.py +++ b/woocommerce/__init__.py @@ -10,7 +10,7 @@ """ __title__ = "woocommerce" -__version__ = "2.1.1" +__version__ = "3.0.0" __author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" diff --git a/woocommerce/api.py b/woocommerce/api.py index f16642f..a2010e6 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-api" -__version__ = "2.1.2" +__version__ = "3.0.0" __author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" @@ -72,7 +72,7 @@ def __request(self, method, endpoint, data, params=None, **kwargs): url = self.__get_url(endpoint) auth = None headers = { - "user-agent": f'WooCommerce API {__version__}', + "user-agent": f"WooCommerce API {__version__}", "accept": "application/json" } diff --git a/woocommerce/oauth.py b/woocommerce/oauth.py index 6b5538e..488405a 100644 --- a/woocommerce/oauth.py +++ b/woocommerce/oauth.py @@ -5,7 +5,7 @@ """ __title__ = "woocommerce-oauth" -__version__ = "2.1.1" +__version__ = "3.0.0" __author__ = "Claudio Sanches @ Automattic" __license__ = "MIT" @@ -14,18 +14,8 @@ from hmac import new as HMAC from hashlib import sha1, sha256 from base64 import b64encode - -try: - from urllib.parse import urlencode, quote, unquote, parse_qsl, urlparse -except ImportError: - from urllib import urlencode, quote, unquote - from urlparse import parse_qsl, urlparse - -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict - +from collections import OrderedDict +from urllib.parse import urlencode, quote, unquote, parse_qsl, urlparse class OAuth(object): """ API Class """ @@ -57,7 +47,7 @@ def get_oauth_url(self): query_string = urlencode(params) - return "%s?%s" % (url, query_string) + return f"{url}?{query_string}" def generate_oauth_signature(self, params, url): """ Generate OAuth Signature """ @@ -71,7 +61,7 @@ def generate_oauth_signature(self, params, url): for key, value in params.items()] query_string = "%26".join(query_params) - string_to_sign = "%s&%s&%s" % (self.method, base_request_uri, query_string) + string_to_sign = f"{self.method}&{base_request_uri}&{query_string}" consumer_secret = str(self.consumer_secret) if self.version not in ["v1", "v2"]: From 31b5b01b7fa74c68eb13ac32d9a6a684df1e0016 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 14:31:57 -0300 Subject: [PATCH 42/63] Updated link and year --- LICENSE.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.txt b/LICENSE.txt index e6768bc..73248e1 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019, Automattic (https://woocommerce.com/) +Copyright (c) 2021, Automattic (https://automattic.com/) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 9a806ae16677496d502d56b4410f7bba85f94416 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 14:32:09 -0300 Subject: [PATCH 43/63] Updated test matrix --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a8155d6..969a0ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,9 @@ language: python python: - - "2.7" - - "3.5" - "3.6" + - "3.7" + - "3.8" + - "3.9" - "nightly" # command to install dependencies install: From b5ea3ab4d57f96e4c6d7d9e7cc842bdbf6d32de8 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 14:50:05 -0300 Subject: [PATCH 44/63] Fixed coding standards --- woocommerce/oauth.py | 1 + 1 file changed, 1 insertion(+) diff --git a/woocommerce/oauth.py b/woocommerce/oauth.py index 488405a..62557c0 100644 --- a/woocommerce/oauth.py +++ b/woocommerce/oauth.py @@ -17,6 +17,7 @@ from collections import OrderedDict from urllib.parse import urlencode, quote, unquote, parse_qsl, urlparse + class OAuth(object): """ API Class """ From be81faebfb457e89e053efe3ea4cfaf5fe8288d2 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 14:50:15 -0300 Subject: [PATCH 45/63] Added .flake8 --- .flake8 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..80676bc --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +per-file-ignores = __init__.py:F401 From d510d162e0f07378d1e785902b812ae550bcfc71 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 14:56:21 -0300 Subject: [PATCH 46/63] Updated test framework --- .travis.yml | 2 +- requirements-test.txt | 3 ++- tests.py => test_woocommerce.py | 0 3 files changed, 3 insertions(+), 2 deletions(-) rename tests.py => test_woocommerce.py (100%) diff --git a/.travis.yml b/.travis.yml index 969a0ab..182b326 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,4 +10,4 @@ install: - pip install . - pip install -r requirements-test.txt # command to run tests -script: nosetests +script: pytest diff --git a/requirements-test.txt b/requirements-test.txt index 4255091..950b2c5 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,3 +1,4 @@ -r requirements.txt httmock==1.4.0 -nose==1.3.7 +pytest==6.2.2 +flake8==3.8.4 diff --git a/tests.py b/test_woocommerce.py similarity index 100% rename from tests.py rename to test_woocommerce.py From f6c6d3b49db603771fbbaaa6988b5060df29ac01 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 15:00:02 -0300 Subject: [PATCH 47/63] Updated test filename --- test_woocommerce.py => test_api.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test_woocommerce.py => test_api.py (100%) diff --git a/test_woocommerce.py b/test_api.py similarity index 100% rename from test_woocommerce.py rename to test_api.py From 28ad7affa4b1486d8d38225ca3e4f4713f319c33 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 15:03:53 -0300 Subject: [PATCH 48/63] Updated classifiers --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 04115ad..56d8da7 100644 --- a/setup.py +++ b/setup.py @@ -44,10 +44,10 @@ "Natural Language :: English", "License :: OSI Approved :: MIT License", "Programming Language :: Python", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "Topic :: Software Development :: Libraries :: Python Modules" ], ) From 8cbf59881dda8efa4fde4278ec0f76bf85cb8f0f Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 15:05:30 -0300 Subject: [PATCH 49/63] Create package publish workflow --- .github/workflows/python-publish.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..d262e2a --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,28 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries +name: Upload Python Package +on: + release: + types: [created] +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* From 24fec0605729a3c8258723cfa7841999a2add967 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 15:15:51 -0300 Subject: [PATCH 50/63] Update and rename python-publish.yml to publish.yml --- .github/workflows/{python-publish.yml => publish.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{python-publish.yml => publish.yml} (96%) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/publish.yml similarity index 96% rename from .github/workflows/python-publish.yml rename to .github/workflows/publish.yml index d262e2a..d9562ac 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/publish.yml @@ -1,6 +1,6 @@ # This workflow will upload a Python Package using Twine when a release is created # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries -name: Upload Python Package +name: Publish package to PyPI on: release: types: [created] From 9c7ac49ad854ed44ca42777a9c6970bf2bb4af30 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 15:17:36 -0300 Subject: [PATCH 51/63] Create ci.yml --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9fbc3d0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions +name: Run CI +on: + push: + branches: [trunk] + pull_request: + branches: [trunk] +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6, 3.7, 3.8, 3.9, nightly] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements-test.txt + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From 575c97f74f2c3f8f4304929e72d74144d7578b3b Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 15:18:33 -0300 Subject: [PATCH 52/63] Added name to job --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9fbc3d0..06ceeae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,12 +8,14 @@ on: branches: [trunk] jobs: build: + name: Build runs-on: ubuntu-latest strategy: matrix: python-version: [3.6, 3.7, 3.8, 3.9, nightly] steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: From c39772a1290f8d875e7cd07c198bf6d030af9165 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 15:20:40 -0300 Subject: [PATCH 53/63] Remove nightly It doesn't work with PyPy --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06ceeae..82f9239 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9, nightly] + python-version: [3.6, 3.7, 3.8, 3.9] steps: - name: Checkout code uses: actions/checkout@v2 From 9fb6d13bdbdd3fde244f9a2f05ebe440e680836c Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 15:22:44 -0300 Subject: [PATCH 54/63] Updated CI badge --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 8d30583..f2c26f9 100644 --- a/README.rst +++ b/README.rst @@ -3,8 +3,8 @@ WooCommerce API - Python Client A Python wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library. -.. image:: https://secure.travis-ci.org/woocommerce/wc-api-python.svg - :target: http://travis-ci.org/woocommerce/wc-api-python +.. image:: https://github.com/woocommerce/wc-api-python/actions/workflows/ci.yml/badge.svg?branch=trunk + :target: https://github.com/woocommerce/wc-api-python/actions/workflows/ci.yml .. image:: https://img.shields.io/pypi/v/woocommerce.svg :target: https://pypi.python.org/pypi/WooCommerce From 2b7d89419308e21e2ac53a065bac3caa7f52dd1d Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 15:24:58 -0300 Subject: [PATCH 55/63] Remove travis --- .travis.yml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 182b326..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: python -python: - - "3.6" - - "3.7" - - "3.8" - - "3.9" - - "nightly" -# command to install dependencies -install: - - pip install . - - pip install -r requirements-test.txt -# command to run tests -script: pytest From fe1affbd2c9bd704a13fad6b16ef9fab459ac3d9 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 15:41:18 -0300 Subject: [PATCH 56/63] Introduced user_agent Closes #53 --- README.rst | 2 ++ woocommerce/api.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index f2c26f9..f11da95 100644 --- a/README.rst +++ b/README.rst @@ -58,6 +58,8 @@ Options +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``query_string_auth`` | ``bool`` | no | Force Basic Authentication as query string when ``True`` and using under HTTPS, default is ``False`` | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ +| ``user_agent`` | ``string`` | no | Set a custom User-Agent, default is ``WooCommerce-Python-REST-API/3.0.0`` | ++-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``oauth_timestamp`` | ``integer`` | no | Custom timestamp for requests made with oAuth1.0a | +-----------------------+-------------+----------+-------------------------------------------------------------------------------------------------------+ | ``wp_api`` | ``bool`` | no | Set to ``False`` in order to use the legacy WooCommerce API (deprecated) | diff --git a/woocommerce/api.py b/woocommerce/api.py index a2010e6..e25df49 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -34,6 +34,7 @@ def __init__(self, url, consumer_key, consumer_secret, **kwargs): self.timeout = kwargs.get("timeout", 5) self.verify_ssl = kwargs.get("verify_ssl", True) self.query_string_auth = kwargs.get("query_string_auth", False) + self.user_agent = kwargs.get("user_agent", f"WooCommerce-Python-REST-API/{__version__}") def __is_ssl(self): """ Check if url use HTTPS """ @@ -72,7 +73,7 @@ def __request(self, method, endpoint, data, params=None, **kwargs): url = self.__get_url(endpoint) auth = None headers = { - "user-agent": f"WooCommerce API {__version__}", + "user-agent": f"{self.user_agent}", "accept": "application/json" } From c79afe312c58b7af7e8a8ab91546df1585805a57 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 16:03:36 -0300 Subject: [PATCH 57/63] Added CHANGELOG.md --- CHANGELOG.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5c5b1cd --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,80 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [2.1.1] - 2019-07-22 +### Changed +- Updated Request library to 2.22.0. +- Updated examples. + +## [2.1.0] - 2019-01-15 +### Changed +- Uses WP REST API by default, need to set `wp_api` as `False` in order to use the legacy WooCommerce API. +- Updated default REST API version to `wc/v3`. + +## [2.0.0] - 2019-01-15 +### Added +- Added support for custom timestamps in oAuth1.0a requests with `oauth_timestamp`. +- Allow pass custom arguments to "Requests" library.. +### Changed +- Updated "Requests" library to version 2.20.0. + +## [1.2.1] - 2016-12-14 +### Fixed +- Fixed use of `content-type` to fix issues with WordPress 4.7. + +## [1.2.0] - 2016-06-22 +### Added +- Added option `query_string_auth` to allow Basic Auth as query strings. + +## [1.1.1] - 2016-06-03 +### Fixed +- Fixed oAuth signature for WP REST API. + +## [1.1.0] - 2016-05-09 +### Added +- Added support for WP REST API. +- Added method to handle HTTP OPTIONS requests. + +## [1.0.5] - 2015-12-07 +### Fixed +- Fixed oAuth filters sorting. + +## [1.0.4] - 2015-09-25 +### Added +- Adds `timeout` argument for `API` class. + +## [1.0.3] - 2015-08-07 +### Changed +- Forced utf-8 encoding on `API.__request()` to avoid `UnicodeDecodeError`. + +## [1.0.2] - 2015-08-05 +### Fixed +- Fixed handler for query strings. + +## [1.0.1] - 2015-07-13 +### Fixed +- Fixed support for Python 2.6. + +## [1.0.0] - 2015-07-12 +### Added +- Initial release. + +[Unreleased]: https://github.com/woocommerce/wc-api-python/compare/1.0.0...HEAD +[2.1.1]: https://github.com/woocommerce/wc-api-python/compare/2.1.1...2.1.1 +[2.1.0]: https://github.com/woocommerce/wc-api-python/compare/2.0.0...2.1.0 +[2.0.0]: https://github.com/woocommerce/wc-api-python/compare/1.2.1...2.0.0 +[1.2.1]: https://github.com/woocommerce/wc-api-python/compare/1.2.0...1.2.1 +[1.2.0]: https://github.com/woocommerce/wc-api-python/compare/1.1.1...1.2.0 +[1.1.1]: https://github.com/woocommerce/wc-api-python/compare/1.1.0...1.1.1 +[1.1.0]: https://github.com/woocommerce/wc-api-python/compare/1.0.5...1.1.0 +[1.0.5]: https://github.com/woocommerce/wc-api-python/compare/1.0.4...1.0.5 +[1.0.4]: https://github.com/woocommerce/wc-api-python/compare/1.0.3...1.0.4 +[1.0.3]: https://github.com/woocommerce/wc-api-python/compare/1.0.2...1.0.3 +[1.0.2]: https://github.com/woocommerce/wc-api-python/compare/1.0.1...1.0.2 +[1.0.1]: https://github.com/woocommerce/wc-api-python/compare/1.0.0...1.0.1 +[1.0.0]: https://github.com/woocommerce/wc-api-python/releases/tag/1.0.0 From 8e59b68c4285e6322263aff9ec92e441b4af43f2 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 16:05:09 -0300 Subject: [PATCH 58/63] Link to changelog --- README.rst | 70 +----------------------------------------------------- 1 file changed, 1 insertion(+), 69 deletions(-) diff --git a/README.rst b/README.rst index f11da95..38d507b 100644 --- a/README.rst +++ b/README.rst @@ -148,72 +148,4 @@ Request with `params` example Changelog --------- -2.1.1 - 2019/07/22 -~~~~~~~~~~~~~~~~~~ - -- Updated Request library to 2.22.0. -- Updated examples. - -2.1.0 - 2019/01/15 -~~~~~~~~~~~~~~~~~~ - -- Uses WP REST API by default, need to force ``wp_api`` as ``False`` in order to use the legacy WooCommerce API. -- Updated default REST API version to ``wc/v3``. - -2.0.0 - 2019/01/15 -~~~~~~~~~~~~~~~~~~ - -- Updated "Requests" library to version 2.20.0. -- Added support for custom timestamps in oAuth1.0a requests with ``oauth_timestamp``. -- Allow pass custom arguments to "Requests" library. - -1.2.1 - 2016/12/14 -~~~~~~~~~~~~~~~~~~ - -- Fixed WordPress 4.7 compatibility. - -1.2.0 - 2016/06/22 -~~~~~~~~~~~~~~~~~~ - -- Added option ``query_string_auth`` to allow Basic Auth as query strings. - -1.1.1 - 2016/06/03 -~~~~~~~~~~~~~~~~~~ - -- Fixed oAuth signature for WP REST API. - -1.1.0 - 2016/05/09 -~~~~~~~~~~~~~~~~~~ - -- Added support for WP REST API. -- Added method to do HTTP OPTIONS requests. - -1.0.5 - 2015/12/07 -~~~~~~~~~~~~~~~~~~ - -- Fixed oAuth filters sorting. - -1.0.4 - 2015/09/25 -~~~~~~~~~~~~~~~~~~ - -- Implemented ``timeout`` argument for ``API`` class. - -1.0.3 - 2015/08/07 -~~~~~~~~~~~~~~~~~~ - -- Forced utf-8 encoding on ``API.__request()`` to avoid ``UnicodeDecodeError`` - -1.0.2 - 2015/08/05 -~~~~~~~~~~~~~~~~~~ - -- Fixed handler for query strings - -1.0.1 - 2015/07/13 -~~~~~~~~~~~~~~~~~~ - -- Fixed support for Python 2.6 - -1.0.1 - 2015/07/12 -~~~~~~~~~~~~~~~~~~ - -- Initial version +See `CHANGELOG.md `_. From 7e2d1e589f0c53721b0581452a35d08f79fb5f7b Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 16:17:38 -0300 Subject: [PATCH 59/63] Updated setup.py Includes python_requires, keyworkds and more. --- setup.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 56d8da7..b6897ab 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ description="A Python wrapper for the WooCommerce REST API", long_description=README, author="Claudio Sanches @ Automattic", + author_email="claudio+pypi@automattic.com" url="https://github.com/woocommerce/wc-api-python", license="MIT License", packages=[ @@ -35,9 +36,9 @@ include_package_data=True, platforms=['any'], install_requires=[ - "requests", - "ordereddict" + "requests" ], + python_requires=">=3.6", classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", @@ -50,4 +51,10 @@ "Programming Language :: Python :: 3.9", "Topic :: Software Development :: Libraries :: Python Modules" ], + keywords='woocommerce rest api', + project_urls={ + 'Documentation': 'https://woocommerce.github.io/woocommerce-rest-api-docs/?python#libraries-and-tools', + 'Source': 'https://github.com/woocommerce/wc-api-python', + 'Tracker': 'https://github.com/woocommerce/wc-api-python/issues', + }, ) From e3a891040a921d16c5647a758d85d820fd1ba113 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 16:19:14 -0300 Subject: [PATCH 60/63] Fixed typo --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b6897ab..9dae917 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ description="A Python wrapper for the WooCommerce REST API", long_description=README, author="Claudio Sanches @ Automattic", - author_email="claudio+pypi@automattic.com" + author_email="claudio+pypi@automattic.com", url="https://github.com/woocommerce/wc-api-python", license="MIT License", packages=[ From 122eac04bb4d9fa5b23890e1d5dee3b8ab7828df Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 16:22:03 -0300 Subject: [PATCH 61/63] Updated .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d96eb55..2b50e6d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist/ sample.py .vscode/ env/ +.pytest_cache/ From 1f30f1795c3b3b12f9d02cbc979bf53558511290 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 16:41:33 -0300 Subject: [PATCH 62/63] Removed legacy support --- woocommerce/api.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/woocommerce/api.py b/woocommerce/api.py index e25df49..a97c901 100644 --- a/woocommerce/api.py +++ b/woocommerce/api.py @@ -14,11 +14,7 @@ from time import time from woocommerce.oauth import OAuth from requests.auth import HTTPBasicAuth - -try: - from urllib.parse import urlencode -except ImportError: - from urllib import urlencode +from urllib.parse import urlencode class API(object): From 003e29937e1059c12fb08ff81732bbb61afc6bbf Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 13 Mar 2021 16:51:45 -0300 Subject: [PATCH 63/63] 3.0.0 changelog --- CHANGELOG.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c5b1cd..d08df1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [3.0.0] - 2021-03-13 +### Removed +- Removed support to legacy Python versions, now supports Python 3.6+. +- Removed ordereddict package dependency. +### Added +- Added support for Python 3.8 and Python 3.9. +- Added option to set custom `user_agent`. +### Changed +- Updated default "User-Agent" to `WooCommerce-Python-REST-API/3.0.0`. +- Updated Request library to 2.25.1. +### Fixed +- Fixed Basic Auth in Python 3.8. + ## [2.1.1] - 2019-07-22 ### Changed - Updated Request library to 2.22.0. @@ -64,8 +77,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release. -[Unreleased]: https://github.com/woocommerce/wc-api-python/compare/1.0.0...HEAD -[2.1.1]: https://github.com/woocommerce/wc-api-python/compare/2.1.1...2.1.1 +[Unreleased]: https://github.com/woocommerce/wc-api-python/compare/3.0.0...HEAD +[3.0.0]: https://github.com/woocommerce/wc-api-python/compare/2.1.1...3.0.0 +[2.1.1]: https://github.com/woocommerce/wc-api-python/compare/2.0.1...2.1.1 [2.1.0]: https://github.com/woocommerce/wc-api-python/compare/2.0.0...2.1.0 [2.0.0]: https://github.com/woocommerce/wc-api-python/compare/1.2.1...2.0.0 [1.2.1]: https://github.com/woocommerce/wc-api-python/compare/1.2.0...1.2.1