aylien_news_api 0.0.1

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.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +67 -0
  4. data/LICENSE +13 -0
  5. data/README.md +133 -0
  6. data/Rakefile +8 -0
  7. data/aylien_news_api.gemspec +33 -0
  8. data/docs/Author.md +10 -0
  9. data/docs/Autocomplete.md +9 -0
  10. data/docs/Autocompletes.md +8 -0
  11. data/docs/Category.md +13 -0
  12. data/docs/CategoryLinks.md +9 -0
  13. data/docs/Coverages.md +12 -0
  14. data/docs/DefaultApi.md +829 -0
  15. data/docs/Entities.md +9 -0
  16. data/docs/Entity.md +12 -0
  17. data/docs/EntityLinks.md +8 -0
  18. data/docs/Error.md +13 -0
  19. data/docs/ErrorLinks.md +8 -0
  20. data/docs/Errors.md +8 -0
  21. data/docs/HistogramInterval.md +9 -0
  22. data/docs/Histograms.md +12 -0
  23. data/docs/Location.md +10 -0
  24. data/docs/Media.md +9 -0
  25. data/docs/RelatedStories.md +11 -0
  26. data/docs/Scope.md +11 -0
  27. data/docs/Sentiment.md +9 -0
  28. data/docs/Sentiments.md +9 -0
  29. data/docs/ShareCount.md +9 -0
  30. data/docs/ShareCounts.md +11 -0
  31. data/docs/Source.md +13 -0
  32. data/docs/Stories.md +10 -0
  33. data/docs/Story.md +27 -0
  34. data/docs/StoryCluster.md +12 -0
  35. data/docs/StoryLinks.md +10 -0
  36. data/docs/Summary.md +8 -0
  37. data/docs/TimeSeries.md +9 -0
  38. data/docs/TimeSeriesList.md +11 -0
  39. data/docs/Trend.md +9 -0
  40. data/docs/Trends.md +9 -0
  41. data/lib/aylien_news_api.rb +74 -0
  42. data/lib/aylien_news_api/api/default_api.rb +1171 -0
  43. data/lib/aylien_news_api/api_client.rb +365 -0
  44. data/lib/aylien_news_api/api_error.rb +38 -0
  45. data/lib/aylien_news_api/configuration.rb +191 -0
  46. data/lib/aylien_news_api/models/author.rb +192 -0
  47. data/lib/aylien_news_api/models/autocomplete.rb +183 -0
  48. data/lib/aylien_news_api/models/autocompletes.rb +176 -0
  49. data/lib/aylien_news_api/models/category.rb +229 -0
  50. data/lib/aylien_news_api/models/category_links.rb +183 -0
  51. data/lib/aylien_news_api/models/coverages.rb +212 -0
  52. data/lib/aylien_news_api/models/entities.rb +187 -0
  53. data/lib/aylien_news_api/models/entity.rb +214 -0
  54. data/lib/aylien_news_api/models/entity_links.rb +174 -0
  55. data/lib/aylien_news_api/models/error.rb +213 -0
  56. data/lib/aylien_news_api/models/error_links.rb +173 -0
  57. data/lib/aylien_news_api/models/errors.rb +175 -0
  58. data/lib/aylien_news_api/models/histogram_interval.rb +183 -0
  59. data/lib/aylien_news_api/models/histograms.rb +211 -0
  60. data/lib/aylien_news_api/models/location.rb +192 -0
  61. data/lib/aylien_news_api/models/media.rb +193 -0
  62. data/lib/aylien_news_api/models/related_stories.rb +203 -0
  63. data/lib/aylien_news_api/models/scope.rb +211 -0
  64. data/lib/aylien_news_api/models/sentiment.rb +193 -0
  65. data/lib/aylien_news_api/models/sentiments.rb +183 -0
  66. data/lib/aylien_news_api/models/share_count.rb +183 -0
  67. data/lib/aylien_news_api/models/share_counts.rb +209 -0
  68. data/lib/aylien_news_api/models/source.rb +223 -0
  69. data/lib/aylien_news_api/models/stories.rb +196 -0
  70. data/lib/aylien_news_api/models/story.rb +353 -0
  71. data/lib/aylien_news_api/models/story_cluster.rb +214 -0
  72. data/lib/aylien_news_api/models/story_links.rb +192 -0
  73. data/lib/aylien_news_api/models/summary.rb +176 -0
  74. data/lib/aylien_news_api/models/time_series.rb +183 -0
  75. data/lib/aylien_news_api/models/time_series_list.rb +203 -0
  76. data/lib/aylien_news_api/models/trend.rb +183 -0
  77. data/lib/aylien_news_api/models/trends.rb +185 -0
  78. data/lib/aylien_news_api/version.rb +17 -0
  79. data/spec/api/default_api_spec.rb +357 -0
  80. data/spec/models/author_spec.rb +66 -0
  81. data/spec/models/autocomplete_spec.rb +56 -0
  82. data/spec/models/autocompletes_spec.rb +46 -0
  83. data/spec/models/category_links_spec.rb +56 -0
  84. data/spec/models/category_spec.rb +96 -0
  85. data/spec/models/coverages_spec.rb +86 -0
  86. data/spec/models/entities_spec.rb +56 -0
  87. data/spec/models/entity_links_spec.rb +46 -0
  88. data/spec/models/entity_spec.rb +86 -0
  89. data/spec/models/error_links_spec.rb +46 -0
  90. data/spec/models/error_spec.rb +96 -0
  91. data/spec/models/errors_spec.rb +46 -0
  92. data/spec/models/histogram_interval_spec.rb +56 -0
  93. data/spec/models/histograms_spec.rb +86 -0
  94. data/spec/models/location_spec.rb +66 -0
  95. data/spec/models/media_spec.rb +56 -0
  96. data/spec/models/related_stories_spec.rb +76 -0
  97. data/spec/models/scope_spec.rb +76 -0
  98. data/spec/models/sentiment_spec.rb +56 -0
  99. data/spec/models/sentiments_spec.rb +56 -0
  100. data/spec/models/share_count_spec.rb +56 -0
  101. data/spec/models/share_counts_spec.rb +76 -0
  102. data/spec/models/source_spec.rb +96 -0
  103. data/spec/models/stories_spec.rb +66 -0
  104. data/spec/models/story_cluster_spec.rb +86 -0
  105. data/spec/models/story_links_spec.rb +66 -0
  106. data/spec/models/story_spec.rb +236 -0
  107. data/spec/models/summary_spec.rb +46 -0
  108. data/spec/models/time_series_list_spec.rb +76 -0
  109. data/spec/models/time_series_spec.rb +56 -0
  110. data/spec/models/trend_spec.rb +56 -0
  111. data/spec/models/trends_spec.rb +56 -0
  112. metadata +391 -0
