backscatterio 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/LICENSE +201 -0
  4. data/README.md +120 -0
  5. data/Rakefile +8 -0
  6. data/backscatterio.gemspec +45 -0
  7. data/docs/ASNEnrichment.md +9 -0
  8. data/docs/ASNEnrichmentResults.md +11 -0
  9. data/docs/Api.md +339 -0
  10. data/docs/Hello.md +9 -0
  11. data/docs/IPEnrichment.md +9 -0
  12. data/docs/IPEnrichmentResults.md +25 -0
  13. data/docs/NetworkEnrichment.md +9 -0
  14. data/docs/NetworkEnrichmentResults.md +10 -0
  15. data/docs/Observation.md +21 -0
  16. data/docs/Observations.md +10 -0
  17. data/docs/Query.md +11 -0
  18. data/docs/Results.md +10 -0
  19. data/docs/Summary.md +15 -0
  20. data/docs/Trends.md +10 -0
  21. data/docs/Unique.md +13 -0
  22. data/git_push.sh +55 -0
  23. data/lib/backscatterio.rb +54 -0
  24. data/lib/backscatterio/api/default_api.rb +349 -0
  25. data/lib/backscatterio/api_client.rb +389 -0
  26. data/lib/backscatterio/api_error.rb +38 -0
  27. data/lib/backscatterio/configuration.rb +209 -0
  28. data/lib/backscatterio/models/asn_enrichment.rb +192 -0
  29. data/lib/backscatterio/models/asn_enrichment_results.rb +212 -0
  30. data/lib/backscatterio/models/hello.rb +192 -0
  31. data/lib/backscatterio/models/ip_enrichment.rb +192 -0
  32. data/lib/backscatterio/models/ip_enrichment_results.rb +336 -0
  33. data/lib/backscatterio/models/network_enrichment.rb +192 -0
  34. data/lib/backscatterio/models/network_enrichment_results.rb +203 -0
  35. data/lib/backscatterio/models/observation.rb +300 -0
  36. data/lib/backscatterio/models/observations.rb +201 -0
  37. data/lib/backscatterio/models/query.rb +244 -0
  38. data/lib/backscatterio/models/results.rb +203 -0
  39. data/lib/backscatterio/models/summary.rb +248 -0
  40. data/lib/backscatterio/models/trends.rb +201 -0
  41. data/lib/backscatterio/models/unique.rb +240 -0
  42. data/lib/backscatterio/version.rb +15 -0
  43. data/spec/api/default_api_spec.rb +107 -0
  44. data/spec/api_client_spec.rb +226 -0
  45. data/spec/configuration_spec.rb +42 -0
  46. data/spec/models/asn_enrichment_results_spec.rb +59 -0
  47. data/spec/models/asn_enrichment_spec.rb +47 -0
  48. data/spec/models/hello_spec.rb +47 -0
  49. data/spec/models/ip_enrichment_results_spec.rb +143 -0
  50. data/spec/models/ip_enrichment_spec.rb +47 -0
  51. data/spec/models/network_enrichment_results_spec.rb +53 -0
  52. data/spec/models/network_enrichment_spec.rb +47 -0
  53. data/spec/models/observation_spec.rb +119 -0
  54. data/spec/models/observations_spec.rb +53 -0
  55. data/spec/models/query_spec.rb +63 -0
  56. data/spec/models/results_spec.rb +53 -0
  57. data/spec/models/summary_spec.rb +83 -0
  58. data/spec/models/trends_spec.rb +53 -0
  59. data/spec/models/unique_spec.rb +71 -0
  60. data/spec/spec_helper.rb +111 -0
  61. metadata +301 -0
