pollster 0.2.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +68 -111
- data/example.rb +128 -0
- data/lib/pollster.rb +46 -4
- data/lib/pollster/api.rb +655 -0
- data/lib/pollster/api_client.rb +400 -0
- data/lib/pollster/api_error.rb +26 -0
- data/lib/pollster/configuration.rb +184 -0
- data/lib/pollster/models/chart.rb +239 -0
- data/lib/pollster/models/chart_estimate.rb +226 -0
- data/lib/pollster/models/chart_estimate_lowess_parameters.rb +197 -0
- data/lib/pollster/models/chart_pollster_estimate_summary.rb +217 -0
- data/lib/pollster/models/chart_pollster_trendlines.rb +41 -0
- data/lib/pollster/models/inline_response_200.rb +208 -0
- data/lib/pollster/models/inline_response_200_3.rb +206 -0
- data/lib/pollster/models/inline_response_200_4.rb +208 -0
- data/lib/pollster/models/poll.rb +279 -0
- data/lib/pollster/models/poll_question.rb +198 -0
- data/lib/pollster/models/poll_question_responses.rb +197 -0
- data/lib/pollster/models/poll_question_sample_subpopulations.rb +209 -0
- data/lib/pollster/models/pollster_chart_poll_questions.rb +92 -0
- data/lib/pollster/models/question.rb +253 -0
- data/lib/pollster/models/question_poll_responses_clean.rb +93 -0
- data/lib/pollster/models/question_poll_responses_raw.rb +86 -0
- data/lib/pollster/models/question_responses.rb +207 -0
- data/lib/pollster/models/tag.rb +207 -0
- data/lib/pollster/version.rb +1 -1
- data/pollster.gemspec +17 -16
- metadata +85 -65
- data/.gitignore +0 -2
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -19
- data/Rakefile +0 -8
- data/lib/pollster/base.rb +0 -45
- data/lib/pollster/chart.rb +0 -69
- data/lib/pollster/poll.rb +0 -47
- data/lib/pollster/question.rb +0 -19
- data/test/test_pollster.rb +0 -26
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Pollster
|
4
|
+
|
5
|
+
class Tag
|
6
|
+
# Unique tag identifier. For example: `2016-president`.
|
7
|
+
attr_accessor :slug
|
8
|
+
|
9
|
+
# Number of Questions with this Tag
|
10
|
+
attr_accessor :n_questions
|
11
|
+
|
12
|
+
# Number of Charts with this Tag (including Charts that represent Questions with this Tag).
|
13
|
+
attr_accessor :n_charts
|
14
|
+
|
15
|
+
# Number of Polls that include Questions with this Tag.
|
16
|
+
attr_accessor :n_polls
|
17
|
+
|
18
|
+
|
19
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
20
|
+
def self.attribute_map
|
21
|
+
{
|
22
|
+
:'slug' => :'slug',
|
23
|
+
:'n_questions' => :'n_questions',
|
24
|
+
:'n_charts' => :'n_charts',
|
25
|
+
:'n_polls' => :'n_polls'
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Attribute type mapping.
|
30
|
+
def self.swagger_types
|
31
|
+
{
|
32
|
+
:'slug' => :'String',
|
33
|
+
:'n_questions' => :'Integer',
|
34
|
+
:'n_charts' => :'Integer',
|
35
|
+
:'n_polls' => :'Integer'
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# Initializes the object
|
40
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
41
|
+
def initialize(attributes = {})
|
42
|
+
return unless attributes.is_a?(Hash)
|
43
|
+
|
44
|
+
# convert string to symbol for hash key
|
45
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
46
|
+
|
47
|
+
if attributes.has_key?(:'slug')
|
48
|
+
self.slug = attributes[:'slug']
|
49
|
+
end
|
50
|
+
|
51
|
+
if attributes.has_key?(:'n_questions')
|
52
|
+
self.n_questions = attributes[:'n_questions']
|
53
|
+
end
|
54
|
+
|
55
|
+
if attributes.has_key?(:'n_charts')
|
56
|
+
self.n_charts = attributes[:'n_charts']
|
57
|
+
end
|
58
|
+
|
59
|
+
if attributes.has_key?(:'n_polls')
|
60
|
+
self.n_polls = attributes[:'n_polls']
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
66
|
+
# @return Array for valid properies with the reasons
|
67
|
+
def list_invalid_properties
|
68
|
+
invalid_properties = Array.new
|
69
|
+
return invalid_properties
|
70
|
+
end
|
71
|
+
|
72
|
+
# Check to see if the all the properties in the model are valid
|
73
|
+
# @return true if the model is valid
|
74
|
+
def valid?
|
75
|
+
return true
|
76
|
+
end
|
77
|
+
|
78
|
+
# Checks equality by comparing each attribute.
|
79
|
+
# @param [Object] Object to be compared
|
80
|
+
def ==(o)
|
81
|
+
return true if self.equal?(o)
|
82
|
+
self.class == o.class &&
|
83
|
+
slug == o.slug &&
|
84
|
+
n_questions == o.n_questions &&
|
85
|
+
n_charts == o.n_charts &&
|
86
|
+
n_polls == o.n_polls
|
87
|
+
end
|
88
|
+
|
89
|
+
# @see the `==` method
|
90
|
+
# @param [Object] Object to be compared
|
91
|
+
def eql?(o)
|
92
|
+
self == o
|
93
|
+
end
|
94
|
+
|
95
|
+
# Calculates hash code according to all attributes.
|
96
|
+
# @return [Fixnum] Hash code
|
97
|
+
def hash
|
98
|
+
[slug, n_questions, n_charts, n_polls].hash
|
99
|
+
end
|
100
|
+
|
101
|
+
# Builds the object from hash
|
102
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
103
|
+
# @return [Object] Returns the model itself
|
104
|
+
def build_from_hash(attributes)
|
105
|
+
return nil unless attributes.is_a?(Hash)
|
106
|
+
self.class.swagger_types.each_pair do |key, type|
|
107
|
+
if type =~ /\AArray<(.*)>/i
|
108
|
+
# check to ensure the input is an array given that the the attribute
|
109
|
+
# is documented as an array but the input is not
|
110
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
111
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
112
|
+
end
|
113
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
114
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
115
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
116
|
+
end
|
117
|
+
|
118
|
+
self
|
119
|
+
end
|
120
|
+
|
121
|
+
# Deserializes the data based on type
|
122
|
+
# @param string type Data type
|
123
|
+
# @param string value Value to be deserialized
|
124
|
+
# @return [Object] Deserialized data
|
125
|
+
def _deserialize(type, value)
|
126
|
+
case type.to_sym
|
127
|
+
when :DateTime
|
128
|
+
DateTime.parse(value)
|
129
|
+
when :Date
|
130
|
+
Date.parse(value)
|
131
|
+
when :String
|
132
|
+
value.to_s
|
133
|
+
when :Integer
|
134
|
+
value.to_i
|
135
|
+
when :Float
|
136
|
+
value.to_f
|
137
|
+
when :BOOLEAN
|
138
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
139
|
+
true
|
140
|
+
else
|
141
|
+
false
|
142
|
+
end
|
143
|
+
when :Object
|
144
|
+
# generic object (usually a Hash), return directly
|
145
|
+
value
|
146
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
147
|
+
inner_type = Regexp.last_match[:inner_type]
|
148
|
+
value.map { |v| _deserialize(inner_type, v) }
|
149
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
150
|
+
k_type = Regexp.last_match[:k_type]
|
151
|
+
v_type = Regexp.last_match[:v_type]
|
152
|
+
{}.tap do |hash|
|
153
|
+
value.each do |k, v|
|
154
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
else # model
|
158
|
+
temp_model = Pollster.const_get(type).new
|
159
|
+
temp_model.build_from_hash(value)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# Returns the string representation of the object
|
164
|
+
# @return [String] String presentation of the object
|
165
|
+
def to_s
|
166
|
+
to_hash.to_s
|
167
|
+
end
|
168
|
+
|
169
|
+
# to_body is an alias to to_hash (backward compatibility)
|
170
|
+
# @return [Hash] Returns the object in the form of hash
|
171
|
+
def to_body
|
172
|
+
to_hash
|
173
|
+
end
|
174
|
+
|
175
|
+
# Returns the object in the form of hash
|
176
|
+
# @return [Hash] Returns the object in the form of hash
|
177
|
+
def to_hash
|
178
|
+
hash = {}
|
179
|
+
self.class.attribute_map.each_pair do |attr, param|
|
180
|
+
value = self.send(attr)
|
181
|
+
next if value.nil?
|
182
|
+
hash[param] = _to_hash(value)
|
183
|
+
end
|
184
|
+
hash
|
185
|
+
end
|
186
|
+
|
187
|
+
# Outputs non-array value in the form of hash
|
188
|
+
# For object, use to_hash. Otherwise, just return the value
|
189
|
+
# @param [Object] value Any valid value
|
190
|
+
# @return [Hash] Returns the value in the form of hash
|
191
|
+
def _to_hash(value)
|
192
|
+
if value.is_a?(Array)
|
193
|
+
value.compact.map{ |v| _to_hash(v) }
|
194
|
+
elsif value.is_a?(Hash)
|
195
|
+
{}.tap do |hash|
|
196
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
197
|
+
end
|
198
|
+
elsif value.respond_to? :to_hash
|
199
|
+
value.to_hash
|
200
|
+
else
|
201
|
+
value
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
data/lib/pollster/version.rb
CHANGED
data/pollster.gemspec
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require
|
2
|
+
require "pollster/version"
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
|
-
s.name
|
7
|
-
s.version
|
8
|
-
s.platform
|
9
|
-
s.authors
|
10
|
-
s.email
|
11
|
-
s.homepage
|
12
|
-
s.summary
|
13
|
-
s.description = "
|
5
|
+
s.name = "pollster"
|
6
|
+
s.version = Pollster::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Adam Hooper"]
|
9
|
+
s.email = ["adam.hooper@huffingtonpost.com"]
|
10
|
+
s.homepage = "https://github.com/huffpostdata/ruby-pollster"
|
11
|
+
s.summary = "Pollster API Ruby Gem"
|
12
|
+
s.description = "Download election-related polling data from Pollster."
|
13
|
+
s.license = "CC-BY-NC-SA-3.0"
|
14
|
+
s.required_ruby_version = ">= 1.9"
|
14
15
|
|
15
|
-
s.
|
16
|
-
s.
|
16
|
+
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
|
17
|
+
s.add_runtime_dependency 'ruby-immutable-struct', '~> 1.0', '>= 1.0.1'
|
17
18
|
|
18
|
-
s.
|
19
|
-
|
20
|
-
s.
|
19
|
+
s.files = `find *`.split("\n").uniq.sort.select{|f| !f.empty? }
|
20
|
+
s.test_files = `find spec/*`.split("\n")
|
21
|
+
s.executables = []
|
22
|
+
s.require_paths = ["lib"]
|
21
23
|
end
|
22
|
-
|
metadata
CHANGED
@@ -1,92 +1,112 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pollster
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.2.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
9
|
-
- Aaron Bycoffe
|
10
|
-
- Andrei Scheinkman
|
6
|
+
authors:
|
7
|
+
- Adam Hooper
|
11
8
|
autorequire:
|
12
9
|
bindir: bin
|
13
10
|
cert_chain: []
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
date: 2017-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typhoeus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.1
|
23
|
+
type: :runtime
|
19
24
|
prerelease: false
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: ruby-immutable-struct
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
23
40
|
- - ">="
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
version:
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.0.1
|
26
43
|
type: :runtime
|
27
|
-
version_requirements: *id001
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: rdoc
|
30
44
|
prerelease: false
|
31
|
-
|
32
|
-
|
33
|
-
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.0'
|
34
50
|
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version:
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
email:
|
41
|
-
- jay.boice@huffingtonpost.com
|
42
|
-
- bycoffe@huffingtonpost.com
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.0.1
|
53
|
+
description: Download election-related polling data from Pollster.
|
54
|
+
email:
|
55
|
+
- adam.hooper@huffingtonpost.com
|
43
56
|
executables: []
|
44
|
-
|
45
57
|
extensions: []
|
46
|
-
|
47
58
|
extra_rdoc_files: []
|
48
|
-
|
49
|
-
files:
|
50
|
-
- .gitignore
|
51
|
-
- Gemfile
|
52
|
-
- Gemfile.lock
|
59
|
+
files:
|
53
60
|
- LICENSE
|
54
61
|
- README.md
|
55
|
-
-
|
62
|
+
- example.rb
|
56
63
|
- lib/pollster.rb
|
57
|
-
- lib/pollster/
|
58
|
-
- lib/pollster/
|
59
|
-
- lib/pollster/
|
60
|
-
- lib/pollster/
|
64
|
+
- lib/pollster/api.rb
|
65
|
+
- lib/pollster/api_client.rb
|
66
|
+
- lib/pollster/api_error.rb
|
67
|
+
- lib/pollster/configuration.rb
|
68
|
+
- lib/pollster/models/chart.rb
|
69
|
+
- lib/pollster/models/chart_estimate.rb
|
70
|
+
- lib/pollster/models/chart_estimate_lowess_parameters.rb
|
71
|
+
- lib/pollster/models/chart_pollster_estimate_summary.rb
|
72
|
+
- lib/pollster/models/chart_pollster_trendlines.rb
|
73
|
+
- lib/pollster/models/inline_response_200.rb
|
74
|
+
- lib/pollster/models/inline_response_200_3.rb
|
75
|
+
- lib/pollster/models/inline_response_200_4.rb
|
76
|
+
- lib/pollster/models/poll.rb
|
77
|
+
- lib/pollster/models/poll_question.rb
|
78
|
+
- lib/pollster/models/poll_question_responses.rb
|
79
|
+
- lib/pollster/models/poll_question_sample_subpopulations.rb
|
80
|
+
- lib/pollster/models/pollster_chart_poll_questions.rb
|
81
|
+
- lib/pollster/models/question.rb
|
82
|
+
- lib/pollster/models/question_poll_responses_clean.rb
|
83
|
+
- lib/pollster/models/question_poll_responses_raw.rb
|
84
|
+
- lib/pollster/models/question_responses.rb
|
85
|
+
- lib/pollster/models/tag.rb
|
61
86
|
- lib/pollster/version.rb
|
62
87
|
- pollster.gemspec
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
88
|
+
homepage: https://github.com/huffpostdata/ruby-pollster
|
89
|
+
licenses:
|
90
|
+
- CC-BY-NC-SA-3.0
|
91
|
+
metadata: {}
|
67
92
|
post_install_message:
|
68
93
|
rdoc_options: []
|
69
|
-
|
70
|
-
require_paths:
|
94
|
+
require_paths:
|
71
95
|
- lib
|
72
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
-
|
74
|
-
requirements:
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
75
98
|
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version:
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
|
80
|
-
requirements:
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '1.9'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
81
103
|
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version:
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
84
106
|
requirements: []
|
85
|
-
|
86
107
|
rubyforge_project:
|
87
|
-
rubygems_version:
|
108
|
+
rubygems_version: 2.6.8
|
88
109
|
signing_key:
|
89
|
-
specification_version:
|
90
|
-
summary:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Pollster API Ruby Gem
|
91
112
|
test_files: []
|
92
|
-
|
data/.gitignore
DELETED
data/Gemfile
DELETED