From c0ca7982b1cde15c57d29b99ed2afbc2acfe09d4 Mon Sep 17 00:00:00 2001 From: William Hunt Date: Thu, 14 Nov 2019 10:08:32 -0500 Subject: [PATCH 1/6] added support for custom ticket properties --- hubspot3/base.py | 13 +++++++++++-- hubspot3/globals.py | 2 +- hubspot3/tickets.py | 12 +++++++++--- setup.cfg | 7 ++++++- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/hubspot3/base.py b/hubspot3/base.py index a4a5583..707f09e 100644 --- a/hubspot3/base.py +++ b/hubspot3/base.py @@ -110,9 +110,10 @@ def _prepare_request_auth(self, subpath, params, data, opts): params["hapikey"] = params.get("hapikey") or self.api_key def _prepare_request( - self, subpath, params, data, opts, doseq=False, query="", retried=False + self, subpath, params, data, opts, doseq=False, query="", retried=False, properties="" ): params = params or {} + properties = properties or {} self._prepare_request_auth(subpath, params, data, opts) if opts.get("hub_id") or opts.get("portal_id"): @@ -139,6 +140,11 @@ def _prepare_request( if data and headers["Content-Type"] == "application/json" and not retried: data = json.dumps(data) + i = 0 + while i < len(properties): + url = url + "&properties=" + properties[i] + i += 1 + return url, headers, data def _create_request(self, conn, method, url, headers, data): @@ -221,6 +227,7 @@ def _call_raw( doseq=False, query="", retried=False, + properties=None, **options ): opts = self.options.copy() @@ -229,7 +236,7 @@ def _call_raw( debug = opts.get("debug") url, headers, data = self._prepare_request( - subpath, params, data, opts, doseq=doseq, query=query, retried=retried + subpath, params, data, opts, doseq=doseq, query=query, retried=retried, properties=properties ) if debug: @@ -343,6 +350,7 @@ def _call( doseq: bool = False, query: str = "", raw: bool = False, + properties: str ="", **options ): result = self._call_raw( @@ -353,6 +361,7 @@ def _call( doseq=doseq, query=query, retried=False, + properties=properties, **options ) return result if raw else self._digest_result(result.body) diff --git a/hubspot3/globals.py b/hubspot3/globals.py index 8e1904b..1e1cfad 100644 --- a/hubspot3/globals.py +++ b/hubspot3/globals.py @@ -1,7 +1,7 @@ """ globals file for hubspot3 """ -__version__ = "3.2.36" +__version__ = "3.2.37" BASE_URL = "https://api.hubapi.com" diff --git a/hubspot3/tickets.py b/hubspot3/tickets.py index 4bb8f36..1612bb2 100644 --- a/hubspot3/tickets.py +++ b/hubspot3/tickets.py @@ -42,7 +42,12 @@ def create( ticket_data.append({"name": "hs_pipeline_stage", "value": stage}) return self._call("objects/tickets", data=ticket_data, method="POST", **options) - def get(self, ticket_id: str, include_deleted: bool = False, **options) -> Dict: + def update(self, ticket_id: str, data: dict, **options) -> Dict: + return self._call( + "objects/tickets/{}".format(ticket_id), method="PUT", data=data, **options + ) + + def get(self, ticket_id: str, properties=["subject", "content", "hs_pipeline", "hs_pipeline_stage", "hs_pipeline"], include_deleted: bool = False, **options) -> Dict: """ get a ticket by its ticket_id TODO: add properties support @@ -54,10 +59,10 @@ def get(self, ticket_id: str, include_deleted: bool = False, **options) -> Dict: options.update({"params": params}) return self._call( - "objects/tickets/{}".format(ticket_id), method="GET", **options + "objects/tickets/{}".format(ticket_id), method="GET", properties=properties, **options ) - def get_all(self, limit: int = -1, **options) -> list: + def get_all(self, properties=["subject", "content", "hs_pipeline", "hs_pipeline_stage", "hs_pipeline"], limit: int = -1, **options) -> list: """ Get all tickets in hubspot :see: https://developers.hubspot.com/docs/methods/tickets/get-all-tickets @@ -71,6 +76,7 @@ def get_all(self, limit: int = -1, **options) -> list: "objects/tickets/paged", method="GET", params={"offset": offset}, + properties=properties, **options ) output.extend(batch["objects"]) diff --git a/setup.cfg b/setup.cfg index 885b668..62da7e2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [mypy] -python_version = 3.5 +python_version = 3.6 disallow_untyped_defs = False ignore_missing_imports = True @@ -7,3 +7,8 @@ ignore_missing_imports = True ignore = N802,N807,W503 max-line-length = 100 max-complexity = 20 + +[egg_info] +tag_build = +tag_date = 0 + From fa126bd9e3d4e95fc2544564b023e392d27b309e Mon Sep 17 00:00:00 2001 From: William Hunt Date: Fri, 15 Nov 2019 10:25:17 -0500 Subject: [PATCH 2/6] Fixed ticket custom properties code --- hubspot3/base.py | 12 +++++------- hubspot3/globals.py | 2 +- hubspot3/tickets.py | 7 ++++--- setup.cfg | 9 ++------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/hubspot3/base.py b/hubspot3/base.py index 707f09e..593f60c 100644 --- a/hubspot3/base.py +++ b/hubspot3/base.py @@ -110,10 +110,10 @@ def _prepare_request_auth(self, subpath, params, data, opts): params["hapikey"] = params.get("hapikey") or self.api_key def _prepare_request( - self, subpath, params, data, opts, doseq=False, query="", retried=False, properties="" + self, subpath, params, data, opts, doseq=False, query="", retried=False, properties=[] ): params = params or {} - properties = properties or {} + properties = properties or [] self._prepare_request_auth(subpath, params, data, opts) if opts.get("hub_id") or opts.get("portal_id"): @@ -140,10 +140,8 @@ def _prepare_request( if data and headers["Content-Type"] == "application/json" and not retried: data = json.dumps(data) - i = 0 - while i < len(properties): - url = url + "&properties=" + properties[i] - i += 1 + for property in properties: + url += '&properties={}'.format(property) return url, headers, data @@ -350,7 +348,7 @@ def _call( doseq: bool = False, query: str = "", raw: bool = False, - properties: str ="", + properties: list() = None, **options ): result = self._call_raw( diff --git a/hubspot3/globals.py b/hubspot3/globals.py index 1e1cfad..8e1904b 100644 --- a/hubspot3/globals.py +++ b/hubspot3/globals.py @@ -1,7 +1,7 @@ """ globals file for hubspot3 """ -__version__ = "3.2.37" +__version__ = "3.2.36" BASE_URL = "https://api.hubapi.com" diff --git a/hubspot3/tickets.py b/hubspot3/tickets.py index 1612bb2..215b376 100644 --- a/hubspot3/tickets.py +++ b/hubspot3/tickets.py @@ -47,13 +47,13 @@ def update(self, ticket_id: str, data: dict, **options) -> Dict: "objects/tickets/{}".format(ticket_id), method="PUT", data=data, **options ) - def get(self, ticket_id: str, properties=["subject", "content", "hs_pipeline", "hs_pipeline_stage", "hs_pipeline"], include_deleted: bool = False, **options) -> Dict: + def get(self, ticket_id: str, properties: list() = None, include_deleted: bool = False, **options) -> Dict: """ get a ticket by its ticket_id TODO: add properties support :see: https://developers.hubspot.com/docs/methods/tickets/get_ticket_by_id """ - + properties = properties or ["subject", "content", "hs_pipeline", "hs_pipeline_stage", "hs_pipeline"] params = options.pop("params", {}) params.update({"includeDeletes": include_deleted}) options.update({"params": params}) @@ -62,11 +62,12 @@ def get(self, ticket_id: str, properties=["subject", "content", "hs_pipeline", " "objects/tickets/{}".format(ticket_id), method="GET", properties=properties, **options ) - def get_all(self, properties=["subject", "content", "hs_pipeline", "hs_pipeline_stage", "hs_pipeline"], limit: int = -1, **options) -> list: + def get_all(self, properties: list() = None, limit: int = -1, **options) -> list: """ Get all tickets in hubspot :see: https://developers.hubspot.com/docs/methods/tickets/get-all-tickets """ + properties = properties or ["subject", "content", "hs_pipeline", "hs_pipeline_stage", "hs_pipeline"] finished = False output = [] # type: list offset = 0 diff --git a/setup.cfg b/setup.cfg index 62da7e2..befd103 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,14 +1,9 @@ [mypy] -python_version = 3.6 +python_version = 3.5 disallow_untyped_defs = False ignore_missing_imports = True [flake8] ignore = N802,N807,W503 max-line-length = 100 -max-complexity = 20 - -[egg_info] -tag_build = -tag_date = 0 - +max-complexity = 20 \ No newline at end of file From 3c0324e74de42fec489470754f00d76a8dbb4cc5 Mon Sep 17 00:00:00 2001 From: William Hunt Date: Fri, 15 Nov 2019 10:33:45 -0500 Subject: [PATCH 3/6] Fixed ticket properties #2 --- hubspot3/base.py | 2 +- hubspot3/tickets.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hubspot3/base.py b/hubspot3/base.py index 593f60c..4d000c8 100644 --- a/hubspot3/base.py +++ b/hubspot3/base.py @@ -348,7 +348,7 @@ def _call( doseq: bool = False, query: str = "", raw: bool = False, - properties: list() = None, + properties: list = None, **options ): result = self._call_raw( diff --git a/hubspot3/tickets.py b/hubspot3/tickets.py index 215b376..be2a7d0 100644 --- a/hubspot3/tickets.py +++ b/hubspot3/tickets.py @@ -47,7 +47,7 @@ def update(self, ticket_id: str, data: dict, **options) -> Dict: "objects/tickets/{}".format(ticket_id), method="PUT", data=data, **options ) - def get(self, ticket_id: str, properties: list() = None, include_deleted: bool = False, **options) -> Dict: + def get(self, ticket_id: str, properties: list = None, include_deleted: bool = False, **options) -> Dict: """ get a ticket by its ticket_id TODO: add properties support @@ -62,7 +62,7 @@ def get(self, ticket_id: str, properties: list() = None, include_deleted: bool = "objects/tickets/{}".format(ticket_id), method="GET", properties=properties, **options ) - def get_all(self, properties: list() = None, limit: int = -1, **options) -> list: + def get_all(self, properties: list = None, limit: int = -1, **options) -> list: """ Get all tickets in hubspot :see: https://developers.hubspot.com/docs/methods/tickets/get-all-tickets From 699e9e1409c3decac3c29ad7fe46aab8e00f205f Mon Sep 17 00:00:00 2001 From: William Hunt Date: Fri, 15 Nov 2019 10:41:01 -0500 Subject: [PATCH 4/6] Fixed ticket properties #3 --- hubspot3/base.py | 12 ++++++++---- hubspot3/tickets.py | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/hubspot3/base.py b/hubspot3/base.py index 4d000c8..a27a161 100644 --- a/hubspot3/base.py +++ b/hubspot3/base.py @@ -110,7 +110,7 @@ def _prepare_request_auth(self, subpath, params, data, opts): params["hapikey"] = params.get("hapikey") or self.api_key def _prepare_request( - self, subpath, params, data, opts, doseq=False, query="", retried=False, properties=[] + self, subpath, params, data, opts, doseq=False, query="", retried=False, properties=None ): params = params or {} properties = properties or [] @@ -140,8 +140,8 @@ def _prepare_request( if data and headers["Content-Type"] == "application/json" and not retried: data = json.dumps(data) - for property in properties: - url += '&properties={}'.format(property) + for hs_property in properties: + url += '&properties={}'.format(hs_property) return url, headers, data @@ -234,7 +234,11 @@ def _call_raw( debug = opts.get("debug") url, headers, data = self._prepare_request( - subpath, params, data, opts, doseq=doseq, query=query, retried=retried, properties=properties + subpath, params, data, opts, + doseq=doseq, + query=query, + retried=retried, + properties=properties ) if debug: diff --git a/hubspot3/tickets.py b/hubspot3/tickets.py index be2a7d0..ed4d020 100644 --- a/hubspot3/tickets.py +++ b/hubspot3/tickets.py @@ -47,13 +47,21 @@ def update(self, ticket_id: str, data: dict, **options) -> Dict: "objects/tickets/{}".format(ticket_id), method="PUT", data=data, **options ) - def get(self, ticket_id: str, properties: list = None, include_deleted: bool = False, **options) -> Dict: + def get(self, ticket_id: str, properties: list = None, include_deleted: bool = False, **options + ) -> Dict: """ get a ticket by its ticket_id TODO: add properties support :see: https://developers.hubspot.com/docs/methods/tickets/get_ticket_by_id """ - properties = properties or ["subject", "content", "hs_pipeline", "hs_pipeline_stage", "hs_pipeline"] + properties = properties or [ + "subject", + "content", + "hs_pipeline", + "hs_pipeline_stage", + "hs_pipeline" + ] + params = options.pop("params", {}) params.update({"includeDeletes": include_deleted}) options.update({"params": params}) @@ -67,7 +75,14 @@ def get_all(self, properties: list = None, limit: int = -1, **options) -> list: Get all tickets in hubspot :see: https://developers.hubspot.com/docs/methods/tickets/get-all-tickets """ - properties = properties or ["subject", "content", "hs_pipeline", "hs_pipeline_stage", "hs_pipeline"] + properties = properties or [ + "subject", + "content", + "hs_pipeline", + "hs_pipeline_stage", + "hs_pipeline" + ] + finished = False output = [] # type: list offset = 0 From 27debd59f3ddd5f70a9fe54bfe9a250316525f92 Mon Sep 17 00:00:00 2001 From: William Hunt Date: Fri, 15 Nov 2019 10:48:19 -0500 Subject: [PATCH 5/6] Fixed ticket properties #4 --- hubspot3/base.py | 8 ++++---- hubspot3/tickets.py | 21 +++++---------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/hubspot3/base.py b/hubspot3/base.py index a27a161..ee7816f 100644 --- a/hubspot3/base.py +++ b/hubspot3/base.py @@ -234,10 +234,10 @@ def _call_raw( debug = opts.get("debug") url, headers, data = self._prepare_request( - subpath, params, data, opts, - doseq=doseq, - query=query, - retried=retried, + subpath, params, data, opts, + doseq=doseq, + query=query, + retried=retried, properties=properties ) diff --git a/hubspot3/tickets.py b/hubspot3/tickets.py index ed4d020..39b652c 100644 --- a/hubspot3/tickets.py +++ b/hubspot3/tickets.py @@ -47,20 +47,15 @@ def update(self, ticket_id: str, data: dict, **options) -> Dict: "objects/tickets/{}".format(ticket_id), method="PUT", data=data, **options ) - def get(self, ticket_id: str, properties: list = None, include_deleted: bool = False, **options + def get( + self, ticket_id: str, properties: list = None, include_deleted: bool = False, **options ) -> Dict: """ get a ticket by its ticket_id TODO: add properties support :see: https://developers.hubspot.com/docs/methods/tickets/get_ticket_by_id """ - properties = properties or [ - "subject", - "content", - "hs_pipeline", - "hs_pipeline_stage", - "hs_pipeline" - ] + properties = properties or ["subject","content","hs_pipeline","hs_pipeline_stage"] params = options.pop("params", {}) params.update({"includeDeletes": include_deleted}) @@ -75,14 +70,8 @@ def get_all(self, properties: list = None, limit: int = -1, **options) -> list: Get all tickets in hubspot :see: https://developers.hubspot.com/docs/methods/tickets/get-all-tickets """ - properties = properties or [ - "subject", - "content", - "hs_pipeline", - "hs_pipeline_stage", - "hs_pipeline" - ] - + properties = properties or ["subject","content","hs_pipeline","hs_pipeline_stage"] + finished = False output = [] # type: list offset = 0 From 270eab6d5e0cd9adda8dc8951b7b67b2f7cb7232 Mon Sep 17 00:00:00 2001 From: William Hunt Date: Fri, 15 Nov 2019 10:50:52 -0500 Subject: [PATCH 6/6] Fixed ticket properties #5 --- hubspot3/tickets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hubspot3/tickets.py b/hubspot3/tickets.py index 39b652c..f55147b 100644 --- a/hubspot3/tickets.py +++ b/hubspot3/tickets.py @@ -55,7 +55,7 @@ def get( TODO: add properties support :see: https://developers.hubspot.com/docs/methods/tickets/get_ticket_by_id """ - properties = properties or ["subject","content","hs_pipeline","hs_pipeline_stage"] + properties = properties or ["subject", "content", "hs_pipeline", "hs_pipeline_stage"] params = options.pop("params", {}) params.update({"includeDeletes": include_deleted}) @@ -70,7 +70,7 @@ def get_all(self, properties: list = None, limit: int = -1, **options) -> list: Get all tickets in hubspot :see: https://developers.hubspot.com/docs/methods/tickets/get-all-tickets """ - properties = properties or ["subject","content","hs_pipeline","hs_pipeline_stage"] + properties = properties or ["subject", "content", "hs_pipeline", "hs_pipeline_stage"] finished = False output = [] # type: list