qualtrics_api 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ module QualtricsAPI
2
+ class QuestionCollection < BaseCollection
3
+ def [](survey_id, question_id)
4
+ find(survey_id, question_id)
5
+ end
6
+
7
+ def find(survey_id, question_id)
8
+ response = QualtricsAPI.connection(self).get(endpoint(survey_id, question_id))
9
+ return nil unless response.status == 200
10
+ build_result(response.body['result']).propagate_connection(self)
11
+ end
12
+
13
+ def each(survey_id)
14
+ page = each_page(survey_id)
15
+ page.each do |element|
16
+ yield element
17
+ end
18
+ end
19
+
20
+ def each_page(survey_id)
21
+ endpoint = list_endpoint(survey_id)
22
+ response = QualtricsAPI.connection(self).get(endpoint)
23
+ parse_page(response)
24
+ end
25
+
26
+ protected
27
+
28
+ def page_endpoint(fetched)
29
+ raise NotSupported
30
+ end
31
+
32
+ private
33
+
34
+ def build_result(element)
35
+ QualtricsAPI::Question.new(element)
36
+ end
37
+
38
+ def list_endpoint(survey_id)
39
+ "survey-definitions/#{survey_id}/questions"
40
+ end
41
+
42
+ def endpoint(survey_id, question_id)
43
+ "survey-definitions/#{survey_id}/questions/#{question_id}"
44
+ end
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module QualtricsAPI
2
- VERSION = "0.0.15".freeze
2
+ VERSION = "0.0.16".freeze
3
3
  end
@@ -15,6 +15,12 @@ describe QualtricsAPI::Client do
15
15
  end
16
16
  end
17
17
 
18
+ describe "#questions" do
19
+ it "returns a QuestionCollection" do
20
+ expect(subject.questions).to be_a QualtricsAPI::QuestionCollection
21
+ end
22
+ end
23
+
18
24
  describe "#initialize" do
19
25
  subject { QualtricsAPI::Client }
