From 264e63f53b4a5d5286741dddbfbd908085286f09 Mon Sep 17 00:00:00 2001 From: Joshua Teitelbaum Date: Tue, 20 Feb 2024 11:20:15 -0800 Subject: [PATCH] Rangeles custom statuses (#622) * Adding APIs for custom ticket statuses * Tests for custom statuses CRUD Also, throw exception immediately if attempting to delete. The API doesn't support deleting custom statuses. --------- Co-authored-by: Ron Angeles --- specification/zendesk/custom_status.json | 17 ++ ..._single_object_creation-create-single.json | 133 +++++++++ ...st_single_object_update-update-single.json | 261 ++++++++++++++++++ ...tfoundexception-recordnotfound-update.json | 132 +++++++++ .../test_create_update_delete_zendesk.py | 27 ++ zenpy/__init__.py | 4 +- zenpy/lib/api.py | 8 + zenpy/lib/api_objects/__init__.py | 75 +++++ zenpy/lib/cache.py | 3 +- zenpy/lib/endpoint.py | 1 + zenpy/lib/mapping.py | 4 +- 11 files changed, 662 insertions(+), 3 deletions(-) create mode 100644 specification/zendesk/custom_status.json create mode 100644 tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_object_creation-create-single.json create mode 100644 tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_object_update-update-single.json create mode 100644 tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_update_raises_recordnotfoundexception-recordnotfound-update.json diff --git a/specification/zendesk/custom_status.json b/specification/zendesk/custom_status.json new file mode 100644 index 00000000..ba611195 --- /dev/null +++ b/specification/zendesk/custom_status.json @@ -0,0 +1,17 @@ +{ + "url": "https://company.zendesk.com/api/v2/custom_statuses/8675309.json", + "id": 8675309, + "status_category": "hold", + "agent_label": "Tutone", + "raw_agent_label": "Tutone", + "end_user_label": "Jenny", + "raw_end_user_label": "Jenny", + "description": "You give me somethin' I can hold on to", + "raw_description": "You give me somethin' I can hold on to", + "end_user_description": "Who can I turn to", + "raw_end_user_description": "Who can I turn to", + "active": true, + "default": false, + "created_at": "2022-12-19T03:32:42Z", + "updated_at": "2023-01-30T16:48:33Z" +} diff --git a/tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_object_creation-create-single.json b/tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_object_creation-create-single.json new file mode 100644 index 00000000..9f181089 --- /dev/null +++ b/tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_object_creation-create-single.json @@ -0,0 +1,133 @@ +{ + "http_interactions": [ + { + "recorded_at": "2023-12-24T07:24:55", + "request": { + "body": { + "encoding": "utf-8", + "string": "{\"custom_status\": {\"agent_label\": \"agent\", \"end_user_label\": \"end\", \"status_category\": \"open\"}}" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Authorization": [ + "Basic " + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "95" + ], + "Content-Type": [ + "application/json" + ], + "User-Agent": [ + "Zenpy/2.0.41" + ] + }, + "method": "POST", + "uri": "https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses.json" + }, + "response": { + "body": { + "encoding": "utf-8", + "string": "{\"custom_status\":{\"url\":\"https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses/22644162812557.json\",\"id\":22644162812557,\"status_category\":\"open\",\"agent_label\":\"agent\",\"raw_agent_label\":\"agent\",\"end_user_label\":\"end\",\"raw_end_user_label\":\"end\",\"description\":null,\"raw_description\":null,\"end_user_description\":null,\"raw_end_user_description\":null,\"active\":true,\"default\":false,\"created_at\":\"2023-12-24T07:24:55Z\",\"updated_at\":\"2023-12-24T07:24:55Z\"}}" + }, + "headers": { + "CF-Cache-Status": [ + "DYNAMIC" + ], + "CF-RAY": [ + "83a71b7a2ce91739-SJC" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "487" + ], + "Content-Type": [ + "application/json; charset=utf-8" + ], + "Date": [ + "Sun, 24 Dec 2023 07:24:55 GMT" + ], + "NEL": [ + "{\"success_fraction\":0.01,\"report_to\":\"cf-nel\",\"max_age\":604800}" + ], + "Report-To": [ + "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=qI0G5OrJmF7akv7%2Fwh2m4gONA0Ip694%2FY1%2BEWqMS%2FixMvvJm72%2FXveyb%2FK5H9L%2FgYzpbG%2BrKeaIoT6PUA8A5K3excSGo3WSJKcYStTVgE1vAz7nDSqs%2FWNL92gwGKaUftSj9zZck3KGLRrK8JA%3D%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}" + ], + "Server": [ + "cloudflare" + ], + "X-Zendesk-Zorg": [ + "yes" + ], + "cache-control": [ + "max-age=0, private, must-revalidate" + ], + "etag": [ + "W/\"8043518af671b2a4c8d79164a8c4dc80\"" + ], + "location": [ + "https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses/22644162812557.json" + ], + "rate-limit": [ + "700" + ], + "rate-limit-remaining": [ + "699" + ], + "rate-limit-reset": [ + "5" + ], + "set-cookie": [ + "_zendesk_cookie=BAhJIhl7ImRldmljZV90b2tlbnMiOnt9fQY6BkVU--0bf2100788cb010d0183feca16aaf88ccaf719ca; path=/; expires=Sun, 22 Dec 2024 07:06:10 GMT; secure; HttpOnly; SameSite=None", + "__cfruid=7bf7d9cea890226ed7f09805b008c8d69df3d432-1703402695; path=/; domain=.d3v-zenpydev.zendesk.com; HttpOnly; Secure; SameSite=None", + "_cfuvid=AnbbIlHOL_DNYVIbM7e2.pxuDnwiHIZ38C1OqalKuH4-1703402695309-0-604800000; path=/; domain=.d3v-zenpydev.zendesk.com; HttpOnly; Secure; SameSite=None" + ], + "strict-transport-security": [ + "max-age=31536000; includeSubDomains" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-rate-limit": [ + "700" + ], + "x-rate-limit-remaining": [ + "699" + ], + "x-request-id": [ + "83a71b7a2ce91739-SJC", + "83a71b7a2ce91739-SJC" + ], + "x-runtime": [ + "0.165526" + ], + "x-zendesk-api-version": [ + "v2" + ], + "x-zendesk-application-version": [ + "v19488" + ], + "x-zendesk-origin-server": [ + "classic-app-server-69bcc7ff5-vdxfw" + ] + }, + "status": { + "code": 201, + "message": "Created" + }, + "url": "https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses.json" + } + } + ], + "recorded_with": "betamax/0.8.1" +} diff --git a/tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_object_update-update-single.json b/tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_object_update-update-single.json new file mode 100644 index 00000000..47ff80ba --- /dev/null +++ b/tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_object_update-update-single.json @@ -0,0 +1,261 @@ +{ + "http_interactions": [ + { + "recorded_at": "2023-12-24T07:37:42", + "request": { + "body": { + "encoding": "utf-8", + "string": "{\"custom_status\": {\"agent_label\": \"agent\", \"end_user_label\": \"end\", \"status_category\": \"open\"}}" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Authorization": [ + "Basic " + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "95" + ], + "Content-Type": [ + "application/json" + ], + "Cookie": [ + "_zendesk_cookie=BAhJIhl7ImRldmljZV90b2tlbnMiOnt9fQY6BkVU--0bf2100788cb010d0183feca16aaf88ccaf719ca; __cfruid=7bf7d9cea890226ed7f09805b008c8d69df3d432-1703402695; _cfuvid=AnbbIlHOL_DNYVIbM7e2.pxuDnwiHIZ38C1OqalKuH4-1703402695309-0-604800000" + ], + "User-Agent": [ + "Zenpy/2.0.41" + ] + }, + "method": "POST", + "uri": "https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses.json" + }, + "response": { + "body": { + "encoding": "utf-8", + "string": "{\"custom_status\":{\"url\":\"https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses/22644243148813.json\",\"id\":22644243148813,\"status_category\":\"open\",\"agent_label\":\"agent\",\"raw_agent_label\":\"agent\",\"end_user_label\":\"end\",\"raw_end_user_label\":\"end\",\"description\":null,\"raw_description\":null,\"end_user_description\":null,\"raw_end_user_description\":null,\"active\":true,\"default\":false,\"created_at\":\"2023-12-24T07:37:42Z\",\"updated_at\":\"2023-12-24T07:37:42Z\"}}" + }, + "headers": { + "CF-Cache-Status": [ + "DYNAMIC" + ], + "CF-RAY": [ + "83a72e33bb87968f-SJC" + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "453" + ], + "Content-Type": [ + "application/json; charset=utf-8" + ], + "Date": [ + "Sun, 24 Dec 2023 07:37:42 GMT" + ], + "NEL": [ + "{\"success_fraction\":0.01,\"report_to\":\"cf-nel\",\"max_age\":604800}" + ], + "Report-To": [ + "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=tGE4HFtQ3XJ90Xdnd0x%2FzjWjw%2F%2Fk9VFFDAwdZk9iGvKaRterMMwODRMgbVCmFH787%2Br1bvbqBposPdCWscNxBel%2FZDpU1FmcNtLTneqqJWkC5Yl0%2F9JminLBOgYGxd3ffBfT046qj2c7o4PuRw%3D%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}" + ], + "Server": [ + "cloudflare" + ], + "X-Zendesk-Zorg": [ + "yes" + ], + "cache-control": [ + "max-age=0, private, must-revalidate" + ], + "etag": [ + "W/\"54e18983326bd5156f1e28c5f64185dd\"" + ], + "location": [ + "https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses/22644243148813.json" + ], + "rate-limit": [ + "700" + ], + "rate-limit-remaining": [ + "699" + ], + "rate-limit-reset": [ + "18" + ], + "strict-transport-security": [ + "max-age=31536000; includeSubDomains" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-rate-limit": [ + "700" + ], + "x-rate-limit-remaining": [ + "699" + ], + "x-request-id": [ + "83a72e33bb87968f-SJC", + "83a72e33bb87968f-SJC" + ], + "x-runtime": [ + "0.193759" + ], + "x-zendesk-api-version": [ + "v2" + ], + "x-zendesk-application-version": [ + "v19488" + ], + "x-zendesk-origin-server": [ + "classic-app-server-69bcc7ff5-smpt9" + ] + }, + "status": { + "code": 201, + "message": "Created" + }, + "url": "https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses.json" + } + }, + { + "recorded_at": "2023-12-24T07:37:42", + "request": { + "body": { + "encoding": "utf-8", + "string": "{\"custom_status\": {\"agent_label\": \"agent0608c4054662dd902e1314f7e450e3eaa81c1143\", \"end_user_label\": \"end7a92f3d26362d6557d5701de77a63a01df61e57f\", \"id\": 22644243148813, \"status_category\": \"open5fc7e38bffe00ca46add89145464a2eaf759d5c2\"}}" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Authorization": [ + "Basic " + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "237" + ], + "Content-Type": [ + "application/json" + ], + "Cookie": [ + "_zendesk_cookie=BAhJIhl7ImRldmljZV90b2tlbnMiOnt9fQY6BkVU--0bf2100788cb010d0183feca16aaf88ccaf719ca; __cfruid=7bf7d9cea890226ed7f09805b008c8d69df3d432-1703402695; _cfuvid=AnbbIlHOL_DNYVIbM7e2.pxuDnwiHIZ38C1OqalKuH4-1703402695309-0-604800000" + ], + "User-Agent": [ + "Zenpy/2.0.41" + ] + }, + "method": "PUT", + "uri": "https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses/22644243148813.json" + }, + "response": { + "body": { + "base64_string": "H4sIAAAAAAAAA6SOyU7DQBBE/6XPJp597PkOTlysZqYdDM7YmiWIRPl3FIIiRWI55NhdVa/qCL7msuyGXLDUDO4INc3g4KWUNbu2PdQlIVeq172Vut8cKAbKbxu/7Fpcp3Yv2hsC5VYIo5RQkquu43LzmpcIDUwB3K3SwCUyeCy0XdIHOFhWOptxS7EMMz7TecvXxQzrvGJaGSNC6JkgLrkaLSnNSBJixz3nSkIDCd+H+wgUw1AzpSuAYrDYi1EGYaQRwWhtg7aMB7IWjUTGw2g4aTt+D7gTESj7NK1lWiK4WOf5Qv3hfS36JfKXjr5MewJXUqVz54h1LuBGnDM14BNhoTBgAQeCCfnAxYNQj8w6aZ0ST9BAXcM/ntPpEwAA//8DAK0mtCJlAgAA", + "encoding": "utf-8", + "string": "" + }, + "headers": { + "CF-Cache-Status": [ + "DYNAMIC" + ], + "CF-RAY": [ + "83a72e377e23968f-SJC" + ], + "Connection": [ + "keep-alive" + ], + "Content-Encoding": [ + "gzip" + ], + "Content-Type": [ + "application/json; charset=utf-8" + ], + "Date": [ + "Sun, 24 Dec 2023 07:37:42 GMT" + ], + "NEL": [ + "{\"success_fraction\":0.01,\"report_to\":\"cf-nel\",\"max_age\":604800}" + ], + "Report-To": [ + "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=vlxssWPGzWdFXQZ50VuBaelV3EWcsDJwB1FnXQ1ob8ZtMUGSk%2Bq3bD3XBK7fAjdiaHXSiKpMerJ2Ib2XPWLNFldvpNIPjAjYKXNPml3vsh906iUWDX7OWRCAiqmhDwFCXCQ%2BaMHVV3Uj3dMWlw%3D%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}" + ], + "Server": [ + "cloudflare" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-Zendesk-Zorg": [ + "yes" + ], + "cache-control": [ + "max-age=0, private, must-revalidate" + ], + "etag": [ + "W/\"d693206ce171b3e6cc491ee133f3749c\"" + ], + "rate-limit": [ + "700" + ], + "rate-limit-remaining": [ + "698" + ], + "rate-limit-reset": [ + "18" + ], + "strict-transport-security": [ + "max-age=31536000; includeSubDomains" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-rate-limit": [ + "700" + ], + "x-rate-limit-remaining": [ + "698" + ], + "x-request-id": [ + "83a72e377e23968f-SJC", + "83a72e377e23968f-SJC" + ], + "x-runtime": [ + "0.088473" + ], + "x-zendesk-api-version": [ + "v2" + ], + "x-zendesk-api-warn": [ + "{:allowed_parameters=>{:controller=>\"custom_statuses\", :action=>\"update\", :unpermitted_keys=>[\"custom_status.id\", \"custom_status.status_category\"], :invalid_values=>[]}}" + ], + "x-zendesk-application-version": [ + "v19488" + ], + "x-zendesk-origin-server": [ + "classic-app-server-69bcc7ff5-v6q2j" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses/22644243148813.json" + } + } + ], + "recorded_with": "betamax/0.8.1" +} \ No newline at end of file diff --git a/tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_update_raises_recordnotfoundexception-recordnotfound-update.json b/tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_update_raises_recordnotfoundexception-recordnotfound-update.json new file mode 100644 index 00000000..8790d420 --- /dev/null +++ b/tests/test_api/betamax/CustomStatusesCreateUpdateDelete.test_single_update_raises_recordnotfoundexception-recordnotfound-update.json @@ -0,0 +1,132 @@ +{ + "http_interactions": [ + { + "recorded_at": "2023-12-24T07:26:56", + "request": { + "body": { + "encoding": "utf-8", + "string": "{\"custom_status\": {\"agent_label\": \"agent label\", \"end_user_label\": \"end user label\", \"id\": 9223372036854775807, \"status_category\": \"open\"}}" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Authorization": [ + "Basic " + ], + "Connection": [ + "keep-alive" + ], + "Content-Length": [ + "139" + ], + "Content-Type": [ + "application/json" + ], + "Cookie": [ + "_zendesk_cookie=BAhJIhl7ImRldmljZV90b2tlbnMiOnt9fQY6BkVU--0bf2100788cb010d0183feca16aaf88ccaf719ca; __cfruid=7bf7d9cea890226ed7f09805b008c8d69df3d432-1703402695; _cfuvid=AnbbIlHOL_DNYVIbM7e2.pxuDnwiHIZ38C1OqalKuH4-1703402695309-0-604800000" + ], + "User-Agent": [ + "Zenpy/2.0.41" + ] + }, + "method": "PUT", + "uri": "https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses/9223372036854775807.json" + }, + "response": { + "body": { + "base64_string": "H4sIAAAAAAAAA6pWSi0qyi9SslIKSk3OL0rxyy9xyy/NS1HSUUpJLU4uyiwoyczPU7JS8ssvUUgDy9QCAAAA//8DAHKmUTI0AAAA", + "encoding": "utf-8", + "string": "" + }, + "headers": { + "CF-Cache-Status": [ + "DYNAMIC" + ], + "CF-RAY": [ + "83a71e726d3967ac-SJC" + ], + "Connection": [ + "keep-alive" + ], + "Content-Encoding": [ + "gzip" + ], + "Content-Type": [ + "application/json; charset=utf-8" + ], + "Date": [ + "Sun, 24 Dec 2023 07:26:56 GMT" + ], + "NEL": [ + "{\"success_fraction\":0.01,\"report_to\":\"cf-nel\",\"max_age\":604800}" + ], + "Report-To": [ + "{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=YSPiW4aHb9FXM7sl6aqrtrtLfJnwzF2QEEIaQ8vNhND3kKNubfPneqs5nl12nHHo%2FOVjbr%2FsYJMOfTCx%2BtylhazN75QJSGrtQLGT%2BzKLDz6sUpaL7xxhZ%2F658tobEy4Y9apj25FN8FWSQmlRvg%3D%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}" + ], + "Server": [ + "cloudflare" + ], + "Transfer-Encoding": [ + "chunked" + ], + "X-Zendesk-Zorg": [ + "yes" + ], + "cache-control": [ + "no-cache" + ], + "rate-limit": [ + "700" + ], + "rate-limit-remaining": [ + "696" + ], + "rate-limit-reset": [ + "4" + ], + "strict-transport-security": [ + "max-age=31536000; includeSubDomains" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-rate-limit": [ + "700" + ], + "x-rate-limit-remaining": [ + "696" + ], + "x-request-id": [ + "83a71e726d3967ac-SJC", + "83a71e726d3967ac-SJC" + ], + "x-runtime": [ + "0.054341" + ], + "x-zendesk-api-version": [ + "v2" + ], + "x-zendesk-api-warn": [ + "{:allowed_parameters=>{:controller=>\"custom_statuses\", :action=>\"update\", :unpermitted_keys=>[\"custom_status.id\", \"custom_status.status_category\"], :invalid_values=>[]}}" + ], + "x-zendesk-application-version": [ + "v19488" + ], + "x-zendesk-origin-server": [ + "classic-app-server-69bcc7ff5-d5gng" + ] + }, + "status": { + "code": 404, + "message": "Not Found" + }, + "url": "https://d3v-zenpydev.zendesk.com/api/v2/custom_statuses/9223372036854775807.json" + } + } + ], + "recorded_with": "betamax/0.8.1" +} \ No newline at end of file diff --git a/tests/test_api/test_create_update_delete_zendesk.py b/tests/test_api/test_create_update_delete_zendesk.py index 86f61df7..d1e7fd3e 100644 --- a/tests/test_api/test_create_update_delete_zendesk.py +++ b/tests/test_api/test_create_update_delete_zendesk.py @@ -21,8 +21,12 @@ OrganizationField, Upload, UserField, + CustomStatus, ) +from zenpy.lib.exception import ( + ZenpyException, +) class TestTicketCreateUpdateDelete(CRUDApiTestCase): __test__ = True @@ -131,3 +135,26 @@ class UserFieldsCreateUpdateDelete( ) ignore_update_kwargs = ["key"] # Can't update key after creation. api_name = "user_fields" + +class CustomStatusesCreateUpdateDelete( + SingleCreateApiTestCase, SingleUpdateApiTestCase +): + __test__ = True + ZenpyType = CustomStatus + api_name = "custom_statuses" + object_kwargs = dict( + agent_label="agent", end_user_label="end", status_category="open" + ) + + # Deletions aren't possible, so clean out any created objects of CustomStatus before tear down + def tearDown(self): + self.created_objects = list(object for object in self.created_objects if type(object) is not self.ZenpyType) + super(CustomStatusesCreateUpdateDelete, self).tearDown() + + # Doesn't matter what the ID is, it should throw an exception + def test_single_object_deletion(self): + with self.assertRaises(ZenpyException): + hopefully_not_real_id = ( + 9223372036854775807 # This is the largest id that Zendesk will accept. + ) + self.delete_method(self.ZenpyType(id=hopefully_not_real_id)) diff --git a/zenpy/__init__.py b/zenpy/__init__.py index 69bad945..29265b4c 100644 --- a/zenpy/__init__.py +++ b/zenpy/__init__.py @@ -45,7 +45,8 @@ UserFieldsApi, ZISApi, WebhooksApi, - LocalesApi + LocalesApi, + CustomStatusesApi ) from zenpy.lib.cache import ZenpyCache, ZenpyCacheManager @@ -181,6 +182,7 @@ def __init__( self.zis = ZISApi(config) self.webhooks = WebhooksApi(config) self.locales = LocalesApi(config) + self.custom_statuses = CustomStatusesApi(config) @staticmethod def http_adapter_kwargs(): diff --git a/zenpy/lib/api.py b/zenpy/lib/api.py index 6edab2b2..aaa05151 100644 --- a/zenpy/lib/api.py +++ b/zenpy/lib/api.py @@ -3127,3 +3127,11 @@ def current(self): :return: Locale """ return self._query_zendesk(self.endpoint.current, 'locale') + +class CustomStatusesApi(CRUDApi): + def __init__(self, config): + super(CustomStatusesApi, self).__init__(config, + object_type='custom_status') + + def delete(self, api_objects, **kwargs): + raise ZenpyException("Custom status cannot be deleted") diff --git a/zenpy/lib/api_objects/__init__.py b/zenpy/lib/api_objects/__init__.py index f32aadc6..7feab293 100644 --- a/zenpy/lib/api_objects/__init__.py +++ b/zenpy/lib/api_objects/__init__.py @@ -927,6 +927,81 @@ def __init__(self, continue +class CustomStatus(BaseObject): + """ + ###################################################################### + # Do not modify, this class is autogenerated by gen_classes.py # + ###################################################################### + """ + def __init__(self, + api=None, + active=None, + agent_label=None, + created_at=None, + default=None, + description=None, + end_user_description=None, + end_user_label=None, + id=None, + raw_agent_label=None, + raw_description=None, + raw_end_user_description=None, + raw_end_user_label=None, + status_category=None, + updated_at=None, + url=None, + **kwargs): + + self.api = api + self.active = active + self.agent_label = agent_label + self.created_at = created_at + self.default = default + self.description = description + self.end_user_description = end_user_description + self.end_user_label = end_user_label + self.id = id + self.raw_agent_label = raw_agent_label + self.raw_description = raw_description + self.raw_end_user_description = raw_end_user_description + self.raw_end_user_label = raw_end_user_label + self.status_category = status_category + self.updated_at = updated_at + self.url = url + + for key, value in kwargs.items(): + setattr(self, key, value) + + for key in self.to_dict(): + if getattr(self, key) is None: + try: + self._dirty_attributes.remove(key) + except KeyError: + continue + + @property + def created(self): + + if self.created_at: + return dateutil.parser.parse(self.created_at) + + @created.setter + def created(self, created): + if created: + self.created_at = created + + @property + def updated(self): + + if self.updated_at: + return dateutil.parser.parse(self.updated_at) + + @updated.setter + def updated(self, updated): + if updated: + self.updated_at = updated + + class Definitions(BaseObject): """ ###################################################################### diff --git a/zenpy/lib/cache.py b/zenpy/lib/cache.py index c5432716..48d02f65 100644 --- a/zenpy/lib/cache.py +++ b/zenpy/lib/cache.py @@ -126,7 +126,8 @@ def __init__(self, disabled=False): 'sharing_agreement': ZenpyCache('TTLCache', maxsize=10000, ttl=6000), - 'identity': ZenpyCache('LRUCache', maxsize=10000) + 'identity': ZenpyCache('LRUCache', maxsize=10000), + 'custom_status': ZenpyCache('LRUCache', maxsize=1000) } def add(self, zenpy_object): diff --git a/zenpy/lib/endpoint.py b/zenpy/lib/endpoint.py index 39f80d60..e3a40c05 100644 --- a/zenpy/lib/endpoint.py +++ b/zenpy/lib/endpoint.py @@ -574,6 +574,7 @@ class EndpointFactory(object): chats.stream = ChatSearchEndpoint('stream/chats') chats.incremental = ChatIncrementalEndpoint('incremental/chats') custom_agent_roles = PrimaryEndpoint('custom_roles') + custom_statuses = PrimaryEndpoint('custom_statuses') dynamic_contents = PrimaryEndpoint('dynamic_content/items') dynamic_contents.variants = SecondaryEndpoint( 'dynamic_content/items/%(id)s/variants.json') diff --git a/zenpy/lib/mapping.py b/zenpy/lib/mapping.py index bd2a4eb0..68ea1ecb 100644 --- a/zenpy/lib/mapping.py +++ b/zenpy/lib/mapping.py @@ -16,6 +16,7 @@ CreateEvent, CustomAgentRole, CustomFieldOption, + CustomStatus, Definitions, ErrorEvent, Export, @@ -231,7 +232,8 @@ class ZendeskObjectMapping(object): 'invocation_attempt': InvocationAttempt, 'signing_secret': WebhookSecret, 'subscription' : Subscription, - 'vote': Vote + 'vote': Vote, + 'custom_status': CustomStatus } skip_attrs = []