survey-gizmo-ruby 4.1.0 → 5.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
1
  module SurveyGizmo
2
- # TODO: When bumping to 5.0, remove the deprecated parameters for Resource.all and Resource.first
3
- VERSION = '4.1.0'
2
+ VERSION = '5.0.2'
4
3
  end
@@ -2,7 +2,6 @@ require 'spec_helper'
2
2
  require 'survey_gizmo/configuration'
3
3
 
4
4
  describe SurveyGizmo::Configuration do
5
-
6
5
  before(:each) do
7
6
  SurveyGizmo.configure do |config|
8
7
  config.user = 'test@test.com'
@@ -14,18 +13,12 @@ describe SurveyGizmo::Configuration do
14
13
  SurveyGizmo.reset!
15
14
  end
16
15
 
17
- it 'should allow basic authentication configuration' do
18
- expect(SurveyGizmo.default_params).to eq({ 'user:md5' => 'test@test.com:5f4dcc3b5aa765d61d8327deb882cf99' })
19
- end
20
-
21
16
  it 'should allow changing user and pass' do
22
17
  SurveyGizmo.configure do |config|
23
18
  config.user = 'slimthug'
24
19
  config.password = 'fourfourz'
25
- config.api_version = 'v3'
26
20
  end
27
21
 
28
- expect(SurveyGizmo.default_params).to eq({ 'user:md5'=>'slimthug:836fd7e2961a094c01cb7ba78bac6a06' })
29
- expect(SurveyGizmo.base_uri).to eq('https://restapi.surveygizmo.com/v3')
22
+ expect(SurveyGizmo::Connection.send(:connection).params).to eq({ 'user:md5'=>'slimthug:836fd7e2961a094c01cb7ba78bac6a06' })
30
23
  end
31
24
  end
@@ -68,6 +68,14 @@ describe 'Survey Gizmo Resource' do
68
68
  survey = described_class.new('statistics' => [['Partial', 2], ['Disqualified', 28], ['Complete', 15]])
69
69
  expect(survey.number_of_completed_responses).to eq(15)
70
70
  end