20
26
 
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::DistributionCollection do
4
+ describe "integration" do
5
+ subject { described_class.new(id: 'ABCD') }
6
+
7
+ describe '#create' do
8
+ let(:distribution) do
9
+ QualtricsAPI::Distribution.new(
10
+ action: "CreateDistribution",
11
+ survey_id: "SV_eVtvUQALTlL8Uzr",
12
+ mailing_list_id: "ML_3wO6vOd0yrRezyd",
13
+ description: "Foobar",
14
+ expiration_date: nil,
15
+ link_type: 'Individual'
16
+ )
17
+ end
18
+ let(:result) do
19
+ VCR.use_cassette(cassette, record: :once) do
20
+ QualtricsAPI::DistributionCollection.new.create(distribution)
21
+ end
22
+ end
23
+
24
+ describe 'when success' do
25
+ let(:cassette) { 'distribution_create_success' }
26
+
27
+ it 'returns distribution' do
28
+ expect(result).to be_a QualtricsAPI::Distribution
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::DistributionLinkCollection do
4
+ describe "integration" do
5
+ subject { described_class.new('SV_eVtvUQALTlL8Uzr', 'EMD_9A7FZioL5pgWZJb') }
6
+
7
+ describe "#find" do
8
+ # There's no API endpoint for retrieving a single distribution link that I can see.
9
+ it 'is not implemented' do
10
+ expect { subject.find('foo') }.to raise_exception(NotImplementedError)
11
+ end
12
+ end
13
+
14
+ describe "#fetch" do
15
+ describe "when success" do
16
+ let!(:result) do
17
+ VCR.use_cassette("distribution_link_collection_fetch_sucess", record: :once) do
18
+ subject.each_page do |page|
19
+ return page
20
+ end
21
+ end
22
+ end
23
+
24
+ it "populates the collection" do
25
+ expect(result.size).to eq 100
26
+ expect(result.first).to be_a QualtricsAPI::DistributionLink
27
+ end
28
+ end
29
+
30
+ describe "when failed" do
31
+ subject { described_class.new('SV_eVtvUQALTlL8Uzr', 'EMD_9A7FZioL5pgxxxx') }
32
+
33
+ it "raises error" do
34
+ VCR.use_cassette("distribution_link_collection_fetch_fail", record: :once) do
35
+ expect { subject.each_page }.to raise_error(QualtricsAPI::NotFoundError)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ describe 'pagination' do
42
+ it 'fetches pages from list endpoint' do
43
+ page1 = page2 = nil
44
+ VCR.use_cassette("distribution_link_collection_pagination") do
45
+ page_no = 0
46
+ max_pages = 2
47
+ subject.each_page do |page|
48
+ break if page_no == max_pages
49
+ if page_no == 0
50
+ page1 = page
51
+ elsif page_no == 1
52
+ page2 = page
53
+ else
54
+ raise 'should not iterate here'
55
+ end
56
+ page_no += 1
57
+ end
58
+ expect(page1).not_to be_nil
59
+ expect(page2).not_to be_nil
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
File without changes
File without changes
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::QuestionCollection do
4
+ describe "integration" do
5
+ subject { described_class.new }
6
+ let(:survey_id) { 'SV_a2AcbPZz1DehlOd' }
7
+ let(:missing_survey_id) { 'SV_a2AcbPZz1Dxxxx' }
8
+ let(:question_id) { 'QID1' }
9
+ let(:missing_question_id) { 'QID1xxxx' }
10
+ let(:question_attr_keys) do
11
+ %i[
12
+ question_text
13
+ data_export_tag
14
+ question_type
15
+ selector
16
+ sub_selector
17
+ configuration
18
+ question_description
19
+ choices
20
+ choice_order
21
+ validation
22
+ language
23
+ next_choice_id
24
+ next_answer_id
25
+ question_id
26
+ question_text_unsafe
27
+ ]
28
+ end
29
+
30
+ describe "#find" do
31
+ context 'when exists' do
32
+ let!(:result) do
33
+ VCR.use_cassette("question_find") do
34
+ subject.find(survey_id, question_id)
35
+ end
36
+ end
37
+
38
+ it 'populates the result' do
39
+ expect(result.attributes.keys).to match_array(question_attr_keys)
40
+ end
41
+ end
42
+
43
+ context 'when does not exist' do
44
+ let!(:result) do
45
+ VCR.use_cassette("question_find_fail") do
46
+ subject.find(missing_survey_id, missing_question_id)
47
+ end
48
+ end
49
+
50
+ it 'raises error', skip: 'API Bug' do
51
+ # TODO: API returns 403 in this case. 404 seems more appropriate.
52
+ # expect { result }.to raise_error(QualtricsAPI::NotFoundError)
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "#fetch" do
58
+ describe "when success" do
59
+ let!(:result) do
60
+ VCR.use_cassette("question_collection_fetch_success") do
61
+ subject.each_page(survey_id) do |page|
62
+ return page
63
+ end
64
+ end
65
+ end
66
+
67
+ it "populates the collection" do
68
+ expect(result.first).to be_a QualtricsAPI::Question
69
+ end
70
+ end
71
+
72
+ describe "when failed" do
73
+ let!(:result) do
74
+ VCR.use_cassette("question_collection_fetch_fail") do
75
+ subject.each_page(missing_survey_id)
76
+ end
77
+ end
78
+
79
+ it "raises error", skip: 'API Bug' do
80
+ # TODO: API returns 403 in this case. 404 seems more appropriate.
81
+ # expect { result }.to raise_error(QualtricsAPI::NotFoundError)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::Question do
4
+ let(:qualtrics_response) do
5
+ {
6
+ "QuestionText" => "Who is your favorite writer?",
7
+ "DataExportTag" => "Q1",
8
+ "QuestionType" => "MC",
9
+ "Selector" => "SAVR",
10
+ "SubSelector" => "TX",
11
+ "Configuration" => {
12
+ "QuestionDescriptionOption" => "UseText"
13
+ },
14
+ "QuestionDescription" => "Who is your favorite writer?",
15
+ "Choices" => {
16
+ "1" => {
17
+ "Display" => "Thomas Mann"
18
+ },
19
+ "2" => {
20
+ "Display" => "Albert Camus"
21
+ },
22
+ "3" => {
23
+ "Display" => "Anton Chekov"
24
+ }
25
+ },
26
+ "ChoiceOrder" => [
27
+ 1,
28
+ 2,
29
+ 3
30
+ ],
31
+ "Validation" => {
32
+ "Settings" => {
33
+ "ForceResponse" => "OFF",
34
+ "ForceResponseType" => "ON",
35
+ "Type" => "None"
36
+ }
37
+ },
38
+ "Language" => [],
39
+ "NextChoiceId" => 4,
40
+ "NextAnswerId" => 1,
41
+ "QuestionID" => "QID1",
42
+ "QuestionText_Unsafe" => "Who is your favorite writer?"
43
+ }
44
+ end
45
+
46
+ subject { described_class.new qualtrics_response }
47
+
48
+ it "has question text" do
49
+ expect(subject.question_text).to eq qualtrics_response["QuestionText"]
50
+ end
51
+
52
+ it "has a data export tag" do
53
+ expect(subject.data_export_tag).to eq qualtrics_response["DataExportTag"]
54
+ end
55
+
56
+ it "has a question type" do
57
+ expect(subject.question_type).to eq qualtrics_response["QuestionType"]
58
+ end
59
+
60
+ it "has a selector" do
61
+ expect(subject.selector).to eq qualtrics_response["Selector"]
62
+ end
63
+
64
+ it "has a sub selector" do
65
+ expect(subject.sub_selector).to eq qualtrics_response["SubSelector"]
66
+ end
67
+
68
+ it "has a configuration" do
69
+ expect(subject.configuration).to eq qualtrics_response["Configuration"]
70
+ end
71
+
72
+ it "has a question description" do
73
+ expect(subject.question_description).to eq qualtrics_response["QuestionDescription"]
74
+ end
75
+
76
+ it "has choices" do
77
+ expect(subject.choices).to eq qualtrics_response["Choices"]
78
+ end
79
+
80
+ it "has a choice order" do
81
+ expect(subject.choice_order).to eq qualtrics_response["ChoiceOrder"]
82
+ end
83
+
84
+ it "has validation" do
85
+ expect(subject.validation).to eq qualtrics_response["Validation"]
86
+ end
87
+
88
+ it "has a language" do
89
+ expect(subject.language).to eq qualtrics_response["Language"]
90
+ end
91
+
92
+ it "has a next choice id" do
93
+ expect(subject.next_choice_id).to eq qualtrics_response["NextChoiceId"]
94
+ end
95
+
96
+ it "has a next answer id" do
97
+ expect(subject.next_answer_id).to eq qualtrics_response["NextAnswerId"]
98
+ end
99
+
100
+ it "has a question id" do
101
+ expect(subject.question_id).to eq qualtrics_response["QuestionID"]
102
+ end
103
+
104
+ it "has question text (unsafe)" do
105
+ expect(subject.question_text_unsafe).to eq qualtrics_response["QuestionText_Unsafe"]
106
+ end
107
+
108
+ describe 'equality' do
109
+ context 'when same' do
110
+ it 'returns true' do
111
+ expect(subject).to eq(described_class.new(subject.attributes))
112
+ end
113
+ end
114
+
115
+ context 'when different' do
116
+ it 'returns false' do
117
+ expect(subject).not_to eq(described_class.new)
118
+ end
119
+ end
120
+ end
121
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qualtrics_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yurui Zhang
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-01-08 00:00:00.000000000 Z
13
+ date: 2019-07-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
@@ -129,6 +129,11 @@ files:
129
129
  - LICENSE.txt
