aylien_news_api 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +5 -129
- data/aylien_news_api-0.2.0.gem +0 -0
- data/aylien_news_api.gemspec +2 -2
- data/docs/DefaultApi.md +60 -0
- data/docs/Rank.md +10 -0
- data/docs/Rankings.md +8 -0
- data/docs/Source.md +7 -2
- data/lib/aylien_news_api.rb +2 -0
- data/lib/aylien_news_api/api/default_api.rb +356 -4
- data/lib/aylien_news_api/api_client.rb +7 -2
- data/lib/aylien_news_api/configuration.rb +19 -6
- data/lib/aylien_news_api/models/entity.rb +13 -7
- data/lib/aylien_news_api/models/rank.rb +211 -0
- data/lib/aylien_news_api/models/rankings.rb +192 -0
- data/lib/aylien_news_api/models/sentiment.rb +13 -7
- data/lib/aylien_news_api/models/source.rb +56 -6
- data/lib/aylien_news_api/version.rb +1 -1
- data/spec/models/rank_spec.rb +54 -0
- data/spec/models/rankings_spec.rb +42 -0
- metadata +13 -4
@@ -30,7 +30,7 @@ module AylienNewsApi
|
|
30
30
|
attr_accessor :default_headers
|
31
31
|
|
32
32
|
# Initializes the ApiClient
|
33
|
-
# @option config [Configuration]
|
33
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
34
34
|
def initialize(config = Configuration.default)
|
35
35
|
@config = config
|
36
36
|
@user_agent = "aylien-news-api/#{VERSION}/ruby"
|
@@ -90,6 +90,9 @@ module AylienNewsApi
|
|
90
90
|
|
91
91
|
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
92
92
|
|
93
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
94
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
95
|
+
|
93
96
|
req_opts = {
|
94
97
|
:method => http_method,
|
95
98
|
:headers => header_params,
|
@@ -97,11 +100,13 @@ module AylienNewsApi
|
|
97
100
|
:params_encoding => @config.params_encoding,
|
98
101
|
:timeout => @config.timeout,
|
99
102
|
:ssl_verifypeer => @config.verify_ssl,
|
103
|
+
:ssl_verifyhost => _verify_ssl_host,
|
100
104
|
:sslcert => @config.cert_file,
|
101
105
|
:sslkey => @config.key_file,
|
102
106
|
:verbose => @config.debugging
|
103
107
|
}
|
104
108
|
|
109
|
+
# set custom cert, if provided
|
105
110
|
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
106
111
|
|
107
112
|
if [:post, :patch, :put, :delete].include?(http_method)
|
@@ -274,7 +279,7 @@ module AylienNewsApi
|
|
274
279
|
# Update hearder and query params based on authentication settings.
|
275
280
|
#
|
276
281
|
# @param [Hash] header_params Header parameters
|
277
|
-
# @param [Hash]
|
282
|
+
# @param [Hash] query_params Query parameters
|
278
283
|
# @param [String] auth_names Authentication scheme name
|
279
284
|
def update_params_for_auth!(header_params, query_params, auth_names)
|
280
285
|
Array(auth_names).each do |auth_name|
|
@@ -78,7 +78,7 @@ module AylienNewsApi
|
|
78
78
|
# Default to 0 (never times out).
|
79
79
|
attr_accessor :timeout
|
80
80
|
|
81
|
-
### TLS/SSL
|
81
|
+
### TLS/SSL setting
|
82
82
|
# Set this to false to skip verifying SSL certificate when calling API from https server.
|
83
83
|
# Default to true.
|
84
84
|
#
|
@@ -87,13 +87,16 @@ module AylienNewsApi
|
|
87
87
|
# @return [true, false]
|
88
88
|
attr_accessor :verify_ssl
|
89
89
|
|
90
|
-
|
91
|
-
#
|
90
|
+
### TLS/SSL setting
|
91
|
+
# Set this to false to skip verifying SSL host name
|
92
|
+
# Default to true.
|
92
93
|
#
|
93
|
-
# @
|
94
|
-
#
|
95
|
-
|
94
|
+
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
95
|
+
#
|
96
|
+
# @return [true, false]
|
97
|
+
attr_accessor :verify_ssl_host
|
96
98
|
|
99
|
+
### TLS/SSL setting
|
97
100
|
# Set this to customize the certificate file to verify the peer.
|
98
101
|
#
|
99
102
|
# @return [String] the path to the certificate file
|
@@ -102,12 +105,21 @@ module AylienNewsApi
|
|
102
105
|
# https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
|
103
106
|
attr_accessor :ssl_ca_cert
|
104
107
|
|
108
|
+
### TLS/SSL setting
|
105
109
|
# Client certificate file (for client certificate)
|
106
110
|
attr_accessor :cert_file
|
107
111
|
|
112
|
+
### TLS/SSL setting
|
108
113
|
# Client private key file (for client certificate)
|
109
114
|
attr_accessor :key_file
|
110
115
|
|
116
|
+
# Set this to customize parameters encoding of array parameter with multi collectionFormat.
|
117
|
+
# Default to nil.
|
118
|
+
#
|
119
|
+
# @see The params_encoding option of Ethon. Related source code:
|
120
|
+
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
|
121
|
+
attr_accessor :params_encoding
|
122
|
+
|
111
123
|
attr_accessor :inject_format
|
112
124
|
|
113
125
|
attr_accessor :force_ending_format
|
@@ -120,6 +132,7 @@ module AylienNewsApi
|
|
120
132
|
@api_key_prefix = {}
|
121
133
|
@timeout = 0
|
122
134
|
@verify_ssl = true
|
135
|
+
@verify_ssl_host = true
|
123
136
|
@params_encoding = :multi
|
124
137
|
@cert_file = nil
|
125
138
|
@key_file = nil
|
@@ -93,29 +93,35 @@ module AylienNewsApi
|
|
93
93
|
# @return Array for valid properies with the reasons
|
94
94
|
def list_invalid_properties
|
95
95
|
invalid_properties = Array.new
|
96
|
+
|
97
|
+
if !@score.nil? && @score > 1.0
|
98
|
+
invalid_properties.push("invalid value for 'score', must be smaller than or equal to 1.0.")
|
99
|
+
end
|
100
|
+
|
101
|
+
if !@score.nil? && @score < 0.0
|
102
|
+
invalid_properties.push("invalid value for 'score', must be greater than or equal to 0.0.")
|
103
|
+
end
|
104
|
+
|
96
105
|
return invalid_properties
|
97
106
|
end
|
98
107
|
|
99
108
|
# Check to see if the all the properties in the model are valid
|
100
109
|
# @return true if the model is valid
|
101
110
|
def valid?
|
102
|
-
return false if @score > 1.0
|
103
|
-
return false if @score < 0.0
|
111
|
+
return false if !@score.nil? && @score > 1.0
|
112
|
+
return false if !@score.nil? && @score < 0.0
|
104
113
|
return true
|
105
114
|
end
|
106
115
|
|
107
116
|
# Custom attribute writer method with validation
|
108
117
|
# @param [Object] score Value to be assigned
|
109
118
|
def score=(score)
|
110
|
-
if score.nil?
|
111
|
-
fail ArgumentError, "score cannot be nil"
|
112
|
-
end
|
113
119
|
|
114
|
-
if score > 1.0
|
120
|
+
if !score.nil? && score > 1.0
|
115
121
|
fail ArgumentError, "invalid value for 'score', must be smaller than or equal to 1.0."
|
116
122
|
end
|
117
123
|
|
118
|
-
if score < 0.0
|
124
|
+
if !score.nil? && score < 0.0
|
119
125
|
fail ArgumentError, "invalid value for 'score', must be greater than or equal to 0.0."
|
120
126
|
end
|
121
127
|
|
@@ -0,0 +1,211 @@
|
|
1
|
+
# Copyright 2016 Aylien, Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'date'
|
16
|
+
|
17
|
+
module AylienNewsApi
|
18
|
+
|
19
|
+
class Rank
|
20
|
+
# The rank
|
21
|
+
attr_accessor :rank
|
22
|
+
|
23
|
+
# The country code which the rank is in it
|
24
|
+
attr_accessor :country
|
25
|
+
|
26
|
+
# The fetched date of the rank
|
27
|
+
attr_accessor :fetched_at
|
28
|
+
|
29
|
+
|
30
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
31
|
+
def self.attribute_map
|
32
|
+
{
|
33
|
+
:'rank' => :'rank',
|
34
|
+
:'country' => :'country',
|
35
|
+
:'fetched_at' => :'fetched_at'
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# Attribute type mapping.
|
40
|
+
def self.api_types
|
41
|
+
{
|
42
|
+
:'rank' => :'Integer',
|
43
|
+
:'country' => :'String',
|
44
|
+
:'fetched_at' => :'DateTime'
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
# Initializes the object
|
49
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
50
|
+
def initialize(attributes = {})
|
51
|
+
return unless attributes.is_a?(Hash)
|
52
|
+
|
53
|
+
# convert string to symbol for hash key
|
54
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
55
|
+
|
56
|
+
if attributes.has_key?(:'rank')
|
57
|
+
self.rank = attributes[:'rank']
|
58
|
+
end
|
59
|
+
|
60
|
+
if attributes.has_key?(:'country')
|
61
|
+
self.country = attributes[:'country']
|
62
|
+
end
|
63
|
+
|
64
|
+
if attributes.has_key?(:'fetched_at')
|
65
|
+
self.fetched_at = attributes[:'fetched_at']
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
71
|
+
# @return Array for valid properies with the reasons
|
72
|
+
def list_invalid_properties
|
73
|
+
invalid_properties = Array.new
|
74
|
+
return invalid_properties
|
75
|
+
end
|
76
|
+
|
77
|
+
# Check to see if the all the properties in the model are valid
|
78
|
+
# @return true if the model is valid
|
79
|
+
def valid?
|
80
|
+
return true
|
81
|
+
end
|
82
|
+
|
83
|
+
# Checks equality by comparing each attribute.
|
84
|
+
# @param [Object] Object to be compared
|
85
|
+
def ==(o)
|
86
|
+
return true if self.equal?(o)
|
87
|
+
self.class == o.class &&
|
88
|
+
rank == o.rank &&
|
89
|
+
country == o.country &&
|
90
|
+
fetched_at == o.fetched_at
|
91
|
+
end
|
92
|
+
|
93
|
+
# @see the `==` method
|
94
|
+
# @param [Object] Object to be compared
|
95
|
+
def eql?(o)
|
96
|
+
self == o
|
97
|
+
end
|
98
|
+
|
99
|
+
# Calculates hash code according to all attributes.
|
100
|
+
# @return [Fixnum] Hash code
|
101
|
+
def hash
|
102
|
+
[rank, country, fetched_at].hash
|
103
|
+
end
|
104
|
+
|
105
|
+
# Builds the object from hash
|
106
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
107
|
+
# @return [Object] Returns the model itself
|
108
|
+
def build_from_hash(attributes)
|
109
|
+
return nil unless attributes.is_a?(Hash)
|
110
|
+
self.class.api_types.each_pair do |key, type|
|
111
|
+
if type =~ /^Array<(.*)>/i
|
112
|
+
# check to ensure the input is an array given that the the attribute
|
113
|
+
# is documented as an array but the input is not
|
114
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
115
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
116
|
+
end
|
117
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
118
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
119
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
120
|
+
end
|
121
|
+
|
122
|
+
self
|
123
|
+
end
|
124
|
+
|
125
|
+
# Deserializes the data based on type
|
126
|
+
# @param string type Data type
|
127
|
+
# @param string value Value to be deserialized
|
128
|
+
# @return [Object] Deserialized data
|
129
|
+
def _deserialize(type, value)
|
130
|
+
case type.to_sym
|
131
|
+
when :DateTime
|
132
|
+
DateTime.parse(value)
|
133
|
+
when :Date
|
134
|
+
Date.parse(value)
|
135
|
+
when :String
|
136
|
+
value.to_s
|
137
|
+
when :Integer
|
138
|
+
value.to_i
|
139
|
+
when :Float
|
140
|
+
value.to_f
|
141
|
+
when :BOOLEAN
|
142
|
+
if value.to_s =~ /^(true|t|yes|y|1)$/i
|
143
|
+
true
|
144
|
+
else
|
145
|
+
false
|
146
|
+
end
|
147
|
+
when :Object
|
148
|
+
# generic object (usually a Hash), return directly
|
149
|
+
value
|
150
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
151
|
+
inner_type = Regexp.last_match[:inner_type]
|
152
|
+
value.map { |v| _deserialize(inner_type, v) }
|
153
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
154
|
+
k_type = Regexp.last_match[:k_type]
|
155
|
+
v_type = Regexp.last_match[:v_type]
|
156
|
+
{}.tap do |hash|
|
157
|
+
value.each do |k, v|
|
158
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
else # model
|
162
|
+
temp_model = AylienNewsApi.const_get(type).new
|
163
|
+
temp_model.build_from_hash(value)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Returns the string representation of the object
|
168
|
+
# @return [String] String presentation of the object
|
169
|
+
def to_s
|
170
|
+
to_hash.to_s
|
171
|
+
end
|
172
|
+
|
173
|
+
# to_body is an alias to to_hash (backward compatibility)
|
174
|
+
# @return [Hash] Returns the object in the form of hash
|
175
|
+
def to_body
|
176
|
+
to_hash
|
177
|
+
end
|
178
|
+
|
179
|
+
# Returns the object in the form of hash
|
180
|
+
# @return [Hash] Returns the object in the form of hash
|
181
|
+
def to_hash
|
182
|
+
hash = {}
|
183
|
+
self.class.attribute_map.each_pair do |attr, param|
|
184
|
+
value = self.send(attr)
|
185
|
+
next if value.nil?
|
186
|
+
hash[param] = _to_hash(value)
|
187
|
+
end
|
188
|
+
hash
|
189
|
+
end
|
190
|
+
|
191
|
+
# Outputs non-array value in the form of hash
|
192
|
+
# For object, use to_hash. Otherwise, just return the value
|
193
|
+
# @param [Object] value Any valid value
|
194
|
+
# @return [Hash] Returns the value in the form of hash
|
195
|
+
def _to_hash(value)
|
196
|
+
if value.is_a?(Array)
|
197
|
+
value.compact.map{ |v| _to_hash(v) }
|
198
|
+
elsif value.is_a?(Hash)
|
199
|
+
{}.tap do |hash|
|
200
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
201
|
+
end
|
202
|
+
elsif value.respond_to? :to_hash
|
203
|
+
value.to_hash
|
204
|
+
else
|
205
|
+
value
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# Copyright 2016 Aylien, Inc. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'date'
|
16
|
+
|
17
|
+
module AylienNewsApi
|
18
|
+
|
19
|
+
class Rankings
|
20
|
+
attr_accessor :alexa
|
21
|
+
|
22
|
+
|
23
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
24
|
+
def self.attribute_map
|
25
|
+
{
|
26
|
+
:'alexa' => :'alexa'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
# Attribute type mapping.
|
31
|
+
def self.api_types
|
32
|
+
{
|
33
|
+
:'alexa' => :'Array<Rank>'
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
# Initializes the object
|
38
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
39
|
+
def initialize(attributes = {})
|
40
|
+
return unless attributes.is_a?(Hash)
|
41
|
+
|
42
|
+
# convert string to symbol for hash key
|
43
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
44
|
+
|
45
|
+
if attributes.has_key?(:'alexa')
|
46
|
+
if (value = attributes[:'alexa']).is_a?(Array)
|
47
|
+
self.alexa = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
54
|
+
# @return Array for valid properies with the reasons
|
55
|
+
def list_invalid_properties
|
56
|
+
invalid_properties = Array.new
|
57
|
+
return invalid_properties
|
58
|
+
end
|
59
|
+
|
60
|
+
# Check to see if the all the properties in the model are valid
|
61
|
+
# @return true if the model is valid
|
62
|
+
def valid?
|
63
|
+
return true
|
64
|
+
end
|
65
|
+
|
66
|
+
# Checks equality by comparing each attribute.
|
67
|
+
# @param [Object] Object to be compared
|
68
|
+
def ==(o)
|
69
|
+
return true if self.equal?(o)
|
70
|
+
self.class == o.class &&
|
71
|
+
alexa == o.alexa
|
72
|
+
end
|
73
|
+
|
74
|
+
# @see the `==` method
|
75
|
+
# @param [Object] Object to be compared
|
76
|
+
def eql?(o)
|
77
|
+
self == o
|
78
|
+
end
|
79
|
+
|
80
|
+
# Calculates hash code according to all attributes.
|
81
|
+
# @return [Fixnum] Hash code
|
82
|
+
def hash
|
83
|
+
[alexa].hash
|
84
|
+
end
|
85
|
+
|
86
|
+
# Builds the object from hash
|
87
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
88
|
+
# @return [Object] Returns the model itself
|
89
|
+
def build_from_hash(attributes)
|
90
|
+
return nil unless attributes.is_a?(Hash)
|
91
|
+
self.class.api_types.each_pair do |key, type|
|
92
|
+
if type =~ /^Array<(.*)>/i
|
93
|
+
# check to ensure the input is an array given that the the attribute
|
94
|
+
# is documented as an array but the input is not
|
95
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
96
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
97
|
+
end
|
98
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
99
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
100
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
101
|
+
end
|
102
|
+
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
# Deserializes the data based on type
|
107
|
+
# @param string type Data type
|
108
|
+
# @param string value Value to be deserialized
|
109
|
+
# @return [Object] Deserialized data
|
110
|
+
def _deserialize(type, value)
|
111
|
+
case type.to_sym
|
112
|
+
when :DateTime
|
113
|
+
DateTime.parse(value)
|
114
|
+
when :Date
|
115
|
+
Date.parse(value)
|
116
|
+
when :String
|
117
|
+
value.to_s
|
118
|
+
when :Integer
|
119
|
+
value.to_i
|
120
|
+
when :Float
|
121
|
+
value.to_f
|
122
|
+
when :BOOLEAN
|
123
|
+
if value.to_s =~ /^(true|t|yes|y|1)$/i
|
124
|
+
true
|
125
|
+
else
|
126
|
+
false
|
127
|
+
end
|
128
|
+
when :Object
|
129
|
+
# generic object (usually a Hash), return directly
|
130
|
+
value
|
131
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
132
|
+
inner_type = Regexp.last_match[:inner_type]
|
133
|
+
value.map { |v| _deserialize(inner_type, v) }
|
134
|
+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
|
135
|
+
k_type = Regexp.last_match[:k_type]
|
136
|
+
v_type = Regexp.last_match[:v_type]
|
137
|
+
{}.tap do |hash|
|
138
|
+
value.each do |k, v|
|
139
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
else # model
|
143
|
+
temp_model = AylienNewsApi.const_get(type).new
|
144
|
+
temp_model.build_from_hash(value)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Returns the string representation of the object
|
149
|
+
# @return [String] String presentation of the object
|
150
|
+
def to_s
|
151
|
+
to_hash.to_s
|
152
|
+
end
|
153
|
+
|
154
|
+
# to_body is an alias to to_hash (backward compatibility)
|
155
|
+
# @return [Hash] Returns the object in the form of hash
|
156
|
+
def to_body
|
157
|
+
to_hash
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns the object in the form of hash
|
161
|
+
# @return [Hash] Returns the object in the form of hash
|
162
|
+
def to_hash
|
163
|
+
hash = {}
|
164
|
+
self.class.attribute_map.each_pair do |attr, param|
|
165
|
+
value = self.send(attr)
|
166
|
+
next if value.nil?
|
167
|
+
hash[param] = _to_hash(value)
|
168
|
+
end
|
169
|
+
hash
|
170
|
+
end
|
171
|
+
|
172
|
+
# Outputs non-array value in the form of hash
|
173
|
+
# For object, use to_hash. Otherwise, just return the value
|
174
|
+
# @param [Object] value Any valid value
|
175
|
+
# @return [Hash] Returns the value in the form of hash
|
176
|
+
def _to_hash(value)
|
177
|
+
if value.is_a?(Array)
|
178
|
+
value.compact.map{ |v| _to_hash(v) }
|
179
|
+
elsif value.is_a?(Hash)
|
180
|
+
{}.tap do |hash|
|
181
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
182
|
+
end
|
183
|
+
elsif value.respond_to? :to_hash
|
184
|
+
value.to_hash
|
185
|
+
else
|
186
|
+
value
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|