pollster 0.2.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -1
  3. data/README.md +68 -111
  4. data/example.rb +128 -0
  5. data/lib/pollster.rb +46 -4
  6. data/lib/pollster/api.rb +655 -0
  7. data/lib/pollster/api_client.rb +400 -0
  8. data/lib/pollster/api_error.rb +26 -0
  9. data/lib/pollster/configuration.rb +184 -0
  10. data/lib/pollster/models/chart.rb +239 -0
  11. data/lib/pollster/models/chart_estimate.rb +226 -0
  12. data/lib/pollster/models/chart_estimate_lowess_parameters.rb +197 -0
  13. data/lib/pollster/models/chart_pollster_estimate_summary.rb +217 -0
  14. data/lib/pollster/models/chart_pollster_trendlines.rb +41 -0
  15. data/lib/pollster/models/inline_response_200.rb +208 -0
  16. data/lib/pollster/models/inline_response_200_3.rb +206 -0
  17. data/lib/pollster/models/inline_response_200_4.rb +208 -0
  18. data/lib/pollster/models/poll.rb +279 -0
  19. data/lib/pollster/models/poll_question.rb +198 -0
  20. data/lib/pollster/models/poll_question_responses.rb +197 -0
  21. data/lib/pollster/models/poll_question_sample_subpopulations.rb +209 -0
  22. data/lib/pollster/models/pollster_chart_poll_questions.rb +92 -0
  23. data/lib/pollster/models/question.rb +253 -0
  24. data/lib/pollster/models/question_poll_responses_clean.rb +93 -0
  25. data/lib/pollster/models/question_poll_responses_raw.rb +86 -0
  26. data/lib/pollster/models/question_responses.rb +207 -0
  27. data/lib/pollster/models/tag.rb +207 -0
  28. data/lib/pollster/version.rb +1 -1
  29. data/pollster.gemspec +17 -16
  30. metadata +85 -65
  31. data/.gitignore +0 -2
  32. data/Gemfile +0 -3
  33. data/Gemfile.lock +0 -19
  34. data/Rakefile +0 -8
  35. data/lib/pollster/base.rb +0 -45
  36. data/lib/pollster/chart.rb +0 -69
  37. data/lib/pollster/poll.rb +0 -47
  38. data/lib/pollster/question.rb +0 -19
  39. data/test/test_pollster.rb +0 -26