71
+
72
+ it 'should determine if there are new results' do
73
+ stub_request(:get, /#{@base}\/survey\/1\/surveyresponse/).to_return(json_response(true, []))
74
+
75
+ survey = described_class.new(id: 1)
76
+ expect(survey.server_has_new_results_since?(Time.now)).to be_false
77
+ a_request(:get, /#{@base}\/survey\/1\/surveyresponse/).should have_been_made
78
+ end
71
79
  end
72
80
 
73
81
  describe SurveyGizmo::API::Question do
@@ -95,19 +103,65 @@ describe 'Survey Gizmo Resource' do
95
103
  described_class.new(:_subtype => 'radio').type.should == 'radio'
96
104
  end
97
105
 
98
- it 'should have no subquestions' do
99
- expect(described_class.new.sub_questions).to eq([])
100
- end
101
-
102
106
  it 'should find the survey' do
103
107
  stub_request(:get, /#{@base}\/survey\/1234/).to_return(json_response(true, get_attributes))
104
108
  described_class.new(base_params).survey
105
109
  a_request(:get, /#{@base}\/survey\/1234/).should have_been_made
106
110
  end
107
111
 
108
- context 'with subquestions' do
112
+ context 'options' do
113
+ let(:survey_id) { 15 }
114
+ let(:question_id) { 23 }
115
+ let(:body_data) do
116
+ {
117
+ "id" => question_id,
118
+ "title" => {"English"=>"How likely are you to bang your head to Bohemian Rhapsody?"},
119
+ "options"=>
120
+ [
121
+ {
122
+ "id" => 10014,
123
+ "title" => {"English"=>"0 = Not at all likely"},
124
+ "value" => "0 = Not at all likely"
125
+ },
126
+ {
127
+ "id" => 10015,
128
+ "title" => {"English"=>"1"},
129
+ "value" => "1"
130
+ }
131
+ ]
132
+ }
133
+ end
134
+
135
+ context 'option parsing' do
136
+ before do
137
+ stub_request(:get, /#{@base}\/survey\/#{survey_id}\/surveyquestion\/#{question_id}/).to_return(json_response(true, body_data))
138
+ end
139
+
140
+ it 'correctly parses options out of question data' do
141
+ question = described_class.first(survey_id: survey_id, id: question_id)
142
+ expect(question.options.all? { |o| o.question_id == question_id && o.survey_id == survey_id }).to be_true
143
+ expect(question.options.map { |o| o.id }).to eq([10014, 10015])
144
+ a_request(:get, /#{@base}\/.*surveyoption/).should_not have_been_made
145
+ end
146
+
147
+ it 'correctly parses sub question options' do
148
+ question = described_class.new(survey_id: survey_id, id: question_id + 1, parent_question_id: question_id)
149
+ expect(question.parent_question.id).to eq(described_class.new(body_data).id)
150
+ expect(question.options.all? { |o| o.question_id == question.id && o.survey_id == survey_id }).to be_true
151
+ expect(question.options.map { |o| o.id }).to eq([10014, 10015])
152
+ a_request(:get, /#{@base}\/survey\/#{survey_id}\/surveyquestion\/#{question_id}/).should have_been_made
153
+ end
154
+ end
155
+ end
156
+
157
+ context 'subquestions' do
109
158
  let(:parent_id) { 33 }
110
- let(:question_with_subquestions) { described_class.new(id: parent_id, survey_id: 1234, sub_question_skus: [1, 2]) }
159
+ let(:skus) { [544, 322] }
160
+ let(:question_with_subquestions) { described_class.new(id: parent_id, survey_id: 1234, sub_question_skus: skus) }
161
+
162
+ it 'should have no subquestions' do
163
+ expect(described_class.new.sub_questions).to eq([])
164
+ end
111
165
 
112
166
  it 'should have 2 subquestions and they should have the right parent question' do
113
167
  stub_request(:get, /#{@base}/).to_return(json_response(true, get_attributes))
@@ -115,6 +169,21 @@ describe 'Survey Gizmo Resource' do
115
169
 
116
170
  question_with_subquestions.sub_questions.first.parent_question
117
171
  a_request(:get, /#{@base}\/survey\/1234\/surveyquestion\/#{parent_id}/).should have_been_made
172
+ skus.each { |sku| a_request(:get, /#{@base}\/survey\/1234\/surveyquestion\/#{sku}/).should have_been_made }
173
+ end
174
+
175
+ context 'and shortname' do
176
+ let(:sku) { 6 }
177
+ let(:question_with_subquestions) { described_class.new(id: parent_id, survey_id: 1234, sub_question_skus: [["0", sku], ["foo", 8]]) }
178
+
179
+ it 'should have 2 subquestions and they should have the right parent question' do
180
+ stub_request(:get, /#{@base}/).to_return(json_response(true, get_attributes))
181
+ expect(question_with_subquestions.sub_questions.size).to eq(2)
182
+
183
+ question_with_subquestions.sub_questions.first.parent_question
184
+ a_request(:get, /#{@base}\/survey\/1234\/surveyquestion\/#{parent_id}/).should have_been_made
185
+ a_request(:get, /#{@base}\/survey\/1234\/surveyquestion\/#{sku}/).should have_been_made
186
+ end
118
187
  end
119
188
  end
120
189
  end
@@ -165,6 +234,45 @@ describe 'Survey Gizmo Resource' do
165
234
 
166
235
  it_should_behave_like 'an API object'
167
236
  it_should_behave_like 'an object with errors'
237
+
238
+ context 'answers' do
239
+ let(:survey_id) { 6 }
240
+ let(:response_id) { 7 }
241
+ let(:timestamp) { '2015-01-02'.to_time(:utc) }
242
+ let(:answers) do
243
+ {
244
+ "[question(3), option(\"10021-other\")]" => "Some other text field answer",
245
+ "[question(3), option(10021)]" => "Other (required)",
246
+ "[question(5)]" => "VERY important",
247
+ "[question(6)]" => nil,
248
+ "[question(7), option(10001)]" => nil,
249
+ "[question(8)]" => false,
250
+ "[question(9), option(10002)]" => '16',
251
+ "[question(10), question_pipe(\"Que aplicación\")]" => "5 = Extremely important",
252
+ "[question(11), option(10001)]" => ""
253
+ }
254
+ end
255
+
256
+ it 'should propagate time, survey_id, and response_id' do
257
+ response = described_class.new(
258
+ answers: answers.select { |k,v| k == "[question(5)]"},
259
+ survey_id: survey_id,
260
+ id: response_id,
261
+ submitted_at: timestamp
262
+ )
263
+ expect(response.parsed_answers.map { |a| a.to_hash }).to eq([ { survey_id: survey_id, response_id: response_id, question_id: 5, answer_text: "VERY important", submitted_at: timestamp }])
264
+ end
265
+
266
+ it 'should parse the answers and remove extraneous answers' do
267
+ expect(described_class.new(answers: answers, survey_id: 1).parsed_answers.map { |a| a.to_hash }).to eq([
268
+ { survey_id: 1, question_id: 3, option_id: 10021, other_text: "Some other text field answer" },
269
+ { survey_id: 1, question_id: 5, answer_text: "VERY important" },
270
+ { survey_id: 1, question_id: 8, answer_text: 'false' },
271
+ { survey_id: 1, question_id: 9, option_id: 10002 },
272
+ { survey_id: 1, question_id: 10, question_pipe: "Que aplicación", answer_text: "5 = Extremely important" }
273
+ ])
274
+ end
275
+ end
168
276
  end
169
277
 
170
278
  describe SurveyGizmo::API::AccountTeams do
data/spec/spec_helper.rb CHANGED
@@ -11,10 +11,16 @@ RSpec.configure do |config|
11
11
  config.include SurveyGizmoSpec::Methods
12
12
 
13
13
  config.before(:each) do
14
- @base = 'https://restapi.surveygizmo.com/v4'
15
14
  SurveyGizmo.configure do |config|
16
15
  config.user = 'test@test.com'
17
16
  config.password = 'password'
17
+ config.logger.level = Logger::WARN
18
18
  end
19
+
20
+ Pester.configure do |config|
21
+ config.environments[:survey_gizmo_ruby][:logger] = ::Logger.new(nil)
22
+ end
23
+
24
+ @base = "#{SurveyGizmo.configuration.api_url}/#{SurveyGizmo.configuration.api_version}"
19
25
  end
20
26
  end
@@ -4,16 +4,12 @@ shared_examples_for 'an API object' do
4
4
  end
5
5
 
6
6
  context "#create" do
7
- it "should make a request" do
8
- stub_api_call(:put)
9
- described_class.create(create_attributes)
10
- a_request(:put, /#{@base}#{uri_paths[:create]}/).should have_been_made
11
- end
12
-
13
- it "should return a new instance" do
7
+ it "should make a request and create a new instance" do
14
8
  stub_api_call(:put)
15
9
  obj = described_class.create(create_attributes)
10
+
16
11
  obj.should be_instance_of(described_class)
12
+ a_request(:put, /#{@base}#{uri_paths[:create]}/).should have_been_made
17
13
  end
18
14
 
19
15
  it "should set the attributes" do
@@ -25,15 +21,10 @@ shared_examples_for 'an API object' do
25
21
  end
26
22
 
27
23
  context "#get" do
28
- it "should make a request" do
29
- stub_request(:get, /#{@base}/).to_return(json_response(true, get_attributes))
30
- described_class.first(first_params)
31
- a_request(:get, /#{@base}#{uri_paths[:get]}/).should have_been_made
32
- end
33
-
34
- it "should set the attributes" do
24
+ it "should make a request and set the attributes" do
35
25
  stub_request(:get, /#{@base}/).to_return(json_response(true, get_attributes))
36
26
  obj = described_class.first(first_params)
27
+ a_request(:get, /#{@base}#{uri_paths[:get]}/).should have_been_made
37
28
  obj.attributes.reject{|k,v| v.blank? }.should == (get_attributes_to_compare || get_attributes)
38
29
  end
39
30
 
@@ -90,8 +81,8 @@ shared_examples_for 'an API object' do
90
81
  end
91
82
 
92
83
  context '#all' do
93
- before(:all) do
94
- @array = [
84
+ let(:data) do
85
+ [
95
86
  {:id => 1, :title => 'resource 1'},
96
87
  {:id => 2, :title => 'resource 2'},
97
88
  {:id => 3, :title => 'resource 3'}
@@ -99,28 +90,13 @@ shared_examples_for 'an API object' do
99
90
  end
100
91
 
101
92
  it "should make a get request" do
102
- stub_request(:get, /#{@base}/).to_return(json_response(true, []))
103
- described_class.all(get_attributes)
93
+ stub_request(:get, /#{@base}/).to_return(json_response(true, data))
94
+ iterator = described_class.all(get_attributes.merge(page: 1))
95
+ iterator.should be_instance_of(Enumerator)
96
+ collection = iterator.to_a
104
97
  a_request(:get, /#{@base}#{uri_paths[:create]}/).should have_been_made
105
- end
106
-
107
- it "should create a collection using the class" do
108
- stub_request(:get, /#{@base}/).to_return(json_response(true, @array))
109
- collection = described_class.all(get_attributes)
110
- collection.should be_instance_of(Array)
111
- end
112
-
113
- it "should return instances of the class" do
114
- stub_request(:get, /#{@base}/).to_return(json_response(true, @array))
115
- collection = described_class.all(get_attributes)
116
98
  collection.first.should be_instance_of(described_class)
117
- end
118
-
119
- it "should include all elements" do
120
- stub_request(:get, /#{@base}/).to_return(json_response(true, @array))
121
- collection = described_class.all(get_attributes)
122
99
  collection.length.should == 3
123
100
  end
124
101
  end
125
-
126
102
  end
@@ -6,7 +6,7 @@ shared_examples_for 'an object with errors' do
6
6
  context 'class methods' do
7
7
  it 'should raise errors' do
8
8
  expect { described_class.first(get_attributes) }.to raise_error
9
- expect { described_class.all(get_attributes) }.to raise_error
9
+ expect { described_class.all(get_attributes.merge(page: 1)).to_a }.to raise_error
10
10
  end
11
11
  end
12
12
  end
@@ -7,13 +7,12 @@ module SurveyGizmoSpec
7
7
  attribute :test_id, Integer
8
8
 
9
9
  # routes
10
- route '/test/:id', :via => :get
11
- route '/test/:test_id/resource', :via => :create
12
- route '/test/:test_id/resource/:id', :via => [:update, :delete]
13
-
14
- def to_param_options
15
- {id: self.id, test_id: self.test_id}
16
- end
10
+ @route = {
11
+ get: '/test/:id',
12
+ create: '/test/:test_id/resource',
13
+ update: '/test/:test_id/resource/:id',
14
+ delete: '/test/:test_id/resource/:id'
15
+ }
17
16
  end
18
17
 
19
18
  class GenericResource
@@ -16,10 +16,12 @@ Gem::Specification.new do |gem|
16
16
  gem.required_ruby_version = '>= 1.9'
17
17
 
18
18
  gem.add_dependency 'activesupport', '>= 3.0'
19
- gem.add_dependency 'addressable'
20
- gem.add_dependency 'awesome_print'
21
- gem.add_dependency 'httparty'
19
+ gem.add_dependency 'addressable', '~> 2'
20
+ gem.add_dependency 'awesome_print', '~> 1'
21
+ gem.add_dependency 'faraday', '~> 0.9'
22
+ gem.add_dependency 'faraday_middleware'
22
23
  gem.add_dependency 'i18n'
24
+ gem.add_dependency 'pester', '>= 1.0.0'
23
25
  gem.add_dependency 'virtus', '>= 1.0.0'
24
26
 
25
27
  gem.add_development_dependency 'rspec', '~> 2.11.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: survey-gizmo-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 5.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kabari Hendrick
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-12-18 00:00:00.000000000 Z
14
+ date: 2015-12-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -31,18 +31,46 @@ dependencies:
31
31
  name: addressable
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - ">="
34
+ - - "~>"
35
35
  - !ruby/object:Gem::Version
36
- version: '0'
36
+ version: '2'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ">="
41
+ - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: '0'
43
+ version: '2'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: awesome_print
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '1'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1'
58
+ - !ruby/object:Gem::Dependency
59
+ name: faraday
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '0.9'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '0.9'
72
+ - !ruby/object:Gem::Dependency
73
+ name: faraday_middleware
46
74
  requirement: !ruby/object:Gem::Requirement
47
75
  requirements:
48
76
  - - ">="
@@ -56,7 +84,7 @@ dependencies:
56
84
  - !ruby/object:Gem::Version
57
85
  version: '0'
58
86
  - !ruby/object:Gem::Dependency
59
- name: httparty
87
+ name: i18n
60
88
  requirement: !ruby/object:Gem::Requirement
61
89
  requirements:
62
90
  - - ">="
@@ -70,19 +98,19 @@ dependencies:
70
98
  - !ruby/object:Gem::Version
71
99
  version: '0'
72
100
  - !ruby/object:Gem::Dependency
73
- name: i18n
101
+ name: pester
74
102
  requirement: !ruby/object:Gem::Requirement
75
103
  requirements:
76
104
  - - ">="
77
105
  - !ruby/object:Gem::Version
78
- version: '0'
106
+ version: 1.0.0
79
107
  type: :runtime
80
108
  prerelease: false
81
109
  version_requirements: !ruby/object:Gem::Requirement
82
110
  requirements:
83
111
  - - ">="
84
112
  - !ruby/object:Gem::Version
85
- version: '0'
113
+ version: 1.0.0
86
114
  - !ruby/object:Gem::Dependency
87
115
  name: virtus
88
116
  requirement: !ruby/object:Gem::Requirement
@@ -169,6 +197,8 @@ files:
169
197
  - Rakefile
170
198
  - lib/survey-gizmo-ruby.rb
171
199
  - lib/survey_gizmo/api/account_teams.rb
200
+ - lib/survey_gizmo/api/answer.rb
201
+ - lib/survey_gizmo/api/campaign.rb
172
202
  - lib/survey_gizmo/api/contact.rb
173
203
  - lib/survey_gizmo/api/email_message.rb
174
204
  - lib/survey_gizmo/api/option.rb
@@ -176,12 +206,12 @@ files:
176
206
  - lib/survey_gizmo/api/question.rb
177
207
  - lib/survey_gizmo/api/response.rb
178
208
  - lib/survey_gizmo/api/survey.rb
179
- - lib/survey_gizmo/api/survey_campaign.rb
180
209
  - lib/survey_gizmo/configuration.rb
210
+ - lib/survey_gizmo/connection.rb
211
+ - lib/survey_gizmo/faraday_middleware/parse_survey_gizmo.rb
212
+ - lib/survey_gizmo/faraday_middleware/pester_survey_gizmo.rb
181
213
  - lib/survey_gizmo/multilingual_title.rb
182
214
  - lib/survey_gizmo/resource.rb
183
- - lib/survey_gizmo/rest_response.rb
184
- - lib/survey_gizmo/survey_gizmo.rb
185
215
  - lib/survey_gizmo/version.rb
186
216
  - spec/configuration_spec.rb
187
217
  - spec/resource_spec.rb
@@ -190,7 +220,6 @@ files:
190
220
  - spec/support/spec_shared_api_object.rb
191
221
  - spec/support/spec_shared_object_with_errors.rb
192
222
  - spec/support/test_resource_classes.rb
193
- - spec/survey-gizmo-ruby_spec.rb
194
223
  - spec/test_json/page.json
195
224
  - spec/test_json/question.json
196
225
  - spec/test_json/survey.json
@@ -215,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
244
  version: '0'
216
245
  requirements: []
217
246
  rubyforge_project:
218
- rubygems_version: 2.4.5.1
247
+ rubygems_version: 2.5.1
219
248
  signing_key:
220
249
  specification_version: 4
221
250
  summary: Gem to use the SurveyGizmo.com REST API, v3+
@@ -227,7 +256,6 @@ test_files:
227
256
  - spec/support/spec_shared_api_object.rb
228
257
  - spec/support/spec_shared_object_with_errors.rb
229
258
  - spec/support/test_resource_classes.rb
230
- - spec/survey-gizmo-ruby_spec.rb
231
259
  - spec/test_json/page.json
232
260
  - spec/test_json/question.json
233
261
  - spec/test_json/survey.json