From d320e5889e3ab6fb8518e74a4453eef59e394fd7 Mon Sep 17 00:00:00 2001 From: atom Date: Tue, 5 May 2026 17:08:27 -0700 Subject: [PATCH] PLAT-300: Add HTTP PATCH method --- lib/spark_api/request.rb | 13 +++++++++++++ spec/unit/spark_api/request_spec.rb | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/spark_api/request.rb b/lib/spark_api/request.rb index f4363a5..bb16cc0 100644 --- a/lib/spark_api/request.rb +++ b/lib/spark_api/request.rb @@ -42,6 +42,19 @@ def put(path, body = nil, options={}) request(:put, path, body, options) end + # Perform an HTTP PATCH request + # + # * path - Path of an api resource, excluding version and endpoint (domain) information + # * body - Hash for patch body data + # * options - Resource request options as specified being supported via and api resource + # :returns: + # Hash of the json results as documented in the api. + # :raises: + # SparkApi::ClientError or subclass if the request failed. + def patch(path, body = nil, options={}) + request(:patch, path, body, options) + end + # Perform an HTTP DELETE request # # * path - Path of an api resource, excluding version and endpoint (domain) information diff --git a/spec/unit/spark_api/request_spec.rb b/spec/unit/spark_api/request_spec.rb index ebac4b1..3634888 100644 --- a/spec/unit/spark_api/request_spec.rb +++ b/spec/unit/spark_api/request_spec.rb @@ -120,8 +120,11 @@ } stub.put('/v1/arraydata?ApiSig=SignedToken&AuthToken=1234', '{"D":["A","B","C"]}') {[200, {}, '{"D": { "Success": true}}']} + stub.patch('/v1/contacts/1000?ApiSig=SignedToken&AuthToken=1234', '{"D":{"Contacts":[{"DisplayName":"WLMCEWENS Contact","PrimaryEmail":"wlmcewen789@fbsdata.com"}]}}') { [200, {}, '{"D": { + "Success": true}}'] + } stub.delete('/v1/contacts/1000?ApiSig=SignedToken&AuthToken=1234') { [200, {}, '{"D": { - "Success": true}}'] + "Success": true}}'] } # Other MISC requests stub.post('/v1/stringdata?ApiSig=SignedToken&AuthToken=1234', 'I am a lonely String!') { [200, {}, '{"D": { @@ -214,6 +217,11 @@ def version() expect(subject.put('/contacts/1000', data).size).to be(0) # No validation here, if no error is raised, everything is hunky dory end + it "should patch to a service" do + data = {"Contacts" => [{"DisplayName"=>"WLMCEWENS Contact","PrimaryEmail"=>"wlmcewen789@fbsdata.com"}]} + expect(subject.patch('/contacts/1000', data).size).to be(0) + # No validation here, if no error is raised, everything is hunky dory + end it "should delete from a service" do # This is a hypothetical unsupported service action at this time expect(subject.delete('/contacts/1000').size).to be(0)