From c815bce44cfdd0261bab502ed24f3f22f6540535 Mon Sep 17 00:00:00 2001 From: Yurui Zhang Date: Mon, 4 Dec 2017 18:16:26 -0500 Subject: [PATCH] adds support for surveyengine.partialResponse --- ...bscription_create_partial_response_sub.yml | 81 +++++++++++++++++++ .../event_subscription_collection.rb | 4 + .../lib/event_subscription_collection_spec.rb | 14 ++++ 3 files changed, 99 insertions(+) create mode 100644 fixtures/vcr_cassettes/event_subscription_create_partial_response_sub.yml diff --git a/fixtures/vcr_cassettes/event_subscription_create_partial_response_sub.yml b/fixtures/vcr_cassettes/event_subscription_create_partial_response_sub.yml new file mode 100644 index 0000000..c7523e3 --- /dev/null +++ b/fixtures/vcr_cassettes/event_subscription_create_partial_response_sub.yml @@ -0,0 +1,81 @@ +--- +http_interactions: +- request: + method: post + uri: https://co1.qualtrics.com/API/v3/eventsubscriptions + body: + encoding: UTF-8 + string: '{"publicationUrl":"https://request.url.fake","topics":"surveyengine.partialResponse.SV_ANOTHER_SURVEY","encrypt":false}' + headers: + X-API-TOKEN: + - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ + User-Agent: + - Faraday v0.9.2 + Content-Type: + - application/json + response: + status: + code: 200 + message: + headers: + request-time: + - '381' + content-type: + - application/json + content-length: + - '123' + x-edgeconnect-midmile-rtt: + - '20' + x-edgeconnect-origin-mex-latency: + - '429' + date: + - Mon, 04 Dec 2017 23:14:25 GMT + connection: + - close + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + body: + encoding: UTF-8 + string: '{"result":{"id":"SUB_0fHFD2hnaSp9veZ"},"meta":{"httpStatus":"200 - + OK","requestId":"cd3306e3-b58b-4930-86d8-77909aeea772"}}' + http_version: + recorded_at: Mon, 04 Dec 2017 23:14:25 GMT +- request: + method: get + uri: https://co1.qualtrics.com/API/v3/eventsubscriptions/SUB_0fHFD2hnaSp9veZ + body: + encoding: US-ASCII + string: '' + headers: + X-API-TOKEN: + - 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ + User-Agent: + - Faraday v0.9.2 + response: + status: + code: 200 + message: + headers: + request-time: + - '226' + content-type: + - application/json + content-length: + - '294' + x-edgeconnect-midmile-rtt: + - '25' + x-edgeconnect-origin-mex-latency: + - '272' + date: + - Mon, 04 Dec 2017 23:14:26 GMT + connection: + - close + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + body: + encoding: UTF-8 + string: '{"result":{"id":"SUB_0fHFD2hnaSp9veZ","scope":"cambridgetripod","topics":"surveyengine.partialResponse.SV_ANOTHER_SURVEY","publicationUrl":"https://request.url.fake","encrypted":false,"successfulCalls":0},"meta":{"httpStatus":"200 + - OK","requestId":"2d448524-8850-4865-82c1-2a8923f3ee2c"}}' + http_version: + recorded_at: Mon, 04 Dec 2017 23:14:26 GMT +recorded_with: VCR 2.9.3 diff --git a/lib/qualtrics_api/event_subscription_collection.rb b/lib/qualtrics_api/event_subscription_collection.rb index 2a68169..e7d51de 100644 --- a/lib/qualtrics_api/event_subscription_collection.rb +++ b/lib/qualtrics_api/event_subscription_collection.rb @@ -17,6 +17,10 @@ def create_completed_response_subscription(url, survey_id, opts = { encrypt: fal create(url, "surveyengine.completedResponse.#{survey_id}", opts) end + def create_partial_response_subscription(url, survey_id, opts = { encrypt: false }) + create(url, "surveyengine.partialResponse.#{survey_id}", opts) + end + def delete(id) QualtricsAPI.connection(self) .delete(endpoint(id)) diff --git a/spec/lib/event_subscription_collection_spec.rb b/spec/lib/event_subscription_collection_spec.rb index 79a3c40..88b910d 100644 --- a/spec/lib/event_subscription_collection_spec.rb +++ b/spec/lib/event_subscription_collection_spec.rb @@ -46,6 +46,20 @@ end end end + + describe "#create_completed_response_subscription" do + it "creates a subscription to the partialResponse event of the survey id specified" do + VCR.use_cassette("event_subscription_create_partial_response_sub") do + survey_id = 'SV_ANOTHER_SURVEY' + url = 'https://request.url.fake' + result = subject.create_partial_response_subscription(url, survey_id) + expect(result).to be_a QualtricsAPI::EventSubscription + expect(result.id).to_not be_nil + expect(result.publication_url).to eq url + expect(result.topics).to eq "surveyengine.partialResponse.#{survey_id}" + end + end + end end describe "#delete" do