130
130
  - README.md
131
131
  - Rakefile
132
+ - fixtures/vcr_cassettes/distribution_create_success.yml
133
+ - fixtures/vcr_cassettes/distribution_link_collection_fetch_fail.yml
134
+ - fixtures/vcr_cassettes/distribution_link_collection_fetch_sucess.yml
135
+ - fixtures/vcr_cassettes/distribution_link_collection_pagination.yml
136
+ - fixtures/vcr_cassettes/distribution_links.yml
132
137
  - fixtures/vcr_cassettes/event_subscription_create.yml
133
138
  - fixtures/vcr_cassettes/event_subscription_create_partial_response_sub.yml
134
139
  - fixtures/vcr_cassettes/event_subscription_create_response_sub.yml
@@ -147,6 +152,10 @@ files:
147
152
  - fixtures/vcr_cassettes/panel_member_collection_fetch_success.yml
148
153
  - fixtures/vcr_cassettes/panel_member_single_create_failure.yml
149
154
  - fixtures/vcr_cassettes/panel_member_single_create_success.yml
155
+ - fixtures/vcr_cassettes/question_collection_fetch_fail.yml
156
+ - fixtures/vcr_cassettes/question_collection_fetch_success.yml
157
+ - fixtures/vcr_cassettes/question_find.yml
158
+ - fixtures/vcr_cassettes/question_find_fail.yml
150
159
  - fixtures/vcr_cassettes/response_export_start_success.yml
