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.
- checksums.yaml +4 -4
- data/README.md +108 -50
- data/lib/survey-gizmo-ruby.rb +12 -20
- data/lib/survey_gizmo/api/account_teams.rb +1 -6
- data/lib/survey_gizmo/api/answer.rb +59 -0
- data/lib/survey_gizmo/api/{survey_campaign.rb → campaign.rb} +4 -5
- data/lib/survey_gizmo/api/contact.rb +2 -7
- data/lib/survey_gizmo/api/email_message.rb +1 -6
- data/lib/survey_gizmo/api/option.rb +2 -7
- data/lib/survey_gizmo/api/page.rb +12 -8
- data/lib/survey_gizmo/api/question.rb +24 -12
- data/lib/survey_gizmo/api/response.rb +14 -5
- data/lib/survey_gizmo/api/survey.rb +29 -13
- data/lib/survey_gizmo/configuration.rb +61 -12
- data/lib/survey_gizmo/connection.rb +39 -0
- data/lib/survey_gizmo/faraday_middleware/parse_survey_gizmo.rb +75 -0
- data/lib/survey_gizmo/faraday_middleware/pester_survey_gizmo.rb +18 -0
- data/lib/survey_gizmo/multilingual_title.rb +1 -3
- data/lib/survey_gizmo/resource.rb +100 -104
- data/lib/survey_gizmo/version.rb +1 -2
- data/spec/configuration_spec.rb +1 -8
- data/spec/resource_spec.rb +114 -6
- data/spec/spec_helper.rb +7 -1
- data/spec/support/spec_shared_api_object.rb +11 -35
- data/spec/support/spec_shared_object_with_errors.rb +1 -1
- data/spec/support/test_resource_classes.rb +6 -7
- data/survey-gizmo-ruby.gemspec +5 -3
- metadata +44 -16
- data/lib/survey_gizmo/rest_response.rb +0 -91
- data/lib/survey_gizmo/survey_gizmo.rb +0 -15
- data/spec/survey-gizmo-ruby_spec.rb +0 -7
@@ -1,91 +0,0 @@
|
|
1
|
-
# This class normalizes the response returned by Survey Gizmo, including validation.
|
2
|
-
|
3
|
-
class RestResponse
|
4
|
-
attr_accessor :raw_response
|
5
|
-
attr_accessor :parsed_response
|
6
|
-
|
7
|
-
def initialize(http_response)
|
8
|
-
@raw_response = http_response
|
9
|
-
@parsed_response = http_response.parsed_response
|
10
|
-
|
11
|
-
if ENV['GIZMO_DEBUG']
|
12
|
-
ap 'Parsed SurveyGizmo Response:'
|
13
|
-
ap @parsed_response
|
14
|
-
end
|
15
|
-
|
16
|
-
fail "Bad response: #{http_response.inspect}" unless @parsed_response['result_ok'] && @parsed_response['result_ok'].to_s.downcase == 'true'
|
17
|
-
return unless data
|
18
|
-
|
19
|
-
# Handle really crappy [] notation in SG API, so far just in SurveyResponse
|
20
|
-
(data.is_a?(Array) ? data : [data]).compact.each do |datum|
|
21
|
-
unless datum['datesubmitted'].blank?
|
22
|
-
# SurveyGizmo returns date information in EST but does not provide time zone information.
|
23
|
-
# See https://surveygizmov4.helpgizmo.com/help/article/link/date-and-time-submitted
|
24
|
-
datum['datesubmitted'] = datum['datesubmitted'] + ' EST'
|
25
|
-
end
|
26
|
-
|
27
|
-
datum.keys.grep(/^\[/).each do |key|
|
28
|
-
next if datum[key].nil? || datum[key].length == 0
|
29
|
-
|
30
|
-
parent = find_attribute_parent(key)
|
31
|
-
datum[parent] ||= {}
|
32
|
-
|
33
|
-
case key.downcase
|
34
|
-
when /(url|variable.*standard)/
|
35
|
-
datum[parent][cleanup_attribute_name(key).to_sym] = datum[key]
|
36
|
-
when /variable.*shown/
|
37
|
-
datum[parent][cleanup_attribute_name(key).to_i] = datum[key].include?('1')
|
38
|
-
when /variable/
|
39
|
-
datum[parent][cleanup_attribute_name(key).to_i] = datum[key].to_i
|
40
|
-
when /question/
|
41
|
-
datum[parent][key] = datum[key]
|
42
|
-
end
|
43
|
-
|
44
|
-
datum.delete(key)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# The parsed JSON data of the response
|
50
|
-
def data
|
51
|
-
@parsed_response['data']
|
52
|
-
end
|
53
|
-
|
54
|
-
# The error message if there is one
|
55
|
-
def message
|
56
|
-
@parsed_response['message']
|
57
|
-
end
|
58
|
-
|
59
|
-
def current_page
|
60
|
-
@parsed_response['page']
|
61
|
-
end
|
62
|
-
|
63
|
-
def total_pages
|
64
|
-
@parsed_response['total_pages']
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def cleanup_attribute_name(attr)
|
70
|
-
attr.downcase.gsub(/[^[:alnum:]]+/, '_')
|
71
|
-
.gsub(/(url|variable|standard|shown)/, '')
|
72
|
-
.gsub(/_+/, '_')
|
73
|
-
.gsub(/^_/, '')
|
74
|
-
.gsub(/_$/, '')
|
75
|
-
end
|
76
|
-
|
77
|
-
def find_attribute_parent(attr)
|
78
|
-
case attr.downcase
|
79
|
-
when /url/
|
80
|
-
'url'
|
81
|
-
when /variable.*standard/
|
82
|
-
'meta'
|
83
|
-
when /variable.*shown/
|
84
|
-
'shown'
|
85
|
-
when /variable/
|
86
|
-
'variable'
|
87
|
-
when /question/
|
88
|
-
'answers'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module SurveyGizmo
|
2
|
-
include HTTParty
|
3
|
-
|
4
|
-
debug_output $stderr if ENV['GIZMO_DEBUG'] =~ /^(true|t|yes|y|1)$/i
|
5
|
-
default_timeout 600 # 10 minutes, SurveyGizmo has serious problems.
|
6
|
-
|
7
|
-
format :json
|
8
|
-
|
9
|
-
URLError = Class.new(RuntimeError)
|
10
|
-
|
11
|
-
def self.setup
|
12
|
-
base_uri "https://restapi.surveygizmo.com/#{SurveyGizmo.configuration.api_version}"
|
13
|
-
default_params({ 'user:md5' => "#{SurveyGizmo.configuration.user}:#{Digest::MD5.hexdigest(SurveyGizmo.configuration.password)}" })
|
14
|
-
end
|
15
|
-
end
|