survey-gizmo-ruby 4.1.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SurveyGizmo do
4
- it 'should have a base uri' do
5
- SurveyGizmo.base_uri.should == 'https://restapi.surveygizmo.com/v4'
6
- end
7
- end