151
160
  - fixtures/vcr_cassettes/response_export_update_success.yml
152
161
  - fixtures/vcr_cassettes/survey_collection_fetch_fail.yml
@@ -158,6 +167,10 @@ files:
158
167
  - lib/qualtrics_api/client.rb
159
168
  - lib/qualtrics_api/configurable.rb
160
169
  - lib/qualtrics_api/connectable.rb
170
+ - lib/qualtrics_api/distribution.rb
171
+ - lib/qualtrics_api/distribution_collection.rb
172
+ - lib/qualtrics_api/distribution_link.rb
173
+ - lib/qualtrics_api/distribution_link_collection.rb
161
174
  - lib/qualtrics_api/event_subscription.rb
162
175
  - lib/qualtrics_api/event_subscription_collection.rb
163
176
  - lib/qualtrics_api/extensions/serializable_collection.rb
@@ -167,6 +180,8 @@ files:
167
180
  - lib/qualtrics_api/panel_import.rb
168
181
  - lib/qualtrics_api/panel_member.rb
169
182
  - lib/qualtrics_api/panel_member_collection.rb
183
+ - lib/qualtrics_api/question.rb
184
+ - lib/qualtrics_api/question_collection.rb
170
185
  - lib/qualtrics_api/request_error_handler.rb
171
186
  - lib/qualtrics_api/response_export.rb
172
187
  - lib/qualtrics_api/response_export_collection.rb
@@ -176,6 +191,10 @@ files:
176
191
  - lib/qualtrics_api/version.rb
177
192
  - qualtrics_api.gemspec
178
193
  - spec/lib/client_spec.rb
194
+ - spec/lib/distribution_collection_spec.rb
195
+ - spec/lib/distribution_link_collection_spec.rb
196
+ - spec/lib/distribution_link_spec.rb
197
+ - spec/lib/distribution_spec.rb
179
198
  - spec/lib/event_subscription_collection_spec.rb
180
199
  - spec/lib/event_subscription_spec.rb
181
200
  - spec/lib/panel_collection_spec.rb
@@ -183,6 +202,8 @@ files:
183
202
  - spec/lib/panel_member_collection_spec.rb
184
203
  - spec/lib/panel_member_spec.rb
185
204
  - spec/lib/panel_spec.rb
205
+ - spec/lib/question_collection_spec.rb
206
+ - spec/lib/question_spec.rb
186
207
  - spec/lib/response_export_collection_spec.rb
187
208
  - spec/lib/response_export_spec.rb
188
209
  - spec/lib/services/response_export_service_spec.rb
@@ -209,13 +230,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
230
  - !ruby/object:Gem::Version
210
231
  version: '0'
211
232
  requirements: []
212
- rubyforge_project:
213
- rubygems_version: 2.7.4
233
+ rubygems_version: 3.0.4
214
234
  signing_key:
215
235
  specification_version: 4
216
236
  summary: A Ruby wrapper for Qualtrics REST API v3.0
217
237
  test_files:
218
238
  - spec/lib/client_spec.rb
239
+ - spec/lib/distribution_collection_spec.rb
240
+ - spec/lib/distribution_link_collection_spec.rb
241
+ - spec/lib/distribution_link_spec.rb
242
+ - spec/lib/distribution_spec.rb
219
243
  - spec/lib/event_subscription_collection_spec.rb
220
244
  - spec/lib/event_subscription_spec.rb
221
245
  - spec/lib/panel_collection_spec.rb
@@ -223,6 +247,8 @@ test_files:
223
247
  - spec/lib/panel_member_collection_spec.rb
224
248
  - spec/lib/panel_member_spec.rb
225
249
  - spec/lib/panel_spec.rb
250
+ - spec/lib/question_collection_spec.rb
251
+ - spec/lib/question_spec.rb
226
252
  - spec/lib/response_export_collection_spec.rb
227
253
  - spec/lib/response_export_spec.rb
228
254
  - spec/lib/services/response_export_service_spec.rb