@@ -0,0 +1,279 @@
1
+ require 'date'
2
+
3
+ module Pollster
4
+
5
+ class Poll
6
+ # Unique Poll identifier. For example: `gallup-26892`.
7
+ attr_accessor :slug
8
+
9
+ # First date survey house conducted polling.
10
+ attr_accessor :start_date
11
+
12
+ # Last date survey house conducted polling.
13
+ attr_accessor :end_date
14
+
15
+ # Date Pollster editors first entered this Poll
16
+ attr_accessor :created_at
17
+
18
+ # Date Pollster editors last edited this Poll. Edits are usually corrections; they are sometimes additions of new questions that were originally skipped.
19
+ attr_accessor :updated_at
20
+
21
+ # Name of survey house. For example: `Gallup`
22
+ attr_accessor :survey_house
23
+
24
+ # One of `Automated Phone`, `Internet`, `IVR/Live Phone`, etc.
25
+ attr_accessor :mode
26
+
27
+ # Website where the survey house published the poll results.
28
+ attr_accessor :url
29
+
30
+ # One of `Nonpartisan`, `Pollster` (the survey house is partisan), `Sponsor` (the survey house is nonpartisan, but the sponsor is partisan)
31
+ attr_accessor :partisanship
32
+
33
+ # `None` if `partisanship` is `Nonpartisan`; otherwise one of `Dem`, `Rep` or `Other`
34
+ attr_accessor :partisan_affiliation
35
+
36
+ # Questions on the Poll that Pollster editors have entered. Pollster doesn't include every question on the poll: it only includes questions of interest to Pollster editors. Poll questions are ordered in the same order as published by the survey house.
37
+ attr_accessor :poll_questions
38
+
39
+
40
+ # Attribute mapping from ruby-style variable name to JSON key.
41
+ def self.attribute_map
42
+ {
43
+ :'slug' => :'slug',
44
+ :'start_date' => :'start_date',
45
+ :'end_date' => :'end_date',
46
+ :'created_at' => :'created_at',
47
+ :'updated_at' => :'updated_at',
48
+ :'survey_house' => :'survey_house',
49
+ :'mode' => :'mode',
50
+ :'url' => :'url',
51
+ :'partisanship' => :'partisanship',
52
+ :'partisan_affiliation' => :'partisan_affiliation',
53
+ :'poll_questions' => :'poll_questions'
54
+ }
55
+ end
56
+
57
+ # Attribute type mapping.
58
+ def self.swagger_types
59
+ {
60
+ :'slug' => :'String',
61
+ :'start_date' => :'Date',
62
+ :'end_date' => :'Date',
63
+ :'created_at' => :'DateTime',
64
+ :'updated_at' => :'DateTime',
65
+ :'survey_house' => :'String',
66
+ :'mode' => :'String',
67
+ :'url' => :'String',
68
+ :'partisanship' => :'String',
69
+ :'partisan_affiliation' => :'String',
70
+ :'poll_questions' => :'Array<PollQuestion>'
71
+ }
72
+ end
73
+
74
+ # Initializes the object
75
+ # @param [Hash] attributes Model attributes in the form of hash
76
+ def initialize(attributes = {})
77
+ return unless attributes.is_a?(Hash)
78
+
79
+ # convert string to symbol for hash key
80
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
81
+
82
+ if attributes.has_key?(:'slug')
83
+ self.slug = attributes[:'slug']
84
+ end
85
+
86
+ if attributes.has_key?(:'start_date')
87
+ self.start_date = attributes[:'start_date']
88
+ end
89
+
90
+ if attributes.has_key?(:'end_date')
91
+ self.end_date = attributes[:'end_date']
92
+ end
93
+
94
+ if attributes.has_key?(:'created_at')
95
+ self.created_at = attributes[:'created_at']
96
+ end
97
+
98
+ if attributes.has_key?(:'updated_at')
99
+ self.updated_at = attributes[:'updated_at']
100
+ end
101
+
102
+ if attributes.has_key?(:'survey_house')
103
+ self.survey_house = attributes[:'survey_house']
104
+ end
105
+
106
+ if attributes.has_key?(:'mode')
107
+ self.mode = attributes[:'mode']
108
+ end
109
+
110
+ if attributes.has_key?(:'url')
111
+ self.url = attributes[:'url']
112
+ end
113
+
114
+ if attributes.has_key?(:'partisanship')
115
+ self.partisanship = attributes[:'partisanship']
116
+ end
117
+
118
+ if attributes.has_key?(:'partisan_affiliation')
119
+ self.partisan_affiliation = attributes[:'partisan_affiliation']
120
+ end
121
+
122
+ if attributes.has_key?(:'poll_questions')
123
+ if (value = attributes[:'poll_questions']).is_a?(Array)
124
+ self.poll_questions = value
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ # Show invalid properties with the reasons. Usually used together with valid?
131
+ # @return Array for valid properies with the reasons
132
+ def list_invalid_properties
133
+ invalid_properties = Array.new
134
+ return invalid_properties
135
+ end
136
+
137
+ # Check to see if the all the properties in the model are valid
138
+ # @return true if the model is valid
139
+ def valid?
140
+ return true
141
+ end
142
+
143
+ # Checks equality by comparing each attribute.
144
+ # @param [Object] Object to be compared
145
+ def ==(o)
146
+ return true if self.equal?(o)
147
+ self.class == o.class &&
148
+ slug == o.slug &&
149
+ start_date == o.start_date &&
150
+ end_date == o.end_date &&
151
+ created_at == o.created_at &&
152
+ updated_at == o.updated_at &&
153
+ survey_house == o.survey_house &&
154
+ mode == o.mode &&
155
+ url == o.url &&
156
+ partisanship == o.partisanship &&
157
+ partisan_affiliation == o.partisan_affiliation &&
158
+ poll_questions == o.poll_questions
159
+ end
160
+
161
+ # @see the `==` method
162
+ # @param [Object] Object to be compared
163
+ def eql?(o)
164
+ self == o
165
+ end
166
+
167
+ # Calculates hash code according to all attributes.
168
+ # @return [Fixnum] Hash code
169
+ def hash
170
+ [slug, start_date, end_date, created_at, updated_at, survey_house, mode, url, partisanship, partisan_affiliation, poll_questions].hash
171
+ end
172
+
173
+ # Builds the object from hash
174
+ # @param [Hash] attributes Model attributes in the form of hash
175
+ # @return [Object] Returns the model itself
176
+ def build_from_hash(attributes)
177
+ return nil unless attributes.is_a?(Hash)
178
+ self.class.swagger_types.each_pair do |key, type|
179
+ if type =~ /\AArray<(.*)>/i
180
+ # check to ensure the input is an array given that the the attribute
181
+ # is documented as an array but the input is not
182
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
183
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
184
+ end
185
+ elsif !attributes[self.class.attribute_map[key]].nil?
186
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
187
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
188
+ end
189
+
190
+ self
191
+ end
192
+
193
+ # Deserializes the data based on type
194
+ # @param string type Data type
195
+ # @param string value Value to be deserialized
196
+ # @return [Object] Deserialized data
197
+ def _deserialize(type, value)
198
+ case type.to_sym
199
+ when :DateTime
200
+ DateTime.parse(value)
201
+ when :Date
202
+ Date.parse(value)
203
+ when :String
204
+ value.to_s
205
+ when :Integer
206
+ value.to_i
207
+ when :Float
208
+ value.to_f
209
+ when :BOOLEAN
210
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
211
+ true
212
+ else
213
+ false
214
+ end
215
+ when :Object
216
+ # generic object (usually a Hash), return directly
217
+ value
218
+ when /\AArray<(?<inner_type>.+)>\z/
219
+ inner_type = Regexp.last_match[:inner_type]
220
+ value.map { |v| _deserialize(inner_type, v) }
221
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
222
+ k_type = Regexp.last_match[:k_type]
223
+ v_type = Regexp.last_match[:v_type]
224
+ {}.tap do |hash|
225
+ value.each do |k, v|
226
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
227
+ end
228
+ end
229
+ else # model
230
+ temp_model = Pollster.const_get(type).new
231
+ temp_model.build_from_hash(value)
232
+ end
233
+ end
234
+
235
+ # Returns the string representation of the object
236
+ # @return [String] String presentation of the object
237
+ def to_s
238
+ to_hash.to_s
239
+ end
240
+
241
+ # to_body is an alias to to_hash (backward compatibility)
242
+ # @return [Hash] Returns the object in the form of hash
243
+ def to_body
244
+ to_hash
245
+ end
246
+
247
+ # Returns the object in the form of hash
248
+ # @return [Hash] Returns the object in the form of hash
249
+ def to_hash
250
+ hash = {}
251
+ self.class.attribute_map.each_pair do |attr, param|
252
+ value = self.send(attr)
253
+ next if value.nil?
254
+ hash[param] = _to_hash(value)
255
+ end
256
+ hash
257
+ end
258
+
259
+ # Outputs non-array value in the form of hash
260
+ # For object, use to_hash. Otherwise, just return the value
261
+ # @param [Object] value Any valid value
262
+ # @return [Hash] Returns the value in the form of hash
263
+ def _to_hash(value)
264
+ if value.is_a?(Array)
265
+ value.compact.map{ |v| _to_hash(v) }
266
+ elsif value.is_a?(Hash)
267
+ {}.tap do |hash|
268
+ value.each { |k, v| hash[k] = _to_hash(v) }
269
+ end
270
+ elsif value.respond_to? :to_hash
271
+ value.to_hash
272
+ else
273
+ value
274
+ end
275
+ end
276
+
277
+ end
278
+
279
+ end
@@ -0,0 +1,198 @@
1
+ require 'date'
2
+
3
+ module Pollster
4
+
5
+ class PollQuestion
6
+ # The text of the question in the Poll. This may be an empty string if the survey house didn't publish the question or if Pollster editors didn't enter it.
7
+ attr_accessor :text
8
+
9
+ attr_accessor :question
10
+
11
+ # Results by subpopulation that Pollster editors have entered for this question. These are always in this order: Adults, Adults - Democrat, Adults - Republican, Adults - independent, Registered Voters, Registered Voters - Democrat, Registered Voters - Republican, Registered Voters - independent, Likely Voters, Likely Voters - Democrat, Likely Voters - Republican, Likely Voters - independent
12
+ attr_accessor :sample_subpopulations
13
+
14
+
15
+ # Attribute mapping from ruby-style variable name to JSON key.
16
+ def self.attribute_map
17
+ {
18
+ :'text' => :'text',
19
+ :'question' => :'question',
20
+ :'sample_subpopulations' => :'sample_subpopulations'
21
+ }
22
+ end
23
+
24
+ # Attribute type mapping.
25
+ def self.swagger_types
26
+ {
27
+ :'text' => :'String',
28
+ :'question' => :'Question',
29
+ :'sample_subpopulations' => :'Array<PollQuestionSampleSubpopulations>'
30
+ }
31
+ end
32
+
33
+ # Initializes the object
34
+ # @param [Hash] attributes Model attributes in the form of hash
35
+ def initialize(attributes = {})
36
+ return unless attributes.is_a?(Hash)
37
+
38
+ # convert string to symbol for hash key
39
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
40
+
41
+ if attributes.has_key?(:'text')
42
+ self.text = attributes[:'text']
43
+ end
44
+
45
+ if attributes.has_key?(:'question')
46
+ self.question = attributes[:'question']
47
+ end
48
+
49
+ if attributes.has_key?(:'sample_subpopulations')
50
+ if (value = attributes[:'sample_subpopulations']).is_a?(Array)
51
+ self.sample_subpopulations = value
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ # Show invalid properties with the reasons. Usually used together with valid?
58
+ # @return Array for valid properies with the reasons
59
+ def list_invalid_properties
60
+ invalid_properties = Array.new
61
+ return invalid_properties
62
+ end
63
+
64
+ # Check to see if the all the properties in the model are valid
65
+ # @return true if the model is valid
66
+ def valid?
67
+ return true
68
+ end
69
+
70
+ # Checks equality by comparing each attribute.
71
+ # @param [Object] Object to be compared
72
+ def ==(o)
73
+ return true if self.equal?(o)
74
+ self.class == o.class &&
75
+ text == o.text &&
76
+ question == o.question &&
77
+ sample_subpopulations == o.sample_subpopulations
78
+ end
79
+
80
+ # @see the `==` method
81
+ # @param [Object] Object to be compared
82
+ def eql?(o)
83
+ self == o
84
+ end
85
+
86
+ # Calculates hash code according to all attributes.
87
+ # @return [Fixnum] Hash code
88
+ def hash
89
+ [text, question, sample_subpopulations].hash
90
+ end
91
+
92
+ # Builds the object from hash
93
+ # @param [Hash] attributes Model attributes in the form of hash
94
+ # @return [Object] Returns the model itself
95
+ def build_from_hash(attributes)
96
+ return nil unless attributes.is_a?(Hash)
97
+ self.class.swagger_types.each_pair do |key, type|
98
+ if type =~ /\AArray<(.*)>/i
99
+ # check to ensure the input is an array given that the the attribute
100
+ # is documented as an array but the input is not
101
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
102
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
103
+ end
104
+ elsif !attributes[self.class.attribute_map[key]].nil?
105
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
106
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
107
+ end
108
+
109
+ self
110
+ end
111
+
112
+ # Deserializes the data based on type
113
+ # @param string type Data type
114
+ # @param string value Value to be deserialized
115
+ # @return [Object] Deserialized data
116
+ def _deserialize(type, value)
117
+ case type.to_sym
118
+ when :DateTime
119
+ DateTime.parse(value)
120
+ when :Date
121
+ Date.parse(value)
122
+ when :String
123
+ value.to_s
124
+ when :Integer
125
+ value.to_i
126
+ when :Float
127
+ value.to_f
128
+ when :BOOLEAN
129
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
130
+ true
131
+ else
132
+ false
133
+ end
134
+ when :Object
135
+ # generic object (usually a Hash), return directly
136
+ value
137
+ when /\AArray<(?<inner_type>.+)>\z/
138
+ inner_type = Regexp.last_match[:inner_type]
139
+ value.map { |v| _deserialize(inner_type, v) }
140
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
141
+ k_type = Regexp.last_match[:k_type]
142
+ v_type = Regexp.last_match[:v_type]
143
+ {}.tap do |hash|
144
+ value.each do |k, v|
145
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
146
+ end
147
+ end
148
+ else # model
149
+ temp_model = Pollster.const_get(type).new
150
+ temp_model.build_from_hash(value)
151
+ end
152
+ end
153
+
154
+ # Returns the string representation of the object
155
+ # @return [String] String presentation of the object
156
+ def to_s
157
+ to_hash.to_s
158
+ end
159
+
160
+ # to_body is an alias to to_hash (backward compatibility)
161
+ # @return [Hash] Returns the object in the form of hash
162
+ def to_body
163
+ to_hash
164
+ end
165
+
166
+ # Returns the object in the form of hash
167
+ # @return [Hash] Returns the object in the form of hash
168
+ def to_hash
169
+ hash = {}
170
+ self.class.attribute_map.each_pair do |attr, param|
171
+ value = self.send(attr)
172
+ next if value.nil?
173
+ hash[param] = _to_hash(value)
174
+ end
175
+ hash
176
+ end
177
+
178
+ # Outputs non-array value in the form of hash
179
+ # For object, use to_hash. Otherwise, just return the value
180
+ # @param [Object] value Any valid value
181
+ # @return [Hash] Returns the value in the form of hash
182
+ def _to_hash(value)
183
+ if value.is_a?(Array)
184
+ value.compact.map{ |v| _to_hash(v) }
185
+ elsif value.is_a?(Hash)
186
+ {}.tap do |hash|
187
+ value.each { |k, v| hash[k] = _to_hash(v) }
188
+ end
189
+ elsif value.respond_to? :to_hash
190
+ value.to_hash
191
+ else
192
+ value
193
+ end
194
+ end
195
+
196
+ end
197
+
198
+ end