@@ -0,0 +1,248 @@
1
+ =begin
2
+ #Backscatter.io
3
+
4
+ #[This is the Backscatter.io API.](https://backscatter.io/developers)
5
+
6
+ OpenAPI spec version: 1.0.0
7
+ Contact: info@backscatter.io
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module BackscatterIO
16
+ class Summary
17
+ attr_accessor :autonomous_system_count
18
+
19
+ attr_accessor :has_observations
20
+
21
+ attr_accessor :ip_address_count
22
+
23
+ attr_accessor :network_count
24
+
25
+ attr_accessor :observations
26
+
27
+ attr_accessor :observations_count
28
+
29
+ attr_accessor :port_count
30
+
31
+ attr_accessor :protocol_count
32
+
33
+ # Attribute mapping from ruby-style variable name to JSON key.
34
+ def self.attribute_map
35
+ {
36
+ :'autonomous_system_count' => :'autonomous_system_count',
37
+ :'has_observations' => :'has_observations',
38
+ :'ip_address_count' => :'ip_address_count',
39
+ :'network_count' => :'network_count',
40
+ :'observations' => :'observations',
41
+ :'observations_count' => :'observations_count',
42
+ :'port_count' => :'port_count',
43
+ :'protocol_count' => :'protocol_count'
44
+ }
45
+ end
46
+
47
+ # Attribute type mapping.
48
+ def self.swagger_types
49
+ {
50
+ :'autonomous_system_count' => :'Integer',
51
+ :'has_observations' => :'BOOLEAN',
52
+ :'ip_address_count' => :'Array<String>',
53
+ :'network_count' => :'Integer',
54
+ :'observations' => :'BOOLEAN',
55
+ :'observations_count' => :'Integer',
56
+ :'port_count' => :'Integer',
57
+ :'protocol_count' => :'Integer'
58
+ }
59
+ end
60
+
61
+ # Initializes the object
62
+ # @param [Hash] attributes Model attributes in the form of hash
63
+ def initialize(attributes = {})
64
+ return unless attributes.is_a?(Hash)
65
+
66
+ # convert string to symbol for hash key
67
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
68
+
69
+ if attributes.has_key?(:'autonomous_system_count')
70
+ self.autonomous_system_count = attributes[:'autonomous_system_count']
71
+ end
72
+
73
+ if attributes.has_key?(:'has_observations')
74
+ self.has_observations = attributes[:'has_observations']
75
+ end
76
+
77
+ if attributes.has_key?(:'ip_address_count')
78
+ if (value = attributes[:'ip_address_count']).is_a?(Array)
79
+ self.ip_address_count = value
80
+ end
81
+ end
82
+
83
+ if attributes.has_key?(:'network_count')
84
+ self.network_count = attributes[:'network_count']
85
+ end
86
+
87
+ if attributes.has_key?(:'observations')
88
+ self.observations = attributes[:'observations']
89
+ end
90
+
91
+ if attributes.has_key?(:'observations_count')
92
+ self.observations_count = attributes[:'observations_count']
93
+ end
94
+
95
+ if attributes.has_key?(:'port_count')
96
+ self.port_count = attributes[:'port_count']
97
+ end
98
+
99
+ if attributes.has_key?(:'protocol_count')
100
+ self.protocol_count = attributes[:'protocol_count']
101
+ end
102
+ end
103
+
104
+ # Show invalid properties with the reasons. Usually used together with valid?
105
+ # @return Array for valid properties with the reasons
106
+ def list_invalid_properties
107
+ invalid_properties = Array.new
108
+ invalid_properties
109
+ end
110
+
111
+ # Check to see if the all the properties in the model are valid
112
+ # @return true if the model is valid
113
+ def valid?
114
+ true
115
+ end
116
+
117
+ # Checks equality by comparing each attribute.
118
+ # @param [Object] Object to be compared
119
+ def ==(o)
120
+ return true if self.equal?(o)
121
+ self.class == o.class &&
122
+ autonomous_system_count == o.autonomous_system_count &&
123
+ has_observations == o.has_observations &&
124
+ ip_address_count == o.ip_address_count &&
125
+ network_count == o.network_count &&
126
+ observations == o.observations &&
127
+ observations_count == o.observations_count &&
128
+ port_count == o.port_count &&
129
+ protocol_count == o.protocol_count
130
+ end
131
+
132
+ # @see the `==` method
133
+ # @param [Object] Object to be compared
134
+ def eql?(o)
135
+ self == o
136
+ end
137
+
138
+ # Calculates hash code according to all attributes.
139
+ # @return [Fixnum] Hash code
140
+ def hash
141
+ [autonomous_system_count, has_observations, ip_address_count, network_count, observations, observations_count, port_count, protocol_count].hash
142
+ end
143
+
144
+ # Builds the object from hash
145
+ # @param [Hash] attributes Model attributes in the form of hash
146
+ # @return [Object] Returns the model itself
147
+ def build_from_hash(attributes)
148
+ return nil unless attributes.is_a?(Hash)
149
+ self.class.swagger_types.each_pair do |key, type|
150
+ if type =~ /\AArray<(.*)>/i
151
+ # check to ensure the input is an array given that the the attribute
152
+ # is documented as an array but the input is not
153
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
154
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
155
+ end
156
+ elsif !attributes[self.class.attribute_map[key]].nil?
157
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
158
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
159
+ end
160
+
161
+ self
162
+ end
163
+
164
+ # Deserializes the data based on type
165
+ # @param string type Data type
166
+ # @param string value Value to be deserialized
167
+ # @return [Object] Deserialized data
168
+ def _deserialize(type, value)
169
+ case type.to_sym
170
+ when :DateTime
171
+ DateTime.parse(value)
172
+ when :Date
173
+ Date.parse(value)
174
+ when :String
175
+ value.to_s
176
+ when :Integer
177
+ value.to_i
178
+ when :Float
179
+ value.to_f
180
+ when :BOOLEAN
181
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
182
+ true
183
+ else
184
+ false
185
+ end
186
+ when :Object
187
+ # generic object (usually a Hash), return directly
188
+ value
189
+ when /\AArray<(?<inner_type>.+)>\z/
190
+ inner_type = Regexp.last_match[:inner_type]
191
+ value.map { |v| _deserialize(inner_type, v) }
192
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
193
+ k_type = Regexp.last_match[:k_type]
194
+ v_type = Regexp.last_match[:v_type]
195
+ {}.tap do |hash|
196
+ value.each do |k, v|
197
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
198
+ end
199
+ end
200
+ else # model
201
+ temp_model = BackscatterIO.const_get(type).new
202
+ temp_model.build_from_hash(value)
203
+ end
204
+ end
205
+
206
+ # Returns the string representation of the object
207
+ # @return [String] String presentation of the object
208
+ def to_s
209
+ to_hash.to_s
210
+ end
211
+
212
+ # to_body is an alias to to_hash (backward compatibility)
213
+ # @return [Hash] Returns the object in the form of hash
214
+ def to_body
215
+ to_hash
216
+ end
217
+
218
+ # Returns the object in the form of hash
219
+ # @return [Hash] Returns the object in the form of hash
220
+ def to_hash
221
+ hash = {}
222
+ self.class.attribute_map.each_pair do |attr, param|
223
+ value = self.send(attr)
224
+ next if value.nil?
225
+ hash[param] = _to_hash(value)
226
+ end
227
+ hash
228
+ end
229
+
230
+ # Outputs non-array value in the form of hash
231
+ # For object, use to_hash. Otherwise, just return the value
232
+ # @param [Object] value Any valid value
233
+ # @return [Hash] Returns the value in the form of hash
234
+ def _to_hash(value)
235
+ if value.is_a?(Array)
236
+ value.compact.map { |v| _to_hash(v) }
237
+ elsif value.is_a?(Hash)
238
+ {}.tap do |hash|
239
+ value.each { |k, v| hash[k] = _to_hash(v) }
240
+ end
241
+ elsif value.respond_to? :to_hash
242
+ value.to_hash
243
+ else
244
+ value
245
+ end
246
+ end
247
+ end
248
+ end
@@ -0,0 +1,201 @@
1
+ =begin
2
+ #Backscatter.io
3
+
4
+ #[This is the Backscatter.io API.](https://backscatter.io/developers)
5
+
6
+ OpenAPI spec version: 1.0.0
7
+ Contact: info@backscatter.io
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module BackscatterIO
16
+ class Trends
17
+ attr_accessor :query
18
+
19
+ attr_accessor :results
20
+
21
+ attr_accessor :success
22
+
23
+ # Attribute mapping from ruby-style variable name to JSON key.
24
+ def self.attribute_map
25
+ {
26
+ :'query' => :'query',
27
+ :'results' => :'results',
28
+ :'success' => :'success'
29
+ }
30
+ end
31
+
32
+ # Attribute type mapping.
33
+ def self.swagger_types
34
+ {
35
+ :'query' => :'Query',
36
+ :'results' => :'Object',
37
+ :'success' => :'BOOLEAN'
38
+ }
39
+ end
40
+
41
+ # Initializes the object
42
+ # @param [Hash] attributes Model attributes in the form of hash
43
+ def initialize(attributes = {})
44
+ return unless attributes.is_a?(Hash)
45
+
46
+ # convert string to symbol for hash key
47
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
48
+
49
+ if attributes.has_key?(:'query')
50
+ self.query = attributes[:'query']
51
+ end
52
+
53
+ if attributes.has_key?(:'results')
54
+ self.results = attributes[:'results']
55
+ end
56
+
57
+ if attributes.has_key?(:'success')
58
+ self.success = attributes[:'success']
59
+ end
60
+ end
61
+
62
+ # Show invalid properties with the reasons. Usually used together with valid?
63
+ # @return Array for valid properties with the reasons
64
+ def list_invalid_properties
65
+ invalid_properties = Array.new
66
+ invalid_properties
67
+ end
68
+
69
+ # Check to see if the all the properties in the model are valid
70
+ # @return true if the model is valid
71
+ def valid?
72
+ true
73
+ end
74
+
75
+ # Checks equality by comparing each attribute.
76
+ # @param [Object] Object to be compared
77
+ def ==(o)
78
+ return true if self.equal?(o)
79
+ self.class == o.class &&
80
+ query == o.query &&
81
+ results == o.results &&
82
+ success == o.success
83
+ end
84
+
85
+ # @see the `==` method
86
+ # @param [Object] Object to be compared
87
+ def eql?(o)
88
+ self == o
89
+ end
90
+
91
+ # Calculates hash code according to all attributes.
92
+ # @return [Fixnum] Hash code
93
+ def hash
94
+ [query, results, success].hash
95
+ end
96
+
97
+ # Builds the object from hash
98
+ # @param [Hash] attributes Model attributes in the form of hash
99
+ # @return [Object] Returns the model itself
100
+ def build_from_hash(attributes)
101
+ return nil unless attributes.is_a?(Hash)
102
+ self.class.swagger_types.each_pair do |key, type|
103
+ if type =~ /\AArray<(.*)>/i
104
+ # check to ensure the input is an array given that the the attribute
105
+ # is documented as an array but the input is not
106
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
107
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
108
+ end
109
+ elsif !attributes[self.class.attribute_map[key]].nil?
110
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
111
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
112
+ end
113
+
114
+ self
115
+ end
116
+
117
+ # Deserializes the data based on type
118
+ # @param string type Data type
119
+ # @param string value Value to be deserialized
120
+ # @return [Object] Deserialized data
121
+ def _deserialize(type, value)
122
+ case type.to_sym
123
+ when :DateTime
124
+ DateTime.parse(value)
125
+ when :Date
126
+ Date.parse(value)
127
+ when :String
128
+ value.to_s
129
+ when :Integer
130
+ value.to_i
131
+ when :Float
132
+ value.to_f
133
+ when :BOOLEAN
134
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
135
+ true
136
+ else
137
+ false
138
+ end
139
+ when :Object
140
+ # generic object (usually a Hash), return directly
141
+ value
142
+ when /\AArray<(?<inner_type>.+)>\z/
143
+ inner_type = Regexp.last_match[:inner_type]
144
+ value.map { |v| _deserialize(inner_type, v) }
145
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
146
+ k_type = Regexp.last_match[:k_type]
147
+ v_type = Regexp.last_match[:v_type]
148
+ {}.tap do |hash|
149
+ value.each do |k, v|
150
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
151
+ end
152
+ end
153
+ else # model
154
+ temp_model = BackscatterIO.const_get(type).new
155
+ temp_model.build_from_hash(value)
156
+ end
157
+ end
158
+
159
+ # Returns the string representation of the object
160
+ # @return [String] String presentation of the object
161
+ def to_s
162
+ to_hash.to_s
163
+ end
164
+
165
+ # to_body is an alias to to_hash (backward compatibility)
166
+ # @return [Hash] Returns the object in the form of hash
167
+ def to_body
168
+ to_hash
169
+ end
170
+
171
+ # Returns the object in the form of hash
172
+ # @return [Hash] Returns the object in the form of hash
173
+ def to_hash
174
+ hash = {}
175
+ self.class.attribute_map.each_pair do |attr, param|
176
+ value = self.send(attr)
177
+ next if value.nil?
178
+ hash[param] = _to_hash(value)
179
+ end
180
+ hash
181
+ end
182
+
183
+ # Outputs non-array value in the form of hash
184
+ # For object, use to_hash. Otherwise, just return the value
185
+ # @param [Object] value Any valid value
186
+ # @return [Hash] Returns the value in the form of hash
187
+ def _to_hash(value)
188
+ if value.is_a?(Array)
189
+ value.compact.map { |v| _to_hash(v) }
190
+ elsif value.is_a?(Hash)
191
+ {}.tap do |hash|
192
+ value.each { |k, v| hash[k] = _to_hash(v) }
193
+ end
194
+ elsif value.respond_to? :to_hash
195
+ value.to_hash
196
+ else
197
+ value
198
+ end
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,240 @@
1
+ =begin
2
+ #Backscatter.io
3
+
4
+ #[This is the Backscatter.io API.](https://backscatter.io/developers)
5
+
6
+ OpenAPI spec version: 1.0.0
7
+ Contact: info@backscatter.io
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module BackscatterIO
16
+ class Unique
17
+ attr_accessor :autonomous_systems
18
+
19
+ attr_accessor :countries
20
+
21
+ attr_accessor :ip_addresses
22
+
23
+ attr_accessor :networks
24
+
25
+ attr_accessor :ports
26
+
27
+ attr_accessor :protocols
28
+
29
+ # Attribute mapping from ruby-style variable name to JSON key.
30
+ def self.attribute_map
31
+ {
32
+ :'autonomous_systems' => :'autonomous_systems',
33
+ :'countries' => :'countries',
34
+ :'ip_addresses' => :'ip_addresses',
35
+ :'networks' => :'networks',
36
+ :'ports' => :'ports',
37
+ :'protocols' => :'protocols'
38
+ }
39
+ end
40
+
41
+ # Attribute type mapping.
42
+ def self.swagger_types
43
+ {
44
+ :'autonomous_systems' => :'Array<String>',
45
+ :'countries' => :'Array<String>',
46
+ :'ip_addresses' => :'Array<String>',
47
+ :'networks' => :'Array<String>',
48
+ :'ports' => :'Array<String>',
49
+ :'protocols' => :'Array<String>'
50
+ }
51
+ end
52
+
53
+ # Initializes the object
54
+ # @param [Hash] attributes Model attributes in the form of hash
55
+ def initialize(attributes = {})
56
+ return unless attributes.is_a?(Hash)
57
+
58
+ # convert string to symbol for hash key
59
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
60
+
61
+ if attributes.has_key?(:'autonomous_systems')
62
+ if (value = attributes[:'autonomous_systems']).is_a?(Array)
63
+ self.autonomous_systems = value
64
+ end
65
+ end
66
+
67
+ if attributes.has_key?(:'countries')
68
+ if (value = attributes[:'countries']).is_a?(Array)
69
+ self.countries = value
70
+ end
71
+ end
72
+
73
+ if attributes.has_key?(:'ip_addresses')
74
+ if (value = attributes[:'ip_addresses']).is_a?(Array)
75
+ self.ip_addresses = value
76
+ end
77
+ end
78
+
79
+ if attributes.has_key?(:'networks')
80
+ if (value = attributes[:'networks']).is_a?(Array)
81
+ self.networks = value
82
+ end
83
+ end
84
+
85
+ if attributes.has_key?(:'ports')
86
+ if (value = attributes[:'ports']).is_a?(Array)
87
+ self.ports = value
88
+ end
89
+ end
90
+
91
+ if attributes.has_key?(:'protocols')
92
+ if (value = attributes[:'protocols']).is_a?(Array)
93
+ self.protocols = value
94
+ end
95
+ end
96
+ end
97
+
98
+ # Show invalid properties with the reasons. Usually used together with valid?
99
+ # @return Array for valid properties with the reasons
100
+ def list_invalid_properties
101
+ invalid_properties = Array.new
102
+ invalid_properties
103
+ end
104
+
105
+ # Check to see if the all the properties in the model are valid
106
+ # @return true if the model is valid
107
+ def valid?
108
+ true
109
+ end
110
+
111
+ # Checks equality by comparing each attribute.
112
+ # @param [Object] Object to be compared
113
+ def ==(o)
114
+ return true if self.equal?(o)
115
+ self.class == o.class &&
116
+ autonomous_systems == o.autonomous_systems &&
117
+ countries == o.countries &&
118
+ ip_addresses == o.ip_addresses &&
119
+ networks == o.networks &&
120
+ ports == o.ports &&
121
+ protocols == o.protocols
122
+ end
123
+
124
+ # @see the `==` method
125
+ # @param [Object] Object to be compared
126
+ def eql?(o)
127
+ self == o
128
+ end
129
+
130
+ # Calculates hash code according to all attributes.
131
+ # @return [Fixnum] Hash code
132
+ def hash
133
+ [autonomous_systems, countries, ip_addresses, networks, ports, protocols].hash
134
+ end
135
+
136
+ # Builds the object from hash
137
+ # @param [Hash] attributes Model attributes in the form of hash
138
+ # @return [Object] Returns the model itself
139
+ def build_from_hash(attributes)
140
+ return nil unless attributes.is_a?(Hash)
141
+ self.class.swagger_types.each_pair do |key, type|
142
+ if type =~ /\AArray<(.*)>/i
143
+ # check to ensure the input is an array given that the the attribute
144
+ # is documented as an array but the input is not
145
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
146
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
147
+ end
148
+ elsif !attributes[self.class.attribute_map[key]].nil?
149
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
150
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
151
+ end
152
+
153
+ self
154
+ end
155
+
156
+ # Deserializes the data based on type
157
+ # @param string type Data type
158
+ # @param string value Value to be deserialized
159
+ # @return [Object] Deserialized data
160
+ def _deserialize(type, value)
161
+ case type.to_sym
162
+ when :DateTime
163
+ DateTime.parse(value)
164
+ when :Date
165
+ Date.parse(value)
166
+ when :String
167
+ value.to_s
168
+ when :Integer
169
+ value.to_i
170
+ when :Float
171
+ value.to_f
172
+ when :BOOLEAN
173
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
174
+ true
175
+ else
176
+ false
177
+ end
178
+ when :Object
179
+ # generic object (usually a Hash), return directly
180
+ value
181
+ when /\AArray<(?<inner_type>.+)>\z/
182
+ inner_type = Regexp.last_match[:inner_type]
183
+ value.map { |v| _deserialize(inner_type, v) }
184
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
185
+ k_type = Regexp.last_match[:k_type]
186
+ v_type = Regexp.last_match[:v_type]
187
+ {}.tap do |hash|
188
+ value.each do |k, v|
189
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
190
+ end
191
+ end
192
+ else # model
193
+ temp_model = BackscatterIO.const_get(type).new
194
+ temp_model.build_from_hash(value)
195
+ end
196
+ end
197
+
198
+ # Returns the string representation of the object
199
+ # @return [String] String presentation of the object
200
+ def to_s
201
+ to_hash.to_s
202
+ end
203
+
204
+ # to_body is an alias to to_hash (backward compatibility)
205
+ # @return [Hash] Returns the object in the form of hash
206
+ def to_body
207
+ to_hash
208
+ end
209
+
210
+ # Returns the object in the form of hash
211
+ # @return [Hash] Returns the object in the form of hash
212
+ def to_hash
213
+ hash = {}
214
+ self.class.attribute_map.each_pair do |attr, param|
215
+ value = self.send(attr)
216
+ next if value.nil?
217
+ hash[param] = _to_hash(value)
218
+ end
219
+ hash
220
+ end
221
+
222
+ # Outputs non-array value in the form of hash
223
+ # For object, use to_hash. Otherwise, just return the value
224
+ # @param [Object] value Any valid value
225
+ # @return [Hash] Returns the value in the form of hash
226
+ def _to_hash(value)
227
+ if value.is_a?(Array)
228
+ value.compact.map { |v| _to_hash(v) }
229
+ elsif value.is_a?(Hash)
230
+ {}.tap do |hash|
231
+ value.each { |k, v| hash[k] = _to_hash(v) }
232
+ end
233
+ elsif value.respond_to? :to_hash
234
+ value.to_hash
235
+ else
236
+ value
237
+ end
238
+ end
239
+ end
240
+ end