From 03e5c7d5c5f88f86a266a3f98c941dbbc6568133 Mon Sep 17 00:00:00 2001 From: Thomas Stachl Date: Fri, 6 Sep 2013 15:03:32 -0700 Subject: [PATCH] don't allow updating a closed case, fixed #10 --- lib/desk_api/action/update.rb | 5 + lib/desk_api/error/not_updateable.rb | 10 ++ .../once_closed/can_not_be_updated.yml | 124 ++++++++++++++++++ spec/desk_api/resource/case_spec.rb | 28 ++++ 4 files changed, 167 insertions(+) create mode 100644 lib/desk_api/error/not_updateable.rb create mode 100644 spec/cassettes/DeskApi_Resource_Case/once_closed/can_not_be_updated.yml create mode 100644 spec/desk_api/resource/case_spec.rb diff --git a/lib/desk_api/action/update.rb b/lib/desk_api/action/update.rb index 82d48cd..bed85ab 100644 --- a/lib/desk_api/action/update.rb +++ b/lib/desk_api/action/update.rb @@ -2,9 +2,14 @@ module DeskApi module Action module Update def update(params = {}) + if kind_of?(resource('case')) and status == 'closed' + raise DeskApi::Error::NotUpdateable + end + params.each_pair do |key, value| send("#{key}=", value) if respond_to?("#{key}=") end + setup(client.patch(@_links.self.href, @_changed).body) end end diff --git a/lib/desk_api/error/not_updateable.rb b/lib/desk_api/error/not_updateable.rb new file mode 100644 index 0000000..702922c --- /dev/null +++ b/lib/desk_api/error/not_updateable.rb @@ -0,0 +1,10 @@ +require 'desk_api/error' + +module DeskApi + class Error + # Raised when an updateable resources becomes non-updateable + # and you try to update it + class NotUpdateable < DeskApi::Error + end + end +end \ No newline at end of file diff --git a/spec/cassettes/DeskApi_Resource_Case/once_closed/can_not_be_updated.yml b/spec/cassettes/DeskApi_Resource_Case/once_closed/can_not_be_updated.yml new file mode 100644 index 0000000..653108e --- /dev/null +++ b/spec/cassettes/DeskApi_Resource_Case/once_closed/can_not_be_updated.yml @@ -0,0 +1,124 @@ +--- +http_interactions: +- request: + method: get + uri: https://devel.desk.com/api/v2/customers + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/json + User-Agent: + - desk.com Ruby Gem v0.1.2 + response: + status: + code: 200 + message: + headers: + Accept-Ranges: + - bytes + Cache-Control: + - must-revalidate, private, max-age=0 + Content-Type: + - application/json; charset=utf-8 + Date: + - Fri, 06 Sep 2013 21:59:05 GMT + ETag: + - '"e60e588bcd3e052370e36555fc307738"' + Status: + - 200 OK + Vary: + - X-AppVersion + X-AppVersion: + - '9.9' + X-Frame-Options: + - SAMEORIGIN + X-Rate-Limit-Limit: + - '60' + X-Rate-Limit-Remaining: + - '59' + X-Rate-Limit-Reset: + - '55' + X-Request-Id: + - de1a0bfc6a858410f780bc8f2386be51 + Content-Length: + - '31501' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"total_entries":189,"_links":{"self":{"href":"/api/v2/customers?page=1&per_page=50","class":"page"},"first":{"href":"/api/v2/customers?page=1&per_page=50","class":"page"},"last":{"href":"/api/v2/customers?page=4&per_page=50","class":"page"},"previous":null,"next":{"href":"/api/v2/customers?page=2&per_page=50","class":"page"}},"_embedded":{"entries":[{"first_name":"Alex","last_name":"Bard","company":"Desk.com","title":"CEO","external_id":null,"background":"Wowing + customer","language":null,"locked_until":null,"created_at":"2012-06-06T14:51:30Z","updated_at":"2013-08-20T18:45:04Z","custom_fields":{"my_custom_field":"","my_number_field":"0","my_boolean_field":"0","my_date_field":"","my_list_field":"Option + 1"},"emails":[{"type":"work","value":"support@desk.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/34290812","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/138963","class":"company"},"cases":{"href":"/api/v2/customers/34290812/cases","class":"case"}}},{"first_name":"Stella","last_name":"Pavlova","company":"Morpon + Brothers","title":"SVP Production","external_id":null,"background":"","language":null,"locked_until":null,"created_at":"2012-06-06T15:01:44Z","updated_at":"2012-12-07T23:56:00Z","custom_fields":{"my_custom_field":"","my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/34292086","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/138965","class":"company"},"cases":{"href":"/api/v2/customers/34292086/cases","class":"case"}}},{"first_name":"Mike","last_name":"Malmin","company":"Mike + Malmin","title":"","external_id":null,"background":"","language":null,"locked_until":null,"created_at":"2012-06-07T13:50:04Z","updated_at":"2012-12-07T23:56:00Z","custom_fields":{"my_custom_field":"","my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/34406867","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/138578","class":"company"},"cases":{"href":"/api/v2/customers/34406867/cases","class":"case"}}},{"first_name":"Janice","last_name":"Bergman","company":"Data + Mart","title":"VP Purchasing","external_id":null,"background":"","language":null,"locked_until":null,"created_at":"2012-06-07T14:07:13Z","updated_at":"2012-12-07T23:56:00Z","custom_fields":{"my_custom_field":"","my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/34408491","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/138446","class":"company"},"cases":{"href":"/api/v2/customers/34408491/cases","class":"case"}}},{"first_name":"Bob","last_name":"Hodges","company":"United + Partners*","title":"President and CEO","external_id":null,"background":"","language":null,"locked_until":null,"created_at":"2012-06-22T21:56:31Z","updated_at":"2012-12-07T23:56:01Z","custom_fields":{"my_custom_field":"","my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/36328589","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/113131","class":"company"},"cases":{"href":"/api/v2/customers/36328589/cases","class":"case"}}},{"first_name":"Ron","last_name":"Adkins","company":"Valley + Supply Inc.","title":"President Sales Exec Finance Exec","external_id":null,"background":"","language":null,"locked_until":null,"created_at":"2012-06-25T21:12:05Z","updated_at":"2012-12-07T23:56:01Z","custom_fields":{"my_custom_field":"","my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/36652658","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/114536","class":"company"},"cases":{"href":"/api/v2/customers/36652658/cases","class":"case"}}},{"first_name":"Thomas","last_name":"Stachl","company":"stachl.me","title":"Master + of Script Artistry","external_id":null,"background":"Some Background information.","language":"de","locked_until":null,"created_at":"2012-07-04T14:33:39Z","updated_at":"2013-07-15T18:10:21Z","custom_fields":{"my_custom_field":"","my_number_field":"0","my_boolean_field":"0","my_date_field":"","my_list_field":"Option + 1"},"emails":[{"type":"home","value":"thomas@stachl.me"},{"type":"home","value":"tstachl@salesforce.com"}],"phone_numbers":[{"type":"mobile","value":"4156060761"}],"addresses":[{"type":"home","value":"600 + William Street #526\nOakland, CA 94612"}],"_links":{"self":{"href":"/api/v2/customers/37823480","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/373760","class":"company"},"cases":{"href":"/api/v2/customers/37823480/cases","class":"case"}}},{"first_name":"Lauren","last_name":"Boyle*","company":"mailinator.com","title":"","external_id":"0033000001JLAZrAAP","background":"","language":null,"locked_until":null,"created_at":"2012-12-07T23:36:46Z","updated_at":"2013-04-13T03:47:03Z","custom_fields":{"my_custom_field":"","my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"work","value":"lauren.boyle@mailinator.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/58278628","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/2278303","class":"company"},"cases":{"href":"/api/v2/customers/58278628/cases","class":"case"}}},{"first_name":"Sandy","last_name":"Knudson","company":"mailinator.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-02-28T19:28:28Z","updated_at":"2013-02-28T19:45:43Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"work","value":"sandyknudson@mailinator.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/71433005","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/2278303","class":"company"},"cases":{"href":"/api/v2/customers/71433005/cases","class":"case"}}},{"first_name":"Brad","last_name":"Anastasio","company":"fakeemail.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-01T13:51:56Z","updated_at":"2013-03-01T13:51:56Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"work","value":"brad.anastasio@fakeemail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/71579966","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4036540","class":"company"},"cases":{"href":"/api/v2/customers/71579966/cases","class":"case"}}},{"first_name":"Leena","last_name":"Cianflone","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-22T23:49:45Z","updated_at":"2013-03-22T23:49:45Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"leenacianflone@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/75923712","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/75923712/cases","class":"case"}}},{"first_name":"Quinton","last_name":"Swanda","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-22T23:49:45Z","updated_at":"2013-03-22T23:49:45Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"quintonswanda@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/75923713","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/75923713/cases","class":"case"}}},{"first_name":"Jennifer","last_name":"Hansen","company":"zendesk.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-22T23:49:46Z","updated_at":"2013-03-22T23:49:46Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"jennifer@zendesk.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/75923714","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4451253","class":"company"},"cases":{"href":"/api/v2/customers/75923714/cases","class":"case"}}},{"first_name":"Hue","last_name":"Gottesman","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-22T23:49:46Z","updated_at":"2013-03-22T23:49:46Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"huegottesman@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/75923715","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/75923715/cases","class":"case"}}},{"first_name":"Hal","last_name":"Raxter","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-22T23:49:47Z","updated_at":"2013-03-22T23:49:47Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"raxterhal@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/75923716","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/75923716/cases","class":"case"}}},{"first_name":"Colmo","last_name":"","company":"zendesk.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-22T23:49:47Z","updated_at":"2013-03-22T23:49:47Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"colmo@zendesk.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/75923717","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4451253","class":"company"},"cases":{"href":"/api/v2/customers/75923717/cases","class":"case"}}},{"first_name":"Brice","last_name":"Baggenstoss","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-22T23:49:47Z","updated_at":"2013-03-22T23:49:47Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"bricebaggenstoss@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/75923718","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/75923718/cases","class":"case"}}},{"first_name":"Support","last_name":"","company":"zendesk.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-22T23:49:47Z","updated_at":"2013-03-22T23:49:47Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"support@zendesk.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/75923719","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4451253","class":"company"},"cases":{"href":"/api/v2/customers/75923719/cases","class":"case"}}},{"first_name":"Noreply","last_name":"","company":"postmaster.twitter.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-22T23:49:48Z","updated_at":"2013-03-22T23:49:48Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"noreply@postmaster.twitter.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/75923720","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4451254","class":"company"},"cases":{"href":"/api/v2/customers/75923720/cases","class":"case"}}},{"first_name":"Hal","last_name":"Schellhase","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-22T23:49:48Z","updated_at":"2013-03-22T23:49:48Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"halschellhase@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/75923721","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/75923721/cases","class":"case"}}},{"first_name":"Test","last_name":"Tester","company":"example.com","title":"CEO","external_id":null,"background":"","language":"en","locked_until":null,"created_at":"2013-03-27T17:35:51Z","updated_at":"2013-03-27T18:04:48Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"work","value":"tester@example.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/76863359","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4543697","class":"company"},"cases":{"href":"/api/v2/customers/76863359/cases","class":"case"}}},{"first_name":"barr_tim","last_name":"","company":"grandhotels.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-03-29T00:04:09Z","updated_at":"2013-04-15T23:59:05Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"barr_tim@grandhotels.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/77160792","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4574466","class":"company"},"cases":{"href":"/api/v2/customers/77160792/cases","class":"case"}}},{"first_name":"John","last_name":"","company":"example.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-06T22:12:56Z","updated_at":"2013-04-15T16:42:57Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"john@example.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/78914102","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4543697","class":"company"},"cases":{"href":"/api/v2/customers/78914102/cases","class":"case"}}},{"first_name":"Stachl","last_name":"Testing + Page","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-08T20:06:40Z","updated_at":"2013-04-08T20:06:40Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/79246639","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/79246639/cases","class":"case"}}},{"first_name":"Thomas","last_name":"Stachl","company":null,"title":null,"external_id":null,"background":null,"language":"en_us","locked_until":null,"created_at":"2013-04-08T20:18:56Z","updated_at":"2013-04-08T20:18:56Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/79249149","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/79249149/cases","class":"case"}}},{"first_name":"Andrew","last_name":"Frauen","company":null,"title":null,"external_id":null,"background":null,"language":"en","locked_until":null,"created_at":"2013-04-11T17:39:26Z","updated_at":"2013-04-11T17:39:26Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"frauen.a@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/79858779","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/79858779/cases","class":"case"}}},{"first_name":null,"last_name":null,"company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-12T23:46:33Z","updated_at":"2013-04-12T23:46:33Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/80192856","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/80192856/cases","class":"case"}}},{"first_name":null,"last_name":null,"company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-12T23:48:05Z","updated_at":"2013-04-12T23:48:05Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/80193061","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/80193061/cases","class":"case"}}},{"first_name":null,"last_name":null,"company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-13T02:37:48Z","updated_at":"2013-04-13T02:37:48Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/80212952","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/80212952/cases","class":"case"}}},{"first_name":null,"last_name":null,"company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-13T02:39:12Z","updated_at":"2013-04-13T02:39:12Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/80213083","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/80213083/cases","class":"case"}}},{"first_name":null,"last_name":null,"company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-13T02:40:10Z","updated_at":"2013-04-13T02:40:10Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/80213160","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/80213160/cases","class":"case"}}},{"first_name":null,"last_name":null,"company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-13T02:41:53Z","updated_at":"2013-04-13T02:41:53Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/80213349","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/80213349/cases","class":"case"}}},{"first_name":null,"last_name":null,"company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-13T02:43:59Z","updated_at":"2013-04-13T02:43:59Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/80213634","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/80213634/cases","class":"case"}}},{"first_name":null,"last_name":null,"company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-13T02:45:57Z","updated_at":"2013-04-13T02:45:57Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/80213888","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/80213888/cases","class":"case"}}},{"first_name":null,"last_name":null,"company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-13T02:46:52Z","updated_at":"2013-04-13T02:46:52Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/80214018","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/80214018/cases","class":"case"}}},{"first_name":"John","last_name":"Smith","company":"Glorious + D","title":"Senior Vice President of Awesome","external_id":null,"background":"Some + description.","language":null,"locked_until":null,"created_at":"2013-04-15T16:58:30Z","updated_at":"2013-04-15T16:58:31Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"john@gd.com"}],"phone_numbers":[{"type":"home","value":"4155551235"}],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/80640812","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4912151","class":"company"},"cases":{"href":"/api/v2/customers/80640812/cases","class":"case"}}},{"first_name":"Larita","last_name":"Villas","company":null,"title":null,"external_id":null,"background":"","language":null,"locked_until":null,"created_at":"2013-04-22T22:37:00Z","updated_at":"2013-04-22T22:37:00Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"laritavillas@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113673","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/82113673/cases","class":"case"}}},{"first_name":"Nolan","last_name":"Gett","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:37:01Z","updated_at":"2013-04-22T22:37:01Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"nolangett@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113675","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/82113675/cases","class":"case"}}},{"first_name":"Moises","last_name":"Sabio","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:37:02Z","updated_at":"2013-04-22T22:37:02Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"sabiomoises@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113682","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/82113682/cases","class":"case"}}},{"first_name":"Twitter","last_name":"","company":"postmaster.twitter.com","title":null,"external_id":null,"background":"","language":null,"locked_until":null,"created_at":"2013-04-22T22:37:02Z","updated_at":"2013-04-22T22:37:02Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"n-tybonyfhespb=tznvy.pbz-9b29b@postmaster.twitter.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113684","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4451254","class":"company"},"cases":{"href":"/api/v2/customers/82113684/cases","class":"case"}}},{"first_name":"Zendesk","last_name":"","company":"zendesk.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:37:03Z","updated_at":"2013-04-22T22:37:03Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"noreply@zendesk.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113685","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/4451253","class":"company"},"cases":{"href":"/api/v2/customers/82113685/cases","class":"case"}}},{"first_name":"Richie","last_name":"Kalter","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:37:03Z","updated_at":"2013-04-22T22:37:03Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"richiekalter11@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113689","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/82113689/cases","class":"case"}}},{"first_name":"The","last_name":"Desk.com + Team","company":"Desk.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:37:04Z","updated_at":"2013-04-22T22:37:04Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"welcome@desk.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113693","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/138963","class":"company"},"cases":{"href":"/api/v2/customers/82113693/cases","class":"case"}}},{"first_name":"Rupert","last_name":"Warstler","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:37:04Z","updated_at":"2013-04-22T22:37:04Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"rupertwarstler@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113694","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/82113694/cases","class":"case"}}},{"first_name":"Suzy","last_name":"Galicinao","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:38:00Z","updated_at":"2013-04-22T22:38:00Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"suzygalicinao@gmail.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113926","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/82113926/cases","class":"case"}}},{"first_name":"ashley","last_name":"lawrence","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:38:01Z","updated_at":"2013-04-22T22:38:01Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113930","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/82113930/cases","class":"case"}}},{"first_name":"Keshia","last_name":"Hohenstein","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:38:01Z","updated_at":"2013-04-22T22:38:01Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113931","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/82113931/cases","class":"case"}}},{"first_name":"Alex","last_name":"Hisaka","company":"Desk.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:38:01Z","updated_at":"2013-04-22T22:38:02Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"alex.hisaka@desk.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113933","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/138963","class":"company"},"cases":{"href":"/api/v2/customers/82113933/cases","class":"case"}}},{"first_name":"seethaji","last_name":"","company":null,"title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:38:02Z","updated_at":"2013-04-22T22:38:02Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"seethaji@yahoo.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113936","class":"customer"},"locked_by":null,"cases":{"href":"/api/v2/customers/82113936/cases","class":"case"}}},{"first_name":"Sukhjit","last_name":"","company":"Desk.com","title":null,"external_id":null,"background":null,"language":null,"locked_until":null,"created_at":"2013-04-22T22:38:02Z","updated_at":"2013-04-22T22:38:02Z","custom_fields":{"my_custom_field":null,"my_number_field":null,"my_boolean_field":null,"my_date_field":null,"my_list_field":null},"emails":[{"type":"home","value":"sukhjit@desk.com"}],"phone_numbers":[],"addresses":[],"_links":{"self":{"href":"/api/v2/customers/82113939","class":"customer"},"locked_by":null,"company":{"href":"/api/v2/companies/138963","class":"company"},"cases":{"href":"/api/v2/customers/82113939/cases","class":"case"}}}]}}' + http_version: + recorded_at: Fri, 06 Sep 2013 21:59:05 GMT +- request: + method: post + uri: https://devel.desk.com/api/v2/customers/34290812/cases + body: + encoding: UTF-8 + string: '{"type":"phone","subject":"Phone Case Subject","priority":4,"status":"closed","message":{"direction":"in","body":"Example + Body"}}' + headers: + Accept: + - application/json + User-Agent: + - desk.com Ruby Gem v0.1.2 + Content-Type: + - application/json + response: + status: + code: 201 + message: + headers: + Accept-Ranges: + - bytes + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/json; charset=utf-8 + Date: + - Fri, 06 Sep 2013 21:59:05 GMT + ETag: + - '"8b8c5604fbc6d1fad236c6c47663b87d"' + Location: + - https://devel.desk.com/api/v2/cases/3344 + Status: + - 201 Created + Vary: + - X-AppVersion + X-AppVersion: + - '9.9' + X-Frame-Options: + - SAMEORIGIN + X-Rate-Limit-Limit: + - '60' + X-Rate-Limit-Remaining: + - '58' + X-Rate-Limit-Reset: + - '55' + X-Request-Id: + - 19249bfef63cea6a01a2e45c2137ce09 + Content-Length: + - '877' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"external_id":null,"subject":"Phone Case Subject","priority":4,"locked_until":null,"description":null,"status":"closed","type":"phone","labels":[],"language":"de","active_at":null,"created_at":"2013-09-06T21:59:05Z","updated_at":"2013-09-06T21:59:05Z","received_at":null,"custom_fields":{"my_new_custom_field":null,"my_new_number_field":null,"my_new_date_field":null,"my_new_boolean_field":null,"my_new_list_field":null},"_links":{"self":{"href":"/api/v2/cases/3344","class":"case"},"message":{"href":"/api/v2/cases/3344/message","class":"phone"},"customer":{"href":"/api/v2/customers/34290812","class":"customer"},"assigned_user":null,"assigned_group":null,"locked_by":null,"replies":{"href":"/api/v2/cases/3344/replies","class":"reply"},"notes":{"href":"/api/v2/cases/3344/notes","class":"note"},"attachments":{"href":"/api/v2/cases/3344/attachments","class":"attachment"}}}' + http_version: + recorded_at: Fri, 06 Sep 2013 21:59:05 GMT +recorded_with: VCR 2.5.0 diff --git a/spec/desk_api/resource/case_spec.rb b/spec/desk_api/resource/case_spec.rb new file mode 100644 index 0000000..c878116 --- /dev/null +++ b/spec/desk_api/resource/case_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' +require 'desk_api/error/not_updateable' +require 'desk_api/resource/case' + +describe DeskApi::Resource::Case do + subject do + @client ||= DeskApi::Client.new DeskApi::CONFIG + end + + context 'once closed', :vcr do + before do + @kase = subject.customers.first.cases.create({ + type: 'phone', + subject: 'Phone Case Subject', + priority: 4, + status: 'closed', + message: { + direction: 'in', + body: 'Example Body' + } + }) + end + + it 'can not be updated' do + lambda { @kase.update(description: 'Testing') }.should raise_error(DeskApi::Error::NotUpdateable) + end + end +end \ No newline at end of file