qualtrics_api 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -7
- data/fixtures/vcr_cassettes/panel_collection_fetch_fail.yml +10 -8
- data/fixtures/vcr_cassettes/panel_collection_fetch_success.yml +14 -11
- data/fixtures/vcr_cassettes/panel_import_update_success.yml +12 -10
- data/fixtures/vcr_cassettes/panel_member_collection_create_fail.yml +4 -2
- data/fixtures/vcr_cassettes/panel_member_collection_create_success.yml +33 -26
- data/fixtures/vcr_cassettes/panel_member_collection_fetch_success.yml +15 -12
- data/fixtures/vcr_cassettes/response_export_start_success.yml +19 -14
- data/fixtures/vcr_cassettes/response_export_update_success.yml +12 -38
- data/fixtures/vcr_cassettes/survey_collection_fetch_fail.yml +4 -2
- data/fixtures/vcr_cassettes/survey_collection_fetch_sucess.yml +12 -10
- data/lib/qualtrics_api/client.rb +3 -3
- data/lib/qualtrics_api/panel_collection.rb +4 -4
- data/lib/qualtrics_api/panel_import.rb +1 -1
- data/lib/qualtrics_api/panel_member.rb +8 -8
- data/lib/qualtrics_api/panel_member_collection.rb +9 -6
- data/lib/qualtrics_api/request_error_handler.rb +5 -9
- data/lib/qualtrics_api/response_export.rb +2 -2
- data/lib/qualtrics_api/services/response_export_service.rb +13 -19
- data/lib/qualtrics_api/survey.rb +2 -4
- data/lib/qualtrics_api/survey_collection.rb +4 -30
- data/lib/qualtrics_api/url.rb +1 -1
- data/lib/qualtrics_api/version.rb +1 -1
- data/qualtrics_api.gemspec +3 -3
- data/spec/lib/client_spec.rb +0 -4
- data/spec/lib/panel_import_spec.rb +2 -2
- data/spec/lib/panel_member_collection_spec.rb +4 -4
- data/spec/lib/panel_member_spec.rb +8 -8
- data/spec/lib/response_export_spec.rb +1 -1
- data/spec/lib/services/response_export_service_spec.rb +25 -29
- data/spec/lib/survey_collection_spec.rb +1 -28
- data/spec/lib/survey_spec.rb +2 -6
- data/spec/spec_helper.rb +1 -1
- metadata +9 -10
- data/fixtures/vcr_cassettes/survey_collection_fetch_with_scopeId_success.yml +0 -33
@@ -2,13 +2,15 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://co1.qualtrics.com/API/
|
5
|
+
uri: https://co1.qualtrics.com/API/v3/surveys
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
|
+
X-API-TOKEN:
|
11
|
+
- 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
|
10
12
|
User-Agent:
|
11
|
-
- Faraday v0.
|
13
|
+
- Faraday v0.9.2
|
12
14
|
response:
|
13
15
|
status:
|
14
16
|
code: 404
|
@@ -2,32 +2,34 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://co1.qualtrics.com/API/
|
5
|
+
uri: https://co1.qualtrics.com/API/v3/surveys
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
|
+
X-API-TOKEN:
|
11
|
+
- 6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ
|
10
12
|
User-Agent:
|
11
|
-
- Faraday v0.
|
13
|
+
- Faraday v0.9.2
|
12
14
|
response:
|
13
15
|
status:
|
14
16
|
code: 200
|
15
17
|
message:
|
16
18
|
headers:
|
17
|
-
server:
|
18
|
-
- Apache-Coyote/1.1
|
19
19
|
content-type:
|
20
|
-
- application/json
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
request-time:
|
22
|
+
- '573'
|
21
23
|
content-length:
|
22
|
-
- '
|
24
|
+
- '1737'
|
23
25
|
date:
|
24
|
-
-
|
26
|
+
- Mon, 11 Apr 2016 13:04:55 GMT
|
25
27
|
connection:
|
26
28
|
- close
|
27
29
|
body:
|
28
30
|
encoding: UTF-8
|
29
|
-
string: '{"result":[{"id":"SV_djzgZ6eJXqnIUyF","name":"
|
30
|
-
|
31
|
+
string: '{"result":{"elements":[{"id":"SV_djzgZ6eJXqnIUyF","name":"Test","ownerId":"UR_3fnAz35QCGlr725","lastModified":"2015-08-06T16:11:15Z","isActive":false}],"nextPage":"https://co1.qualtrics.com/API/v3/surveys?offset=10"},"meta":{"httpStatus":"200
|
32
|
+
- OK"}}'
|
31
33
|
http_version:
|
32
|
-
recorded_at:
|
34
|
+
recorded_at: Mon, 11 Apr 2016 13:04:55 GMT
|
33
35
|
recorded_with: VCR 2.9.3
|
data/lib/qualtrics_api/client.rb
CHANGED
@@ -7,7 +7,6 @@ module QualtricsAPI
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def surveys(options = {})
|
10
|
-
@surveys = nil if @surveys && @surveys.scope_id != options[:scope_id]
|
11
10
|
@surveys ||= QualtricsAPI::SurveyCollection.new(options).propagate_connection(self)
|
12
11
|
end
|
13
12
|
|
@@ -22,8 +21,9 @@ module QualtricsAPI
|
|
22
21
|
private
|
23
22
|
|
24
23
|
def establish_connection(api_token)
|
25
|
-
Faraday.new(url: QualtricsAPI::URL,
|
26
|
-
faraday.request :
|
24
|
+
Faraday.new(url: QualtricsAPI::URL, headers: { 'X-API-TOKEN' => api_token }) do |faraday|
|
25
|
+
faraday.request :multipart
|
26
|
+
faraday.request :json
|
27
27
|
faraday.response :json, :content_type => /\bjson$/
|
28
28
|
|
29
29
|
faraday.use FaradayMiddleware::FollowRedirects
|
@@ -4,9 +4,9 @@ module QualtricsAPI
|
|
4
4
|
attribute :all, Array, :default => []
|
5
5
|
end
|
6
6
|
|
7
|
-
def fetch(
|
7
|
+
def fetch()
|
8
8
|
@all = []
|
9
|
-
parse_fetch_response(QualtricsAPI.connection(self).get('
|
9
|
+
parse_fetch_response(QualtricsAPI.connection(self).get('mailinglists'))
|
10
10
|
self
|
11
11
|
end
|
12
12
|
|
@@ -23,8 +23,8 @@ module QualtricsAPI
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def parse_fetch_response(response)
|
26
|
-
@all = response.body["result"].map do |
|
27
|
-
QualtricsAPI::Panel.new(
|
26
|
+
@all = response.body["result"]["elements"].map do |elements|
|
27
|
+
QualtricsAPI::Panel.new(elements).propagate_connection(self)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -6,7 +6,7 @@ module QualtricsAPI
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def update_status
|
9
|
-
res = QualtricsAPI.connection(self).get("
|
9
|
+
res = QualtricsAPI.connection(self).get("mailinglists/#{panel_id}/contactimports/#{id}").body["result"]
|
10
10
|
@import_progress = res["percentComplete"]
|
11
11
|
@completed = true if @import_progress == 100.0
|
12
12
|
self
|
@@ -25,14 +25,14 @@ module QualtricsAPI
|
|
25
25
|
|
26
26
|
def attributes_for_save
|
27
27
|
{
|
28
|
-
:id => "
|
29
|
-
:first_name => "
|
30
|
-
:last_name => "
|
31
|
-
:email => "
|
32
|
-
:language => "
|
33
|
-
:unsubscribed => '
|
34
|
-
:external_reference => "
|
35
|
-
:embeded_data => "
|
28
|
+
:id => "recipientID",
|
29
|
+
:first_name => "firstName",
|
30
|
+
:last_name => "lastName",
|
31
|
+
:email => "email",
|
32
|
+
:language => "language",
|
33
|
+
:unsubscribed => 'unsubscribed',
|
34
|
+
:external_reference => "externalReference",
|
35
|
+
:embeded_data => "embeddedData"
|
36
36
|
}
|
37
37
|
end
|
38
38
|
|
@@ -7,15 +7,18 @@ module QualtricsAPI
|
|
7
7
|
|
8
8
|
def fetch(_options = {})
|
9
9
|
@all = []
|
10
|
-
parse_fetch_response(QualtricsAPI.connection(self).get("
|
10
|
+
parse_fetch_response(QualtricsAPI.connection(self).get("mailinglists/#{id}/contacts"))
|
11
11
|
self
|
12
12
|
end
|
13
13
|
|
14
14
|
def create(panel_members)
|
15
|
+
payload = {
|
16
|
+
contacts: Faraday::UploadIO.new(StringIO.new(panel_members.to_json), 'application/json', 'contacts.json')
|
17
|
+
}
|
15
18
|
res = QualtricsAPI.connection(self)
|
16
|
-
|
17
|
-
|
18
|
-
import_id = res['
|
19
|
+
.post("mailinglists/#{id}/contactimports", payload)
|
20
|
+
.body["result"]
|
21
|
+
import_id = res['id']
|
19
22
|
QualtricsAPI::PanelImport.new(id: import_id, panel_id: id).propagate_connection(self)
|
20
23
|
end
|
21
24
|
|
@@ -32,8 +35,8 @@ module QualtricsAPI
|
|
32
35
|
private
|
33
36
|
|
34
37
|
def parse_fetch_response(response)
|
35
|
-
@all = response.body["result"].map do |
|
36
|
-
QualtricsAPI::PanelMember.new(
|
38
|
+
@all = response.body["result"]["elements"].map do |element|
|
39
|
+
QualtricsAPI::PanelMember.new(element).propagate_connection(self)
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module QualtricsAPI
|
2
|
-
|
3
2
|
class RequestErrorHandler < Faraday::Response::Middleware
|
4
|
-
|
5
3
|
def on_complete(env)
|
6
4
|
case env[:status]
|
7
5
|
when 404
|
@@ -19,19 +17,17 @@ module QualtricsAPI
|
|
19
17
|
|
20
18
|
def error_message(response)
|
21
19
|
meta = response["meta"]
|
22
|
-
[
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
["[",
|
21
|
+
meta["status"], " - ",
|
22
|
+
meta["qualtricsErrorCode"] || meta["internalErrorCode"],
|
23
|
+
"] ",
|
24
|
+
meta["errorMessage"]
|
27
25
|
].join
|
28
26
|
end
|
29
|
-
|
30
27
|
end
|
31
28
|
|
32
29
|
class NotFoundError < StandardError; end
|
33
30
|
class BadRequestError < StandardError; end
|
34
31
|
class UnauthorizedError < StandardError; end
|
35
32
|
class InternalServerError < StandardError; end
|
36
|
-
|
37
33
|
end
|
@@ -5,9 +5,9 @@ module QualtricsAPI
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def update_status
|
8
|
-
res = QualtricsAPI.connection(self).get('
|
8
|
+
res = QualtricsAPI.connection(self).get('responseexports/' + id).body["result"]
|
9
9
|
@export_progress = res["percentComplete"]
|
10
|
-
@file_url = res["
|
10
|
+
@file_url = res["file"]
|
11
11
|
@completed = true if @export_progress == 100.0
|
12
12
|
self
|
13
13
|
end
|
@@ -2,46 +2,42 @@ module QualtricsAPI
|
|
2
2
|
module Services
|
3
3
|
class ResponseExportService < QualtricsAPI::BaseModel
|
4
4
|
values do
|
5
|
+
attribute :format, String, :default => 'csv'
|
5
6
|
attribute :survey_id, String
|
6
|
-
attribute :response_set_id, String
|
7
|
-
attribute :file_type, String, :default => 'CSV'
|
8
7
|
attribute :last_response_id, String
|
9
8
|
attribute :start_date, String
|
10
9
|
attribute :end_date, String
|
11
10
|
attribute :limit, String
|
12
11
|
attribute :included_question_ids, String
|
13
|
-
attribute :max_rows, String
|
14
12
|
attribute :use_labels, Boolean, :default => false
|
15
|
-
attribute :
|
13
|
+
attribute :decimal_separator, String, :default => '.'
|
16
14
|
attribute :seen_unanswered_recode, String
|
17
15
|
attribute :use_local_time, Boolean, :default => false
|
18
|
-
|
16
|
+
|
19
17
|
attribute :id, String
|
20
18
|
end
|
21
19
|
|
22
20
|
attr_reader :result
|
23
21
|
|
24
22
|
def start
|
25
|
-
response = QualtricsAPI.connection(self).
|
26
|
-
export_id = response.body["result"]["
|
23
|
+
response = QualtricsAPI.connection(self).post("responseexports", export_params)
|
24
|
+
export_id = response.body["result"]["id"]
|
27
25
|
@result = ResponseExport.new(id: export_id)
|
28
26
|
end
|
29
27
|
|
30
28
|
def export_configurations
|
31
29
|
{
|
32
|
-
|
33
|
-
|
30
|
+
format: format,
|
31
|
+
survey_id: survey_id,
|
34
32
|
last_response_id: last_response_id,
|
35
33
|
start_date: start_date,
|
36
34
|
end_date: end_date,
|
37
35
|
limit: limit,
|
38
36
|
included_question_ids: included_question_ids,
|
39
|
-
max_rows: max_rows,
|
40
37
|
use_labels: use_labels,
|
41
|
-
|
38
|
+
decimal_separator: decimal_separator,
|
42
39
|
seen_unanswered_recode: seen_unanswered_recode,
|
43
|
-
use_local_time: use_local_time
|
44
|
-
spss_string_length: spss_string_length
|
40
|
+
use_local_time: use_local_time
|
45
41
|
}
|
46
42
|
end
|
47
43
|
|
@@ -49,19 +45,17 @@ module QualtricsAPI
|
|
49
45
|
|
50
46
|
def param_mappings
|
51
47
|
{
|
52
|
-
|
53
|
-
|
48
|
+
format: "format",
|
49
|
+
survey_id: "surveyId",
|
54
50
|
last_response_id: "lastResponseId",
|
55
51
|
start_date: "startDate",
|
56
52
|
end_date: "endDate",
|
57
53
|
limit: "limit",
|
58
54
|
included_question_ids: "includedQuestionIds",
|
59
|
-
max_rows: "maxRows",
|
60
55
|
use_labels: "useLabels",
|
61
|
-
|
56
|
+
decimal_separator: "decimalSeparator",
|
62
57
|
seen_unanswered_recode: "seenUnansweredRecode",
|
63
|
-
use_local_time: "useLocalTime"
|
64
|
-
spss_string_length: "spssStringLength"
|
58
|
+
use_local_time: "useLocalTime"
|
65
59
|
}
|
66
60
|
end
|
67
61
|
|
data/lib/qualtrics_api/survey.rb
CHANGED
@@ -5,8 +5,7 @@ module QualtricsAPI
|
|
5
5
|
attribute :name, String
|
6
6
|
attribute :owner_id, String
|
7
7
|
attribute :last_modified, String
|
8
|
-
attribute :
|
9
|
-
attribute :status, String
|
8
|
+
attribute :is_active, Boolean
|
10
9
|
end
|
11
10
|
|
12
11
|
def export_responses(export_options = {})
|
@@ -21,8 +20,7 @@ module QualtricsAPI
|
|
21
20
|
:name => "name",
|
22
21
|
:owner_id => "ownerId",
|
23
22
|
:last_modified => "lastModified",
|
24
|
-
:
|
25
|
-
:created_at => "SurveyCreationDate"
|
23
|
+
:is_active => "isActive"
|
26
24
|
}
|
27
25
|
end
|
28
26
|
end
|
@@ -1,29 +1,15 @@
|
|
1
1
|
module QualtricsAPI
|
2
2
|
class SurveyCollection < BaseCollection
|
3
3
|
values do
|
4
|
-
attribute :scope_id, String
|
5
4
|
attribute :all, Array, :default => []
|
6
5
|
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
def fetch(options = {})
|
7
|
+
def fetch
|
11
8
|
@all = []
|
12
|
-
|
13
|
-
parse_fetch_response(QualtricsAPI.connection(self).get('surveys', query_params))
|
9
|
+
parse_fetch_response(QualtricsAPI.connection(self).get('surveys'))
|
14
10
|
self
|
15
11
|
end
|
16
12
|
|
17
|
-
def query_attributes
|
18
|
-
{
|
19
|
-
:scope_id => @scope_id
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
def update_query_attributes(new_attributes = {})
|
24
|
-
@scope_id = new_attributes[:scope_id] if new_attributes.key?(:scope_id)
|
25
|
-
end
|
26
|
-
|
27
13
|
def [](survey_id)
|
28
14
|
find(survey_id)
|
29
15
|
end
|
@@ -36,21 +22,9 @@ module QualtricsAPI
|
|
36
22
|
|
37
23
|
private
|
38
24
|
|
39
|
-
def attributes_mapping
|
40
|
-
{
|
41
|
-
:scope_id => "scopeId"
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
def query_params
|
46
|
-
query_attributes.map do |k, v|
|
47
|
-
[attributes_mapping[k], v] unless v.nil? || v.to_s.empty?
|
48
|
-
end.compact.to_h
|
49
|
-
end
|
50
|
-
|
51
25
|
def parse_fetch_response(response)
|
52
|
-
@all = response.body["result"].map do |
|
53
|
-
QualtricsAPI::Survey.new(
|
26
|
+
@all = response.body["result"]['elements'].map do |elements|
|
27
|
+
QualtricsAPI::Survey.new(elements).propagate_connection(self)
|
54
28
|
end
|
55
29
|
end
|
56
30
|
end
|
data/lib/qualtrics_api/url.rb
CHANGED
data/qualtrics_api.gemspec
CHANGED
@@ -26,9 +26,9 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency "faraday_middleware", "~> 0.9.1"
|
27
27
|
spec.add_dependency "virtus", "~> 1.0"
|
28
28
|
|
29
|
-
spec.add_development_dependency "bundler", "~> 1.
|
30
|
-
spec.add_development_dependency "rake", "~>
|
31
|
-
spec.add_development_dependency "rspec", "~> 3.
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 11.1"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
32
32
|
spec.add_development_dependency "vcr", "~> 2.9"
|
33
33
|
spec.add_development_dependency "guard-rspec", "~> 4.5"
|
34
34
|
spec.add_development_dependency "pry", "~> 0.10.1"
|
data/spec/lib/client_spec.rb
CHANGED
@@ -18,10 +18,6 @@ describe QualtricsAPI::Client do
|
|
18
18
|
expect(subject.surveys).to be_a QualtricsAPI::SurveyCollection
|
19
19
|
end
|
20
20
|
|
21
|
-
it "assigns scope_id if passed" do
|
22
|
-
expect(subject.surveys(:scope_id => "someId").scope_id).to eq "someId"
|
23
|
-
end
|
24
|
-
|
25
21
|
it "caches the surveys" do
|
26
22
|
expect(subject.surveys.object_id).to eq subject.surveys.object_id
|
27
23
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe QualtricsAPI::PanelImport do
|
4
|
-
subject { described_class.new(id: '
|
4
|
+
subject { described_class.new(id: 'PGRS_4GvIMg79RFEPW4d', panel_id: 'ML_0APx3C4rmHER6w5') }
|
5
5
|
|
6
6
|
describe "integration" do
|
7
7
|
describe "#update_status" do
|
8
8
|
let(:result) do
|
9
|
-
VCR.use_cassette('panel_import_update_success') do
|
9
|
+
VCR.use_cassette('panel_import_update_success', record: :once) do
|
10
10
|
subject.update_status
|
11
11
|
end
|
12
12
|
end
|
@@ -61,8 +61,8 @@ describe QualtricsAPI::PanelMemberCollection do
|
|
61
61
|
|
62
62
|
describe "#create" do
|
63
63
|
let(:result) do
|
64
|
-
VCR.use_cassette(cassette) do
|
65
|
-
QualtricsAPI.panels.fetch['
|
64
|
+
VCR.use_cassette(cassette, record: :once) do
|
65
|
+
QualtricsAPI.panels.fetch['ML_0APx3C4rmHER6w5'].members.create(panel_members)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -75,11 +75,11 @@ describe QualtricsAPI::PanelMemberCollection do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "returns PanelImport with id" do
|
78
|
-
expect(result.id).to eq('
|
78
|
+
expect(result.id).to eq('PGRS_4GvIMg79RFEPW4d')
|
79
79
|
end
|
80
80
|
|
81
81
|
it "returns PanelImport with panel id" do
|
82
|
-
expect(result.panel_id).to eq('
|
82
|
+
expect(result.panel_id).to eq('ML_0APx3C4rmHER6w5')
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|