qualtrics_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::ResponseExport do
4
+
5
+ let(:connection) { double('connection') }
6
+ subject { described_class.new id: "someId", connection: connection }
7
+
8
+ describe "#completed?" do
9
+ it "is true when @completed is true" do
10
+ subject.instance_variable_set(:@completed, true)
11
+ expect(subject.completed?).to eq true
12
+ end
13
+
14
+ it "is false when @completed is false" do
15
+ subject.instance_variable_set(:@completed, false)
16
+ expect(subject.completed?).to eq false
17
+ end
18
+ end
19
+
20
+ describe "#status" do
21
+ describe "when completed" do
22
+ it "returns the progress string without calling update" do
23
+ subject.instance_variable_set(:@completed, true)
24
+ subject.instance_variable_set(:@export_progress, 100)
25
+ expect(subject).to_not receive(:update_status)
26
+ expect(subject.status).to eq "100%"
27
+ end
28
+ end
29
+
30
+ describe "when not completed" do
31
+ it "calls update then prints progress" do
32
+ subject.instance_variable_set(:@export_progress, 10)
33
+ expect(subject).to receive(:update_status)
34
+ expect(subject.status).to eq "10%"
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#percent_completed" do
40
+ describe "when completed" do
41
+ it "returns the progress number without calling update" do
42
+ subject.instance_variable_set(:@completed, true)
43
+ subject.instance_variable_set(:@export_progress, 100)
44
+ expect(subject).to_not receive(:update_status)
45
+ expect(subject.percent_completed).to eq 100
46
+ end
47
+ end
48
+
49
+ describe "when not completed" do
50
+ it "calls update then prints progress" do
51
+ subject.instance_variable_set(:@export_progress, 10)
52
+ expect(subject).to receive(:update_status)
53
+ expect(subject.percent_completed).to eq 10
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#file_url" do
59
+ describe "when completed" do
60
+ it "returns the progress number without calling update" do
61
+ subject.instance_variable_set(:@completed, true)
62
+ subject.instance_variable_set(:@file_url, "some_url")
63
+ expect(subject).to_not receive(:update_status)
64
+ expect(subject.file_url).to eq "some_url"
65
+ end
66
+ end
67
+
68
+ describe "when not completed" do
69
+ it "calls update then prints progress" do
70
+ subject.instance_variable_set(:@export_progress, 10)
71
+ expect(subject).to receive(:update_status)
72
+ expect(subject.file_url).to be_nil
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#update_status" do
78
+ let(:client) { QualtricsAPI.new TEST_API_TOKEN }
79
+
80
+ it "updates the status of the export then returns itself" do
81
+ VCR.use_cassette("response_export_update_success") do
82
+ subject = described_class.new id: "ES_cwLvnQHobKfV9t3", connection: client.connection
83
+
84
+ result = subject.update_status
85
+
86
+ expect(subject.completed?).to be_truthy
87
+ expect(subject.instance_variable_get(:@file_url)).to_not be_nil
88
+ expect(subject.instance_variable_get(:@export_progress)).to eq 100.0
89
+
90
+ expect(result).to eq subject
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::Services::ResponseExportService do
4
+
5
+ describe "initialize" do
6
+ let(:params) do
7
+ {
8
+ survey_id: "s_id",
9
+ response_set_id: "r_set_id",
10
+ file_type: "file type",
11
+ last_response_id: "l_id",
12
+ start_date: "03/22/2015 06:11:11",
13
+ end_date: "03/25/2015 06:00:00",
14
+ limit: "1000",
15
+ included_question_ids: "ids,ids",
16
+ max_rows: "1000",
17
+ use_labels: true,
18
+ decimal_format: ",",
19
+ seen_unanswered_recode: "something",
20
+ use_local_time: true,
21
+ spss_string_length: "15",
22
+ }
23
+ end
24
+ let(:connection) { double("connection") }
25
+
26
+ subject { described_class.new params.merge(connection: connection)}
27
+
28
+ describe "assgin options" do
29
+ before do
30
+ allow_any_instance_of(described_class).to receive(:start)
31
+ end
32
+
33
+ it "assigns passed options" do
34
+ params.each do |key, value|
35
+ expect(subject.send(key)).to eq value
36
+ end
37
+ end
38
+
39
+ it "assigns connection" do
40
+ expect(subject.instance_variable_get(:@conn)).to eq connection
41
+ end
42
+
43
+ describe "defaults" do
44
+ subject { described_class.new connection: connection }
45
+
46
+ it "has default @use_labels - false" do
47
+ expect(subject.use_labels).to eq false
48
+ end
49
+
50
+ it "has default @use_local_time - false" do
51
+ expect(subject.use_local_time).to eq false
52
+ end
53
+
54
+ it "has default @file_type - csv" do
55
+ expect(subject.file_type).to eq 'CSV'
56
+ end
57
+
58
+ it "has default @decimal_format - ." do
59
+ expect(subject.decimal_format).to eq '.'
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "#start" do
65
+ it "calls url with export params" do
66
+ expect(connection).to receive(:get).with("surveys/s_id/responseExports", {
67
+ "responseSetId" => "r_set_id",
68
+ "fileType" => "file type",
69
+ "lastResponseId" => "l_id",
70
+ "startDate" => "03/22/2015 06:11:11",
71
+ "endDate" => "03/25/2015 06:00:00",
72
+ "limit" => "1000",
73
+ "includedQuestionIds" => "ids,ids",
74
+ "maxRows" => "1000",
75
+ "useLabels" => true,
76
+ "decimalFormat" => ",",
77
+ "seenUnansweredRecode" => "something",
78
+ "useLocalTime" => true,
79
+ "spssStringLength" => "15"
80
+ }).and_return(double('resBody', body: {"result" => { "exportStatus" => "some/url" }}))
81
+ subject.start
82
+ end
83
+
84
+ it "assigns and returns a ResponseExport with the id in the url" do
85
+ allow(connection).to receive(:get)
86
+ .and_return(double('resBody', body: {"result" => { "exportStatus" => "some/url/exportId" }}))
87
+ sut = subject.start
88
+ expect(sut).to be_a QualtricsAPI::ResponseExport
89
+ expect(subject.result).to eq sut
90
+ end
91
+ end
92
+ end
93
+
94
+ describe "#integration" do
95
+ let(:client) { QualtricsAPI.new TEST_API_TOKEN }
96
+
97
+ subject do
98
+ VCR.use_cassette("response_export_start_success") do
99
+ client.surveys["SV_djzgZ6eJXqnIUyF"].export_responses.start
100
+ end
101
+ end
102
+
103
+ it "assigns @result with the export id" do
104
+ expect(subject).to_not be_nil
105
+ expect(subject).to be_a QualtricsAPI::ResponseExport
106
+ expect(subject.id).to eq "ES_cwLvnQHobKfV9t3"
107
+ end
108
+ end
109
+
110
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::SurveyCollection do
4
+
5
+ let(:connection) { double('connection') }
6
+
7
+ subject { described_class.new connection: connection, scope_id: "fake_scopeId" }
8
+
9
+ it "has a scope_id" do
10
+ expect(subject.scope_id).to eq "fake_scopeId"
11
+ end
12
+
13
+ it "has no @all when initialized" do
14
+ expect(subject.all).to eq []
15
+ end
16
+
17
+ it "can assign scope_id" do
18
+ expect(subject).to respond_to :scope_id=
19
+ end
20
+
21
+ it "takes a connection" do
22
+ expect(subject.instance_variable_get(:@conn)).to eq connection
23
+ end
24
+
25
+ describe "#query_attributes" do
26
+ it "returns only scope_id" do
27
+ expect(subject.query_attributes.size).to eq 1
28
+ expect(subject.query_attributes[:scope_id]).to eq "fake_scopeId"
29
+ end
30
+ end
31
+
32
+ describe "#find, #[]" do
33
+ let(:survey_1) { QualtricsAPI::Survey.new "id" => "s1" }
34
+ let(:survey_2) { QualtricsAPI::Survey.new "id" => "s2" }
35
+
36
+ it "finds the survey by id" do
37
+ subject.instance_variable_set :@all, [survey_1, survey_2]
38
+ expect(subject.find("s1")).to eq survey_1
39
+ expect(subject["s2"]).to eq survey_2
40
+ end
41
+
42
+ it "returns a new survey with the id" do
43
+ sut = subject["s3"]
44
+ expect(sut).to be_a QualtricsAPI::Survey
45
+ expect(sut.id).to eq "s3"
46
+ expect(sut.instance_variable_get(:@conn)).to eq connection
47
+ end
48
+ end
49
+
50
+ describe "integration" do
51
+ let(:client) { QualtricsAPI.new TEST_API_TOKEN }
52
+
53
+ subject { described_class.new connection: client.connection }
54
+
55
+ describe "#fetch" do
56
+ describe "when success" do
57
+
58
+ before do
59
+ expect(subject.size).to eq 0
60
+ end
61
+
62
+ let!(:result) do
63
+ VCR.use_cassette("survey_collection_fetch_sucess") do
64
+ subject.fetch
65
+ end
66
+ end
67
+
68
+ it "populates the collection" do
69
+ expect(subject.size).to eq 1
70
+ expect(subject.first).to be_a QualtricsAPI::Survey
71
+ end
72
+
73
+ it "passes down the connection" do
74
+ expect(subject.all.first.instance_variable_get(:@conn)).to eq client.connection
75
+ end
76
+
77
+ it "returns itself" do
78
+ expect(result).to eq subject
79
+ end
80
+ end
81
+
82
+ describe "when failed" do
83
+ it "resets surveys" do
84
+ subject.instance_variable_set :@all, [QualtricsAPI::Survey.new({})]
85
+ expect {
86
+ VCR.use_cassette("survey_collection_fetch_fail") do
87
+ subject.fetch(scope_id: "fake") rescue nil
88
+ end
89
+ }.to change { subject.all }.to([])
90
+ end
91
+ end
92
+
93
+ describe "with options" do
94
+ it "updates the options" do
95
+ VCR.use_cassette("survey_collection_fetch_with_scopeId_success") do
96
+ expect(subject.scope_id).to be_nil
97
+ subject.fetch(scope_id: "UR_3fnAz35QCGlr725")
98
+ expect(subject.scope_id).to eq "UR_3fnAz35QCGlr725"
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI::Survey do
4
+
5
+ let(:qualtrics_response) do
6
+ {
7
+ "id" => "SV_djzgZ6eJXqnIUyF",
8
+ "name" => "test_survey",
9
+ "ownerId" => "UR_3fnAz35QCGlr725",
10
+ "lastModified" => "2015-03-20 12:56:33",
11
+ "status" => "Inactive"
12
+ }
13
+ end
14
+
15
+ let(:connection) { double('connection', {get: {}}) }
16
+
17
+ subject { described_class.new qualtrics_response.merge(connection: connection)}
18
+
19
+ it "has an id" do
20
+ expect(subject.id).to eq qualtrics_response["id"]
21
+ end
22
+
23
+ it "has a name" do
24
+ expect(subject.name).to eq qualtrics_response["name"]
25
+ end
26
+
27
+ it "has an ownerId" do
28
+ expect(subject.owner_id).to eq qualtrics_response["ownerId"]
29
+ end
30
+
31
+ it "has last_modified" do
32
+ expect(subject.last_modified).to eq qualtrics_response["lastModified"]
33
+ end
34
+
35
+ it "has status" do
36
+ expect(subject.status).to eq qualtrics_response["status"]
37
+ end
38
+
39
+ it "has a connection" do
40
+ expect(subject.instance_variable_get(:@conn)).to eq connection
41
+ end
42
+
43
+ describe "export_responses" do
44
+ let(:options) do
45
+ {
46
+ start_date: "01/01/2015 10:11:22"
47
+ }
48
+ end
49
+
50
+ it "inits a ResponseExportService with options" do
51
+ expect(QualtricsAPI::Services::ResponseExportService).to receive(:new).with({
52
+ start_date: options[:start_date],
53
+ survey_id: subject.id,
54
+ connection: subject.instance_variable_get(:@conn)
55
+ })
56
+
57
+ subject.export_responses(options)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe QualtricsAPI do
4
+
5
+ describe "#new" do
6
+
7
+ subject { QualtricsAPI.new("someToken") }
8
+
9
+ it "initializes a Client with the token passed" do
10
+ expect(subject).to be_kind_of(QualtricsAPI::Client)
11
+ expect(subject.api_token).to eq "someToken"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'qualtrics_api'
2
+ require 'vcr'
3
+
4
+ TEST_API_TOKEN = "6Wpo0Vsx1cN1kcHivCaGTz5IhOvchLrg1o4L0KOZ"
5
+
6
+ VCR.configure do |config|
7
+ config.cassette_library_dir = "fixtures/vcr_cassettes"
8
+ config.hook_into :faraday
9
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qualtrics_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yurui Zhang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.2.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.9.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.9.3
97
+ description: |-
98
+ A Ruby wrapper for Qualtrics REST API version 3.0.
99
+ See https://co1.qualtrics.com/APIDocs/ for API documents.
100
+ email:
101
+ - yuruiology@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - fixtures/vcr_cassettes/response_export_start_success.yml
112
+ - fixtures/vcr_cassettes/response_export_update_success.yml
113
+ - fixtures/vcr_cassettes/survey_collection_fetch_fail.yml
114
+ - fixtures/vcr_cassettes/survey_collection_fetch_sucess.yml
115
+ - fixtures/vcr_cassettes/survey_collection_fetch_with_scopeId_success.yml
116
+ - lib/qualtrics_api.rb
117
+ - lib/qualtrics_api/client.rb
118
+ - lib/qualtrics_api/request_error_handler.rb
119
+ - lib/qualtrics_api/response_export.rb
120
+ - lib/qualtrics_api/response_export_collection.rb
121
+ - lib/qualtrics_api/services/response_export_service.rb
122
+ - lib/qualtrics_api/survey.rb
123
+ - lib/qualtrics_api/survey_collection.rb
124
+ - lib/qualtrics_api/url.rb
125
+ - lib/qualtrics_api/version.rb
126
+ - qualtrics_api.gemspec
127
+ - spec/lib/client_spec.rb
128
+ - spec/lib/response_export_collection_spec.rb
129
+ - spec/lib/response_export_spec.rb
130
+ - spec/lib/services/response_export_service_spec.rb
131
+ - spec/lib/survey_collection_spec.rb
132
+ - spec/lib/survey_spec.rb
133
+ - spec/qualtrics_api_spec.rb
134
+ - spec/spec_helper.rb
135
+ homepage: ''
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.4.3
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: A Ruby wrapper for Qualtrics REST API v3.0
159
+ test_files:
160
+ - spec/lib/client_spec.rb
161
+ - spec/lib/response_export_collection_spec.rb
162
+ - spec/lib/response_export_spec.rb
163
+ - spec/lib/services/response_export_service_spec.rb
164
+ - spec/lib/survey_collection_spec.rb
165
+ - spec/lib/survey_spec.rb
166
+ - spec/qualtrics_api_spec.rb
167
+ - spec/spec_helper.rb