@@ -0,0 +1,229 @@
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
+ class Category
19
+ # The ID of the category
20
+ attr_accessor :id
21
+
22
+ # The taxonomy of the category
23
+ attr_accessor :taxonomy
24
+
25
+ # The level of the category
26
+ attr_accessor :level
27
+
28
+ # The score of the category
29
+ attr_accessor :score
30
+
31
+ # It defines whether the extracted category is confident or not
32
+ attr_accessor :confident
33
+
34
+ # Related links for the category
35
+ attr_accessor :links
36
+
37
+ # Attribute mapping from ruby-style variable name to JSON key.
38
+ def self.attribute_map
39
+ {
40
+ :'id' => :'id',
41
+ :'taxonomy' => :'taxonomy',
42
+ :'level' => :'level',
43
+ :'score' => :'score',
44
+ :'confident' => :'confident',
45
+ :'links' => :'links'
46
+ }
47
+ end
48
+
49
+ # Attribute type mapping.
50
+ def self.api_types
51
+ {
52
+ :'id' => :'String',
53
+ :'taxonomy' => :'String',
54
+ :'level' => :'Integer',
55
+ :'score' => :'Float',
56
+ :'confident' => :'BOOLEAN',
57
+ :'links' => :'CategoryLinks'
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[:'id']
70
+ self.id = attributes[:'id']
71
+ end
72
+ if attributes[:'taxonomy']
73
+ self.taxonomy = attributes[:'taxonomy']
74
+ end
75
+ if attributes[:'level']
76
+ self.level = attributes[:'level']
77
+ end
78
+ if attributes[:'score']
79
+ self.score = attributes[:'score']
80
+ end
81
+ if attributes[:'confident']
82
+ self.confident = attributes[:'confident']
83
+ end
84
+ if attributes[:'links']
85
+ self.links = attributes[:'links']
86
+ end
87
+ end
88
+
89
+ # Custom attribute writer method checking allowed values (enum).
90
+ # @param [Object] taxonomy Object to be assigned
91
+ def taxonomy=(taxonomy)
92
+ allowed_values = ["iab-qag", "iptc-subjectcode"]
93
+ if taxonomy && !allowed_values.include?(taxonomy)
94
+ fail "invalid value for 'taxonomy', must be one of #{allowed_values}"
95
+ end
96
+ @taxonomy = taxonomy
97
+ end
98
+
99
+ # Checks equality by comparing each attribute.
100
+ # @param [Object] Object to be compared
101
+ def ==(o)
102
+ return true if self.equal?(o)
103
+ self.class == o.class &&
104
+ id == o.id &&
105
+ taxonomy == o.taxonomy &&
106
+ level == o.level &&
107
+ score == o.score &&
108
+ confident == o.confident &&
109
+ links == o.links
110
+ end
111
+
112
+ # @see the `==` method
113
+ # @param [Object] Object to be compared
114
+ def eql?(o)
115
+ self == o
116
+ end
117
+
118
+ # Calculates hash code according to all attributes.
119
+ # @return [Fixnum] Hash code
120
+ def hash
121
+ [id, taxonomy, level, score, confident, links].hash
122
+ end
123
+
124
+ # Builds the object from hash
125
+ # @param [Hash] attributes Model attributes in the form of hash
126
+ # @return [Object] Returns the model itself
127
+ def build_from_hash(attributes)
128
+ return nil unless attributes.is_a?(Hash)
129
+ self.class.api_types.each_pair do |key, type|
130
+ if type =~ /^Array<(.*)>/i
131
+ # check to ensure the input is an array given that the the attribute
132
+ # is documented as an array but the input is not
133
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
134
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
135
+ end
136
+ elsif !attributes[self.class.attribute_map[key]].nil?
137
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
138
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
139
+ end
140
+
141
+ self
142
+ end
143
+
144
+ # Deserializes the data based on type
145
+ # @param string type Data type
146
+ # @param string value Value to be deserialized
147
+ # @return [Object] Deserialized data
148
+ def _deserialize(type, value)
149
+ case type.to_sym
150
+ when :DateTime
151
+ DateTime.parse(value)
152
+ when :Date
153
+ Date.parse(value)
154
+ when :String
155
+ value.to_s
156
+ when :Integer
157
+ value.to_i
158
+ when :Float
159
+ value.to_f
160
+ when :BOOLEAN
161
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
162
+ true
163
+ else
164
+ false
165
+ end
166
+ when :Object
167
+ # generic object (usually a Hash), return directly
168
+ value
169
+ when /\AArray<(?<inner_type>.+)>\z/
170
+ inner_type = Regexp.last_match[:inner_type]
171
+ value.map { |v| _deserialize(inner_type, v) }
172
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
173
+ k_type = Regexp.last_match[:k_type]
174
+ v_type = Regexp.last_match[:v_type]
175
+ {}.tap do |hash|
176
+ value.each do |k, v|
177
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
178
+ end
179
+ end
180
+ else # model
181
+ temp_model = AylienNewsApi.const_get(type).new
182
+ temp_model.build_from_hash(value)
183
+ end
184
+ end
185
+
186
+ # Returns the string representation of the object
187
+ # @return [String] String presentation of the object
188
+ def to_s
189
+ to_hash.to_s
190
+ end
191
+
192
+ # to_body is an alias to to_hash (backward compatibility)
193
+ # @return [Hash] Returns the object in the form of hash
194
+ def to_body
195
+ to_hash
196
+ end
197
+
198
+ # Returns the object in the form of hash
199
+ # @return [Hash] Returns the object in the form of hash
200
+ def to_hash
201
+ hash = {}
202
+ self.class.attribute_map.each_pair do |attr, param|
203
+ value = self.send(attr)
204
+ next if value.nil?
205
+ hash[param] = _to_hash(value)
206
+ end
207
+ hash
208
+ end
209
+
210
+ # Outputs non-array value in the form of hash
211
+ # For object, use to_hash. Otherwise, just return the value
212
+ # @param [Object] value Any valid value
213
+ # @return [Hash] Returns the value in the form of hash
214
+ def _to_hash(value)
215
+ if value.is_a?(Array)
216
+ value.compact.map{ |v| _to_hash(v) }
217
+ elsif value.is_a?(Hash)
218
+ {}.tap do |hash|
219
+ value.each { |k, v| hash[k] = _to_hash(v) }
220
+ end
221
+ elsif value.respond_to? :to_hash
222
+ value.to_hash
223
+ else
224
+ value
225
+ end
226
+ end
227
+
228
+ end
229
+ end
@@ -0,0 +1,183 @@
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
+ class CategoryLinks
19
+ # A URL points to the category
20
+ attr_accessor :_self
21
+
22
+ # A URL points to the parent category
23
+ attr_accessor :parent
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :'_self' => :'self',
29
+ :'parent' => :'parent'
30
+ }
31
+ end
32
+
33
+ # Attribute type mapping.
34
+ def self.api_types
35
+ {
36
+ :'_self' => :'String',
37
+ :'parent' => :'String'
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[:'self']
50
+ self._self = attributes[:'self']
51
+ end
52
+ if attributes[:'parent']
53
+ self.parent = attributes[:'parent']
54
+ end
55
+ end
56
+
57
+ # Checks equality by comparing each attribute.
58
+ # @param [Object] Object to be compared
59
+ def ==(o)
60
+ return true if self.equal?(o)
61
+ self.class == o.class &&
62
+ _self == o._self &&
63
+ parent == o.parent
64
+ end
65
+
66
+ # @see the `==` method
67
+ # @param [Object] Object to be compared
68
+ def eql?(o)
69
+ self == o
70
+ end
71
+
72
+ # Calculates hash code according to all attributes.
73
+ # @return [Fixnum] Hash code
74
+ def hash
75
+ [_self, parent].hash
76
+ end
77
+
78
+ # Builds the object from hash
79
+ # @param [Hash] attributes Model attributes in the form of hash
80
+ # @return [Object] Returns the model itself
81
+ def build_from_hash(attributes)
82
+ return nil unless attributes.is_a?(Hash)
83
+ self.class.api_types.each_pair do |key, type|
84
+ if type =~ /^Array<(.*)>/i
85
+ # check to ensure the input is an array given that the the attribute
86
+ # is documented as an array but the input is not
87
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
88
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
89
+ end
90
+ elsif !attributes[self.class.attribute_map[key]].nil?
91
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
92
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
93
+ end
94
+
95
+ self
96
+ end
97
+
98
+ # Deserializes the data based on type
99
+ # @param string type Data type
100
+ # @param string value Value to be deserialized
101
+ # @return [Object] Deserialized data
102
+ def _deserialize(type, value)
103
+ case type.to_sym
104
+ when :DateTime
105
+ DateTime.parse(value)
106
+ when :Date
107
+ Date.parse(value)
108
+ when :String
109
+ value.to_s
110
+ when :Integer
111
+ value.to_i
112
+ when :Float
113
+ value.to_f
114
+ when :BOOLEAN
115
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
116
+ true
117
+ else
118
+ false
119
+ end
120
+ when :Object
121
+ # generic object (usually a Hash), return directly
122
+ value
123
+ when /\AArray<(?<inner_type>.+)>\z/
124
+ inner_type = Regexp.last_match[:inner_type]
125
+ value.map { |v| _deserialize(inner_type, v) }
126
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
127
+ k_type = Regexp.last_match[:k_type]
128
+ v_type = Regexp.last_match[:v_type]
129
+ {}.tap do |hash|
130
+ value.each do |k, v|
131
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
132
+ end
133
+ end
134
+ else # model
135
+ temp_model = AylienNewsApi.const_get(type).new
136
+ temp_model.build_from_hash(value)
137
+ end
138
+ end
139
+
140
+ # Returns the string representation of the object
141
+ # @return [String] String presentation of the object
142
+ def to_s
143
+ to_hash.to_s
144
+ end
145
+
146
+ # to_body is an alias to to_hash (backward compatibility)
147
+ # @return [Hash] Returns the object in the form of hash
148
+ def to_body
149
+ to_hash
150
+ end
151
+
152
+ # Returns the object in the form of hash
153
+ # @return [Hash] Returns the object in the form of hash
154
+ def to_hash
155
+ hash = {}
156
+ self.class.attribute_map.each_pair do |attr, param|
157
+ value = self.send(attr)
158
+ next if value.nil?
159
+ hash[param] = _to_hash(value)
160
+ end
161
+ hash
162
+ end
163
+
164
+ # Outputs non-array value in the form of hash
165
+ # For object, use to_hash. Otherwise, just return the value
166
+ # @param [Object] value Any valid value
167
+ # @return [Hash] Returns the value in the form of hash
168
+ def _to_hash(value)
169
+ if value.is_a?(Array)
170
+ value.compact.map{ |v| _to_hash(v) }
171
+ elsif value.is_a?(Hash)
172
+ {}.tap do |hash|
173
+ value.each { |k, v| hash[k] = _to_hash(v) }
174
+ end
175
+ elsif value.respond_to? :to_hash
176
+ value.to_hash
177
+ else
178
+ value
179
+ end
180
+ end
181
+
182
+ end
183
+ end
@@ -0,0 +1,212 @@
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
+ class Coverages
19
+ # The input story title
20
+ attr_accessor :story_title
21
+
22
+ # The input story body
23
+ attr_accessor :story_body
24
+
25
+ # The input story published date
26
+ attr_accessor :story_published_at
27
+
28
+ # The input story language
29
+ attr_accessor :story_language
30
+
31
+ # An array of coverages for the input story
32
+ attr_accessor :coverages
33
+
34
+ # Attribute mapping from ruby-style variable name to JSON key.
35
+ def self.attribute_map
36
+ {
37
+ :'story_title' => :'story_title',
38
+ :'story_body' => :'story_body',
39
+ :'story_published_at' => :'story_published_at',
40
+ :'story_language' => :'story_language',
41
+ :'coverages' => :'coverages'
42
+ }
43
+ end
44
+
45
+ # Attribute type mapping.
46
+ def self.api_types
47
+ {
48
+ :'story_title' => :'String',
49
+ :'story_body' => :'String',
50
+ :'story_published_at' => :'DateTime',
51
+ :'story_language' => :'String',
52
+ :'coverages' => :'Array<Story>'
53
+ }
54
+ end
55
+
56
+ # Initializes the object
57
+ # @param [Hash] attributes Model attributes in the form of hash
58
+ def initialize(attributes = {})
59
+ return unless attributes.is_a?(Hash)
60
+
61
+ # convert string to symbol for hash key
62
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
63
+
64
+ if attributes[:'story_title']
65
+ self.story_title = attributes[:'story_title']
66
+ end
67
+ if attributes[:'story_body']
68
+ self.story_body = attributes[:'story_body']
69
+ end
70
+ if attributes[:'story_published_at']
71
+ self.story_published_at = attributes[:'story_published_at']
72
+ end
73
+ if attributes[:'story_language']
74
+ self.story_language = attributes[:'story_language']
75
+ end
76
+ if attributes[:'coverages']
77
+ if (value = attributes[:'coverages']).is_a?(Array)
78
+ self.coverages = value
79
+ end
80
+ end
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
+ story_title == o.story_title &&
89
+ story_body == o.story_body &&
90
+ story_published_at == o.story_published_at &&
91
+ story_language == o.story_language &&
92
+ coverages == o.coverages
93
+ end
94
+
95
+ # @see the `==` method
96
+ # @param [Object] Object to be compared
97
+ def eql?(o)
98
+ self == o
99
+ end
100
+
101
+ # Calculates hash code according to all attributes.
102
+ # @return [Fixnum] Hash code
103
+ def hash
104
+ [story_title, story_body, story_published_at, story_language, coverages].hash
105
+ end
106
+
107
+ # Builds the object from hash
108
+ # @param [Hash] attributes Model attributes in the form of hash
109
+ # @return [Object] Returns the model itself
110
+ def build_from_hash(attributes)
111
+ return nil unless attributes.is_a?(Hash)
112
+ self.class.api_types.each_pair do |key, type|
113
+ if type =~ /^Array<(.*)>/i
114
+ # check to ensure the input is an array given that the the attribute
115
+ # is documented as an array but the input is not
116
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
117
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
118
+ end
119
+ elsif !attributes[self.class.attribute_map[key]].nil?
120
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
121
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
122
+ end
123
+
124
+ self
125
+ end
126
+
127
+ # Deserializes the data based on type
128
+ # @param string type Data type
129
+ # @param string value Value to be deserialized
130
+ # @return [Object] Deserialized data
131
+ def _deserialize(type, value)
132
+ case type.to_sym
133
+ when :DateTime
134
+ DateTime.parse(value)
135
+ when :Date
136
+ Date.parse(value)
137
+ when :String
138
+ value.to_s
139
+ when :Integer
140
+ value.to_i
141
+ when :Float
142
+ value.to_f
143
+ when :BOOLEAN
144
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
145
+ true
146
+ else
147
+ false
148
+ end
149
+ when :Object
150
+ # generic object (usually a Hash), return directly
151
+ value
152
+ when /\AArray<(?<inner_type>.+)>\z/
153
+ inner_type = Regexp.last_match[:inner_type]
154
+ value.map { |v| _deserialize(inner_type, v) }
155
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
156
+ k_type = Regexp.last_match[:k_type]
157
+ v_type = Regexp.last_match[:v_type]
158
+ {}.tap do |hash|
159
+ value.each do |k, v|
160
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
161
+ end
162
+ end
163
+ else # model
164
+ temp_model = AylienNewsApi.const_get(type).new
165
+ temp_model.build_from_hash(value)
166
+ end
167
+ end
168
+
169
+ # Returns the string representation of the object
170
+ # @return [String] String presentation of the object
171
+ def to_s
172
+ to_hash.to_s
173
+ end
174
+
175
+ # to_body is an alias to to_hash (backward compatibility)
176
+ # @return [Hash] Returns the object in the form of hash
177
+ def to_body
178
+ to_hash
179
+ end
180
+
181
+ # Returns the object in the form of hash
182
+ # @return [Hash] Returns the object in the form of hash
183
+ def to_hash
184
+ hash = {}
185
+ self.class.attribute_map.each_pair do |attr, param|
186
+ value = self.send(attr)
187
+ next if value.nil?
188
+ hash[param] = _to_hash(value)
189
+ end
190
+ hash
191
+ end
192
+
193
+ # Outputs non-array value in the form of hash
194
+ # For object, use to_hash. Otherwise, just return the value
195
+ # @param [Object] value Any valid value
196
+ # @return [Hash] Returns the value in the form of hash
197
+ def _to_hash(value)
198
+ if value.is_a?(Array)
199
+ value.compact.map{ |v| _to_hash(v) }
200
+ elsif value.is_a?(Hash)
201
+ {}.tap do |hash|
202
+ value.each { |k, v| hash[k] = _to_hash(v) }
203
+ end
204
+ elsif value.respond_to? :to_hash
205
+ value.to_hash
206
+ else
207
+ value
208
+ end
209
+ end
210
+
211
+ end
212
+ end