qualtrics 0.5.1

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.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +3 -0
  3. data/.gitignore +23 -0
  4. data/.rspec +1 -0
  5. data/Gemfile +7 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +29 -0
  8. data/Rakefile +7 -0
  9. data/lib/qualtrics.rb +52 -0
  10. data/lib/qualtrics/configuration.rb +17 -0
  11. data/lib/qualtrics/distribution.rb +90 -0
  12. data/lib/qualtrics/entity.rb +55 -0
  13. data/lib/qualtrics/mailer.rb +111 -0
  14. data/lib/qualtrics/message.rb +75 -0
  15. data/lib/qualtrics/operation.rb +77 -0
  16. data/lib/qualtrics/panel.rb +69 -0
  17. data/lib/qualtrics/panel_import.rb +41 -0
  18. data/lib/qualtrics/panel_import_file.rb +28 -0
  19. data/lib/qualtrics/recipient.rb +109 -0
  20. data/lib/qualtrics/recipient_import_row.rb +40 -0
  21. data/lib/qualtrics/response.rb +35 -0
  22. data/lib/qualtrics/survey.rb +80 -0
  23. data/lib/qualtrics/survey_import.rb +26 -0
  24. data/lib/qualtrics/transaction.rb +70 -0
  25. data/lib/qualtrics/version.rb +3 -0
  26. data/qualtrics.gemspec +34 -0
  27. data/spec/fixtures/sample_survey.xml +2 -0
  28. data/spec/fixtures/vcr_cassettes/Qualtrics_Distribution/creating_to_qualtrics/can_retrieve_a_panel_of_distributions_in_qualtrics.yml +655 -0
  29. data/spec/fixtures/vcr_cassettes/Qualtrics_Distribution/creating_to_qualtrics/can_update_itself.yml +599 -0
  30. data/spec/fixtures/vcr_cassettes/Qualtrics_Mailer/creating_to_qualtrics/sends_a_reminder_to_a_distribution.yml +493 -0
  31. data/spec/fixtures/vcr_cassettes/Qualtrics_Mailer/creating_to_qualtrics/sends_a_survey_to_a_panel_and_creates_a_distribution.yml +441 -0
  32. data/spec/fixtures/vcr_cassettes/Qualtrics_Mailer/creating_to_qualtrics/sends_a_survey_to_an_individual_and_creates_a_distribution.yml +441 -0
  33. data/spec/fixtures/vcr_cassettes/Qualtrics_Message/creating_to_qualtrics/persists_to_qualtrics.yml +56 -0
  34. data/spec/fixtures/vcr_cassettes/Qualtrics_Message/creating_to_qualtrics/populates_the_message_id_when_successful.yml +56 -0
  35. data/spec/fixtures/vcr_cassettes/Qualtrics_Message/creating_to_qualtrics/populates_the_success_attribute.yml +56 -0
  36. data/spec/fixtures/vcr_cassettes/Qualtrics_Message/retrieves_an_array_of_all_panels_in_a_library.yml +115 -0
  37. data/spec/fixtures/vcr_cassettes/Qualtrics_Panel/creating_to_qualtrics/persists_to_qualtrics.yml +107 -0
  38. data/spec/fixtures/vcr_cassettes/Qualtrics_Panel/creating_to_qualtrics/populates_the_panel_id_when_successful.yml +107 -0
  39. data/spec/fixtures/vcr_cassettes/Qualtrics_Panel/creating_to_qualtrics/populates_the_success_attribute.yml +107 -0
  40. data/spec/fixtures/vcr_cassettes/Qualtrics_Panel/destroys_a_panel_that_returns_true_when_successful.yml +107 -0
  41. data/spec/fixtures/vcr_cassettes/Qualtrics_Panel/raises_an_error_when_you_attempt_to_save_an_already_presisted_panel.yml +55 -0
  42. data/spec/fixtures/vcr_cassettes/Qualtrics_Panel/retrieves_an_array_of_all_panels_in_a_library.yml +704 -0
  43. data/spec/fixtures/vcr_cassettes/Qualtrics_PanelImport/transmits_to_qualtrics.yml +72 -0
  44. data/spec/fixtures/vcr_cassettes/Qualtrics_Recipient/creating_to_qualtrics/persists_to_qualtrics.yml +159 -0
  45. data/spec/fixtures/vcr_cassettes/Qualtrics_Recipient/creating_to_qualtrics/populates_the_recipient_id_when_successful.yml +159 -0
  46. data/spec/fixtures/vcr_cassettes/Qualtrics_Recipient/creating_to_qualtrics/populates_the_success_attribute.yml +159 -0
  47. data/spec/fixtures/vcr_cassettes/Qualtrics_Recipient/creating_to_qualtrics/raises_an_error_when_a_recipient_is_created_without_specifying_a_panel_id.yml +107 -0
  48. data/spec/fixtures/vcr_cassettes/Qualtrics_Recipient/recipient_made_in_qualtrics/can_delete_itself_in_qualtrics.yml +311 -0
  49. data/spec/fixtures/vcr_cassettes/Qualtrics_Recipient/recipient_made_in_qualtrics/can_update_itself_in_qualtrics.yml +313 -0
  50. data/spec/fixtures/vcr_cassettes/Qualtrics_Recipient/recipient_made_in_qualtrics/gets_its_information_in_qualtrics.yml +209 -0
  51. data/spec/fixtures/vcr_cassettes/Qualtrics_Survey/creating_to_qualtrics/can_be_activated_or_deactivated.yml +232 -0
  52. data/spec/fixtures/vcr_cassettes/Qualtrics_Survey/creating_to_qualtrics/destroys_a_survey_that_returns_true_when_successful.yml +128 -0
  53. data/spec/fixtures/vcr_cassettes/Qualtrics_Survey/creating_to_qualtrics/populates_the_survey_id_when_successful.yml +128 -0
  54. data/spec/fixtures/vcr_cassettes/Qualtrics_Survey/creating_to_qualtrics/retrieves_an_array_of_all_surveys.yml +203 -0
  55. data/spec/fixtures/vcr_cassettes/Qualtrics_SurveyImport/transmits_to_qualtrics.yml +128 -0
  56. data/spec/qualtrics/configuration_spec.rb +53 -0
  57. data/spec/qualtrics/distribution_spec.rb +144 -0
  58. data/spec/qualtrics/mailer_spec.rb +127 -0
  59. data/spec/qualtrics/message_spec.rb +105 -0
  60. data/spec/qualtrics/panel_import_file_spec.rb +26 -0
  61. data/spec/qualtrics/panel_import_spec.rb +43 -0
  62. data/spec/qualtrics/panel_spec.rb +80 -0
  63. data/spec/qualtrics/recipient_import_row_spec.rb +62 -0
  64. data/spec/qualtrics/recipient_spec.rb +185 -0
  65. data/spec/qualtrics/response_spec.rb +41 -0
  66. data/spec/qualtrics/survey_import_spec.rb +44 -0
  67. data/spec/qualtrics/survey_spec.rb +125 -0
  68. data/spec/spec_helper.rb +11 -0
  69. data/spec/support/_dotenv.rb +2 -0
  70. data/spec/support/qualtrics.rb +5 -0
  71. data/spec/support/vcr.rb +11 -0
  72. metadata +330 -0
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qualtrics::PanelImport, :vcr => true do
4
+ it 'has a panel' do
5
+ panel = Qualtrics::Panel.new
6
+
7
+ panel_import = Qualtrics::PanelImport.new({
8
+ panel: panel
9
+ })
10
+ expect(panel_import.panel).to eql(panel)
11
+ end
12
+
13
+ it 'has a list of recipients' do
14
+ recipients = [Qualtrics::Recipient.new, Qualtrics::Recipient.new]
15
+
16
+ panel_import = Qualtrics::PanelImport.new({
17
+ recipients: recipients
18
+ })
19
+ expect(panel_import.recipients).to eql(recipients)
20
+ end
21
+
22
+ it 'transmits to qualtrics' do
23
+ panel = Qualtrics::Panel.new({
24
+ name: 'Newest Panel',
25
+ category: 'Great Category'
26
+ })
27
+
28
+ recipients = [
29
+ Qualtrics::Recipient.new(
30
+ email: 'example@example.com',
31
+ first_name: 'First name',
32
+ last_name: 'Last name'
33
+ )
34
+ ]
35
+
36
+ panel_import = Qualtrics::PanelImport.new({
37
+ recipients: recipients,
38
+ panel: panel
39
+ })
40
+
41
+ expect(panel_import.save).to be true
42
+ end
43
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qualtrics::Panel, :vcr => true do
4
+ it 'has a name' do
5
+ name = 'New Panel'
6
+ panel = Qualtrics::Panel.new({
7
+ name: name
8
+ })
9
+ expect(panel.name).to eq(name)
10
+ end
11
+
12
+ it 'has a category' do
13
+ category = 'Amazing Category'
14
+ panel = Qualtrics::Panel.new({
15
+ category: category
16
+ })
17
+ expect(panel.category).to eq(category)
18
+ end
19
+
20
+ it 'has a library id' do
21
+ library_id = '1'
22
+ panel = Qualtrics::Panel.new({
23
+ library_id: library_id
24
+ })
25
+ expect(panel.library_id).to eq(library_id)
26
+ end
27
+
28
+ it 'defaults to the configured library id when none is specified' do
29
+ panel = Qualtrics::Panel.new
30
+ expect(panel.library_id).to eq(Qualtrics.configuration.default_library_id)
31
+ end
32
+
33
+ let(:panel) do
34
+ Qualtrics::Panel.new({
35
+ name: 'Newest Panel',
36
+ category: 'Great Category'
37
+ })
38
+ end
39
+
40
+ context 'creating to qualtrics' do
41
+ before(:each) do
42
+ Qualtrics.begin_transaction!
43
+ end
44
+
45
+ after(:each) do
46
+ Qualtrics.rollback_transaction!
47
+ end
48
+
49
+ it 'persists to qualtrics' do
50
+ expect(panel.save).to be true
51
+ end
52
+
53
+ it 'populates the panel_id when successful' do
54
+ panel.save
55
+ expect(panel.id).to_not be_nil
56
+ end
57
+
58
+ it 'populates the success attribute' do
59
+ panel.save
60
+ expect(panel).to be_success
61
+ end
62
+ end
63
+
64
+ it 'raises an error when you attempt to save an already presisted panel' do
65
+ panel.name = 'An Even Newer Panel'
66
+ expect(panel.save).to be true
67
+ panel.name = 'The new newest panel.'
68
+ expect(lambda{ panel.save }).to raise_error Qualtrics::UpdateNotAllowed
69
+ end
70
+
71
+ it 'destroys a panel that returns true when successful' do
72
+ panel.save
73
+ expect(panel.destroy).to be true
74
+ end
75
+
76
+ it 'retrieves an array of all panels in a library' do
77
+ panel.save
78
+ expect(Qualtrics::Panel.all.map{|p| p.id}).to include(panel.id)
79
+ end
80
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qualtrics::RecipientImportRow do
4
+ let(:email) { 'fake@fake.com' }
5
+ let(:first_name) { 'Johnny' }
6
+ let(:last_name) { 'Fakesalot' }
7
+ let(:external_data) { '1234' }
8
+ let(:embedded_data) { '4567' }
9
+ let(:unsubscribed) { 0 }
10
+ let(:language) { 'EN' }
11
+ let(:recipient) do
12
+ Qualtrics::Recipient.new({
13
+ email: email,
14
+ first_name: first_name,
15
+ last_name: last_name,
16
+ external_data: external_data,
17
+ embedded_data: embedded_data,
18
+ unsubscribed: unsubscribed,
19
+ language: language
20
+ })
21
+ end
22
+ let(:recipient_row) do
23
+ Qualtrics::RecipientImportRow.new(recipient)
24
+ end
25
+
26
+ it 'has a recipient' do
27
+ expect(recipient_row.recipient).to eql(recipient)
28
+ end
29
+
30
+ def index(field)
31
+ Qualtrics::RecipientImportRow.fields.index(field)
32
+ end
33
+
34
+ it 'returns email in the correct spot' do
35
+ expect(recipient_row.to_a[index('email')]).to eql(email)
36
+ end
37
+
38
+ it 'returns the first_name in the correct spot' do
39
+ expect(recipient_row.to_a[index('first_name')]).to eql(first_name)
40
+ end
41
+
42
+ it 'returns the last_name in the correct spot' do
43
+ expect(recipient_row.to_a[index('last_name')]).to eql(last_name)
44
+ end
45
+
46
+ it 'returns the external_data in the correct spot' do
47
+ expect(recipient_row.to_a[index('external_data')]).to eql(external_data)
48
+ end
49
+
50
+ it 'returns the embedded_data in the correct spot' do
51
+ expect(recipient_row.to_a[index('embedded_data')]).to eql(embedded_data)
52
+ end
53
+ it 'returns unsubscribed in the correct spot' do
54
+ expect(recipient_row.to_a[index('unsubscribed')]).to eql(unsubscribed)
55
+ end
56
+
57
+ it 'returns language in the correct spot' do
58
+ expect(recipient_row.to_a[index('language')]).to eql(language)
59
+ end
60
+
61
+
62
+ end
@@ -0,0 +1,185 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qualtrics::Recipient, :vcr => true do
4
+ it 'has an email' do
5
+ email = 'example@example.com'
6
+
7
+ recipient = Qualtrics::Recipient.new({
8
+ email: email
9
+ })
10
+ expect(recipient.email).to eql(email)
11
+ end
12
+
13
+ it 'has a first name' do
14
+ first_name = 'Peter'
15
+
16
+ recipient = Qualtrics::Recipient.new({
17
+ first_name: first_name
18
+ })
19
+ expect(recipient.first_name).to eql(first_name)
20
+ end
21
+
22
+ it 'has a last name' do
23
+ last_name = 'Johnson'
24
+
25
+ recipient = Qualtrics::Recipient.new({
26
+ last_name: last_name
27
+ })
28
+ expect(recipient.last_name).to eql(last_name)
29
+ end
30
+
31
+ it 'has a language' do
32
+ language = 'en'
33
+
34
+ recipient = Qualtrics::Recipient.new({
35
+ language: language
36
+ })
37
+ expect(recipient.language).to eql(language)
38
+ end
39
+
40
+ it 'has an external data reference' do
41
+ external_data = '11'
42
+
43
+ recipient = Qualtrics::Recipient.new({
44
+ external_data: external_data
45
+ })
46
+ expect(recipient.external_data).to eql(external_data)
47
+ end
48
+
49
+ it 'has embedded data' do
50
+ embedded_data = 'recipient_id:1290-38'
51
+
52
+ recipient = Qualtrics::Recipient.new({
53
+ embedded_data: embedded_data
54
+ })
55
+ expect(recipient.embedded_data).to eql(embedded_data)
56
+ end
57
+
58
+ it 'has an unsubscribed attribute' do
59
+ unsubscribed = 1
60
+
61
+ recipient = Qualtrics::Recipient.new({
62
+ unsubscribed: unsubscribed
63
+ })
64
+ expect(recipient.unsubscribed).to eql(unsubscribed)
65
+ end
66
+
67
+ it 'has a panel id' do
68
+ panel_id = 1
69
+
70
+ recipient = Qualtrics::Recipient.new({
71
+ panel_id: panel_id
72
+ })
73
+ expect(recipient.panel_id).to eql(panel_id)
74
+ end
75
+
76
+ it 'has a recipient id' do
77
+ id = 1
78
+
79
+ recipient = Qualtrics::Recipient.new({
80
+ id: id
81
+ })
82
+ expect(recipient.id).to eql(id)
83
+ end
84
+
85
+ it 'defaults to the configured library id when none is specified' do
86
+ recipient = Qualtrics::Recipient.new
87
+ expect(recipient.library_id).to eq(Qualtrics.configuration.default_library_id)
88
+ end
89
+
90
+ let(:panel) do
91
+ Qualtrics::Panel.new({
92
+ name: 'Newest Panel',
93
+ category: 'Great Category'
94
+ })
95
+ end
96
+
97
+ let(:recipient) do
98
+ Qualtrics::Recipient.new({
99
+ panel_id: panel.id
100
+ })
101
+ end
102
+
103
+ context 'creating to qualtrics' do
104
+ before(:each) do
105
+ Qualtrics.begin_transaction!
106
+ panel.save
107
+ end
108
+
109
+ after(:each) do
110
+ Qualtrics.rollback_transaction!
111
+ end
112
+
113
+ it 'persists to qualtrics' do
114
+ expect(recipient.save).to be true
115
+ end
116
+
117
+ it 'populates the recipient id when successful' do
118
+ recipient.save
119
+ expect(recipient.id).to_not be_nil
120
+ end
121
+
122
+ it 'populates the success attribute' do
123
+ recipient.save
124
+ expect(recipient).to be_success
125
+ end
126
+
127
+ it 'raises an error when a recipient is created without specifying a panel id' do
128
+ recipient = Qualtrics::Recipient.new
129
+ expect(recipient.save).to be false
130
+ expect(recipient.errors[:panel_id]).to_not be_blank
131
+ end
132
+ end
133
+
134
+ context 'recipient made in qualtrics' do
135
+ before(:each) do
136
+ Qualtrics.begin_transaction!
137
+ panel.save
138
+ end
139
+
140
+ after(:each) do
141
+ Qualtrics.rollback_transaction!
142
+ end
143
+
144
+ it 'gets its information in qualtrics' do
145
+ first_name = 'Kevin'
146
+
147
+ recipient = Qualtrics::Recipient.new({
148
+ panel_id: panel.id,
149
+ first_name: first_name
150
+ })
151
+ recipient.save
152
+
153
+ expect(recipient.info_hash['FirstName']).to include(recipient.first_name)
154
+ end
155
+
156
+ it 'can update itself in qualtrics' do
157
+ first_name = 'Kevin'
158
+ new_name = 'Ben'
159
+
160
+ recipient = Qualtrics::Recipient.new({
161
+ panel_id: panel.id,
162
+ first_name: first_name
163
+ })
164
+ recipient.save
165
+
166
+ attributes = {
167
+ first_name: new_name
168
+ }
169
+ recipient.update(attributes)
170
+
171
+ expect(recipient.update(attributes)).to be true
172
+ expect(recipient.first_name).to eql(new_name)
173
+ expect(recipient.info_hash['FirstName']).to include(new_name)
174
+ end
175
+
176
+ it 'can delete itself in qualtrics' do
177
+ recipient.save
178
+
179
+ expect(recipient.info_hash['PanelID']).to include(panel.id)
180
+ recipient.delete
181
+ expect(recipient.info_hash).to be false
182
+ end
183
+ end
184
+
185
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qualtrics::Response, :vcr do
4
+ # it 'has a body' do
5
+
6
+ # end
7
+ let(:test_endpoint) do
8
+ Faraday.new do |builder|
9
+ builder.adapter :test, Faraday::Adapter::Test::Stubs.new do |m|
10
+ m.get('/success') { |env| [ 200, {}, '{"Meta":{"Status":"Success","Debug":""},"Result":{"PanelID":"ML_8BKIZdmCic6tkLb"}}' ]}
11
+ m.get('/server_error') { |env| [500, {}, '']}
12
+ m.get('/failure') { |env| [ 200, {}, '{"Meta":{"Status":"Fubar","Debug":""}}' ]}
13
+ end
14
+ end
15
+ end
16
+
17
+ it 'is successful when the meta status is success' do
18
+ raw_response = test_endpoint.get('/success')
19
+ response = Qualtrics::Response.new(raw_response)
20
+ expect(response).to be_success
21
+ end
22
+
23
+ it 'is not successful when the meta status is not success' do
24
+ raw_response = test_endpoint.get('/failure')
25
+ response = Qualtrics::Response.new(raw_response)
26
+ expect(response).to_not be_success
27
+ end
28
+
29
+ it 'has a result hash' do
30
+ raw_response = test_endpoint.get('/success')
31
+ response = Qualtrics::Response.new(raw_response)
32
+ expect(response.result).to be_kind_of(Hash)
33
+ end
34
+
35
+ it 'raises an exception when a 5xx error is received' do
36
+ raw_response = test_endpoint.get('/server_error')
37
+ expect(lambda{ Qualtrics::Response.new(raw_response)}).to raise_error(Qualtrics::ServerErrorEncountered)
38
+ end
39
+
40
+
41
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qualtrics::SurveyImport, :vcr => true do
4
+ it 'has a survey name' do
5
+ survey_name = 'great name'
6
+ survey_import = Qualtrics::SurveyImport.new({
7
+ survey_name: survey_name
8
+ })
9
+ expect(survey_import.survey_name).to eql(survey_name)
10
+ end
11
+
12
+ it 'has a survey' do
13
+ survey_name = 'great name'
14
+ survey_import = Qualtrics::SurveyImport.new({
15
+ survey_name: survey_name
16
+ })
17
+ expect(survey_import.survey_name).to eql(survey_import.survey.survey_name)
18
+ end
19
+
20
+ it 'has survey file location' do
21
+ survey_data_location = 'some location'
22
+
23
+ survey_import = Qualtrics::SurveyImport.new({
24
+ survey_data_location: survey_data_location
25
+ })
26
+ expect(survey_import.survey_data_location).to eql(survey_data_location)
27
+ end
28
+
29
+ it 'transmits to qualtrics' do
30
+ survey_data_location = 'spec/fixtures/sample_survey.xml'
31
+
32
+ survey = Qualtrics::Survey.new({
33
+ survey_name: 'Newest Survey'
34
+ })
35
+
36
+ survey_import = Qualtrics::SurveyImport.new({
37
+ survey_data_location: survey_data_location,
38
+ survey: survey
39
+ })
40
+
41
+ expect(survey_import.save).to be true
42
+ survey_import.survey.destroy
43
+ end
44
+ end