qualtrics 0.5.7 → 0.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/qualtrics.rb +1 -0
- data/lib/qualtrics/response.rb +18 -1
- data/lib/qualtrics/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/Qualtrics_Recipient/creating_to_qualtrics/persists_to_qualtrics.yml +30 -30
- data/spec/qualtrics/response_spec.rb +36 -4
- data/spec/spec_helper.rb +0 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4d90b05afe3ccaf9a2d35b379c7600bfe98d40b
|
4
|
+
data.tar.gz: c144ce0eeec7e63c18e3964edcf70baf9b041e26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57a35f15099f12f0e0a53d93a8a32e56b5a540341e279484feb51b2217b6a4e09a4468b424a20a64c6f2c1150a6e8fc668edec3be76a4e6155ec0ea5a1f978c4
|
7
|
+
data.tar.gz: d4370401903c2822eecbd964edfc71d97b8ed925fac277cbed9fc13765cfc718c12fdb58dec8de9677ec49f094397fe8822463f7af892805f4299ffd92509375
|
data/lib/qualtrics.rb
CHANGED
data/lib/qualtrics/response.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'csv'
|
2
3
|
|
3
4
|
module Qualtrics
|
4
5
|
class Response
|
@@ -28,13 +29,29 @@ module Qualtrics
|
|
28
29
|
if @body.nil?
|
29
30
|
if @raw_response.body == ''
|
30
31
|
@body = {}
|
31
|
-
|
32
|
+
elsif content_type == 'application/json'
|
32
33
|
@body = JSON.parse(@raw_response.body)
|
34
|
+
elsif content_type == 'application/vnd.msexcel'
|
35
|
+
@body = CSV.parse(@raw_response.body)
|
36
|
+
else
|
37
|
+
raise Qualtrics::UnexpectedContentType, content_type
|
33
38
|
end
|
34
39
|
end
|
35
40
|
@body
|
36
41
|
end
|
37
42
|
|
43
|
+
def content_type
|
44
|
+
if @content_type.nil?
|
45
|
+
header = @raw_response.headers['Content-Type']
|
46
|
+
if header.nil?
|
47
|
+
@content_type = {}
|
48
|
+
else
|
49
|
+
@content_type = header
|
50
|
+
end
|
51
|
+
end
|
52
|
+
@content_type
|
53
|
+
end
|
54
|
+
|
38
55
|
private
|
39
56
|
def error_message
|
40
57
|
body['Meta'].nil? ? 'No error message' : body['Meta']['ErrorMessage']
|
data/lib/qualtrics/version.rb
CHANGED
data/spec/fixtures/vcr_cassettes/Qualtrics_Recipient/creating_to_qualtrics/persists_to_qualtrics.yml
CHANGED
@@ -8,7 +8,7 @@ http_interactions:
|
|
8
8
|
string: Category=Great+Category&Format=JSON&LibraryID=<QUALTRICS_LIBRARY_ID>&Name=Newest+Panel&Request=createPanel&Token=<QUALTRICS_TOKEN>&User=brookesidedev%40brookeside.com&Version=2.3
|
9
9
|
headers:
|
10
10
|
User-Agent:
|
11
|
-
- Faraday v0.9.
|
11
|
+
- Faraday v0.9.1
|
12
12
|
Content-Type:
|
13
13
|
- application/x-www-form-urlencoded
|
14
14
|
Accept-Encoding:
|
@@ -25,42 +25,42 @@ http_interactions:
|
|
25
25
|
Cache-Control:
|
26
26
|
- max-age=315360000
|
27
27
|
Expires:
|
28
|
-
-
|
28
|
+
- Fri, 28 Feb 2025 16:05:26 GMT
|
29
29
|
P3p:
|
30
30
|
- CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE", CP="CAO
|
31
31
|
DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"
|
32
32
|
Servershortname:
|
33
|
-
-
|
33
|
+
- w18
|
34
34
|
X-Cnection:
|
35
35
|
- close
|
36
36
|
X-Edgeconnect-Midmile-Rtt:
|
37
|
-
- '
|
38
|
-
- '
|
37
|
+
- '1'
|
38
|
+
- '6'
|
39
39
|
X-Edgeconnect-Origin-Mex-Latency:
|
40
|
-
- '
|
41
|
-
- '
|
40
|
+
- '230'
|
41
|
+
- '669'
|
42
42
|
Content-Length:
|
43
43
|
- '82'
|
44
44
|
Content-Type:
|
45
45
|
- application/json
|
46
46
|
Date:
|
47
|
-
-
|
47
|
+
- Tue, 03 Mar 2015 16:05:26 GMT
|
48
48
|
Connection:
|
49
49
|
- keep-alive
|
50
50
|
body:
|
51
51
|
encoding: UTF-8
|
52
|
-
string: '{"Meta":{"Status":"Success","Debug":""},"Result":{"PanelID":"
|
52
|
+
string: '{"Meta":{"Status":"Success","Debug":""},"Result":{"PanelID":"ML_emkzTL08MvdBaOV"}}'
|
53
53
|
http_version:
|
54
|
-
recorded_at:
|
54
|
+
recorded_at: Tue, 03 Mar 2015 16:05:27 GMT
|
55
55
|
- request:
|
56
56
|
method: post
|
57
57
|
uri: https://survey.qualtrics.com/WRAPI/ControlPanel/api.php
|
58
58
|
body:
|
59
59
|
encoding: UTF-8
|
60
|
-
string: Format=JSON&LibraryID=<QUALTRICS_LIBRARY_ID>&PanelID=
|
60
|
+
string: Format=JSON&LibraryID=<QUALTRICS_LIBRARY_ID>&PanelID=ML_emkzTL08MvdBaOV&Request=addRecipient&Token=<QUALTRICS_TOKEN>&User=brookesidedev%40brookeside.com&Version=2.3
|
61
61
|
headers:
|
62
62
|
User-Agent:
|
63
|
-
- Faraday v0.9.
|
63
|
+
- Faraday v0.9.1
|
64
64
|
Content-Type:
|
65
65
|
- application/x-www-form-urlencoded
|
66
66
|
Accept-Encoding:
|
@@ -77,7 +77,7 @@ http_interactions:
|
|
77
77
|
Cache-Control:
|
78
78
|
- max-age=315360000
|
79
79
|
Expires:
|
80
|
-
-
|
80
|
+
- Fri, 28 Feb 2025 16:05:27 GMT
|
81
81
|
P3p:
|
82
82
|
- CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE", CP="CAO
|
83
83
|
DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"
|
@@ -86,33 +86,33 @@ http_interactions:
|
|
86
86
|
X-Cnection:
|
87
87
|
- close
|
88
88
|
X-Edgeconnect-Midmile-Rtt:
|
89
|
-
- '
|
90
|
-
- '
|
89
|
+
- '14'
|
90
|
+
- '5'
|
91
91
|
X-Edgeconnect-Origin-Mex-Latency:
|
92
|
-
- '
|
93
|
-
- '
|
92
|
+
- '222'
|
93
|
+
- '643'
|
94
94
|
Content-Length:
|
95
95
|
- '88'
|
96
96
|
Content-Type:
|
97
97
|
- application/json
|
98
98
|
Date:
|
99
|
-
-
|
99
|
+
- Tue, 03 Mar 2015 16:05:27 GMT
|
100
100
|
Connection:
|
101
101
|
- keep-alive
|
102
102
|
body:
|
103
103
|
encoding: UTF-8
|
104
|
-
string: '{"Meta":{"Status":"Success","Debug":""},"Result":{"RecipientID":"
|
104
|
+
string: '{"Meta":{"Status":"Success","Debug":""},"Result":{"RecipientID":"MLRP_8rch1z9XaqPya0Z"}}'
|
105
105
|
http_version:
|
106
|
-
recorded_at:
|
106
|
+
recorded_at: Tue, 03 Mar 2015 16:05:28 GMT
|
107
107
|
- request:
|
108
108
|
method: post
|
109
109
|
uri: https://survey.qualtrics.com/WRAPI/ControlPanel/api.php
|
110
110
|
body:
|
111
111
|
encoding: UTF-8
|
112
|
-
string: Format=JSON&LibraryID=<QUALTRICS_LIBRARY_ID>&PanelID=
|
112
|
+
string: Format=JSON&LibraryID=<QUALTRICS_LIBRARY_ID>&PanelID=ML_emkzTL08MvdBaOV&Request=deletePanel&Token=<QUALTRICS_TOKEN>&User=brookesidedev%40brookeside.com&Version=2.3
|
113
113
|
headers:
|
114
114
|
User-Agent:
|
115
|
-
- Faraday v0.9.
|
115
|
+
- Faraday v0.9.1
|
116
116
|
Content-Type:
|
117
117
|
- application/x-www-form-urlencoded
|
118
118
|
Accept-Encoding:
|
@@ -129,31 +129,31 @@ http_interactions:
|
|
129
129
|
Cache-Control:
|
130
130
|
- max-age=315360000
|
131
131
|
Expires:
|
132
|
-
-
|
132
|
+
- Fri, 28 Feb 2025 16:05:28 GMT
|
133
133
|
P3p:
|
134
134
|
- CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE", CP="CAO
|
135
135
|
DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"
|
136
136
|
Servershortname:
|
137
|
-
-
|
137
|
+
- w541
|
138
138
|
X-Cnection:
|
139
139
|
- close
|
140
140
|
X-Edgeconnect-Midmile-Rtt:
|
141
|
-
- '
|
141
|
+
- '13'
|
142
142
|
- '2'
|
143
143
|
X-Edgeconnect-Origin-Mex-Latency:
|
144
|
-
- '
|
145
|
-
- '
|
144
|
+
- '273'
|
145
|
+
- '892'
|
146
146
|
Content-Length:
|
147
147
|
- '66'
|
148
148
|
Content-Type:
|
149
149
|
- application/json
|
150
150
|
Date:
|
151
|
-
-
|
151
|
+
- Tue, 03 Mar 2015 16:05:28 GMT
|
152
152
|
Connection:
|
153
153
|
- keep-alive
|
154
154
|
body:
|
155
155
|
encoding: UTF-8
|
156
156
|
string: '{"Meta":{"Status":"Success","Debug":""},"Result":{"Success":true}}'
|
157
157
|
http_version:
|
158
|
-
recorded_at:
|
159
|
-
recorded_with: VCR 2.9.
|
158
|
+
recorded_at: Tue, 03 Mar 2015 16:05:29 GMT
|
159
|
+
recorded_with: VCR 2.9.3
|
@@ -7,10 +7,10 @@ describe Qualtrics::Response, :vcr do
|
|
7
7
|
let(:test_endpoint) do
|
8
8
|
Faraday.new do |builder|
|
9
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('/server_error2') { |env| [400, {}, '{"Meta":{"Status":"Fubar","Debug":"","ErrorMessage":"Invalid request. Missing or invalid parameter RecipientID."}}']}
|
13
|
-
m.get('/failure') { |env| [ 200, {}, '{"Meta":{"Status":"Fubar","Debug":""}}' ]}
|
10
|
+
m.get('/success') { |env| [ 200, {'Content-Type'=>'application/json'}, '{"Meta":{"Status":"Success","Debug":""},"Result":{"PanelID":"ML_8BKIZdmCic6tkLb"}}' ]}
|
11
|
+
m.get('/server_error') { |env| [500, {'Content-Type'=>'application/json'}, '']}
|
12
|
+
m.get('/server_error2') { |env| [400, {'Content-Type'=>'application/json'}, '{"Meta":{"Status":"Fubar","Debug":"","ErrorMessage":"Invalid request. Missing or invalid parameter RecipientID."}}']}
|
13
|
+
m.get('/failure') { |env| [ 200, {'Content-Type'=>'application/json'}, '{"Meta":{"Status":"Fubar","Debug":""}}' ]}
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -50,4 +50,36 @@ describe Qualtrics::Response, :vcr do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
context 'parsing different content types' do
|
54
|
+
let(:content_endpoints) do
|
55
|
+
Faraday.new do |builder|
|
56
|
+
builder.adapter :test, Faraday::Adapter::Test::Stubs.new do |m|
|
57
|
+
m.get('/csv_response') { |env| [ 200, {'Content-Type'=>'application/vnd.msexcel'}, 'csv,stuff' ]}
|
58
|
+
m.get('/json_response') { |env| [ 200, {'Content-Type'=>'application/json'}, '{"Meta":{"Status":"Fubar","Debug":""}}' ]}
|
59
|
+
m.get('/random_content') { |env| [ 200, {'Content-Type'=>'random stuff'}, 'not a real body' ]}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'can parse csv' do
|
65
|
+
# s = Qualtrics::Submission.new(id: 'R_5msAm76fXKn1adf', survey_id:'SV_8deJytTY3InclQ9')
|
66
|
+
raw_response = content_endpoints.get('/csv_response')
|
67
|
+
response = Qualtrics::Response.new(raw_response)
|
68
|
+
expect(lambda{ response.send(:body) }).to_not raise_error
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'can parse json' do
|
72
|
+
# s = Qualtrics::Submission.new(id: 'R_5msAm76fXKn1adf', survey_id:'SV_8deJytTY3InclQ9')
|
73
|
+
raw_response = content_endpoints.get('/json_response')
|
74
|
+
response = Qualtrics::Response.new(raw_response)
|
75
|
+
expect(lambda{ response.send(:body) }).to_not raise_error
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'raises an error for other content types' do
|
79
|
+
# s = Qualtrics::Submission.new(id: 'R_5msAm76fXKn1adf', survey_id:'SV_8deJytTY3InclQ9')
|
80
|
+
raw_response = content_endpoints.get('/random_content')
|
81
|
+
response = Qualtrics::Response.new(raw_response)
|
82
|
+
expect(lambda{ response.send(:body) }).to raise_error(Qualtrics::UnexpectedContentType)
|
83
|
+
end
|
84
|
+
end
|
53
85
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qualtrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sun
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-03-
|
12
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: configatron
|