aylien_news_api 0.4.0 → 4.1.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 (160) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +7 -1
  3. data/README.md +117 -4
  4. data/Rakefile +10 -0
  5. data/aylien_news_api.gemspec +20 -28
  6. data/docs/Author.md +12 -1
  7. data/docs/Autocomplete.md +10 -0
  8. data/docs/Autocompletes.md +9 -0
  9. data/docs/Category.md +19 -3
  10. data/docs/CategoryLinks.md +11 -1
  11. data/docs/CategoryTaxonomy.md +16 -0
  12. data/docs/Cluster.md +29 -0
  13. data/docs/Clusters.md +21 -0
  14. data/docs/Coverages.md +16 -4
  15. data/docs/DefaultApi.md +1299 -826
  16. data/docs/Entities.md +11 -1
  17. data/docs/Entity.md +16 -3
  18. data/docs/EntityLinks.md +9 -0
  19. data/docs/Error.md +16 -2
  20. data/docs/ErrorLinks.md +11 -0
  21. data/docs/Errors.md +9 -0
  22. data/docs/HistogramInterval.md +10 -0
  23. data/docs/Histograms.md +20 -3
  24. data/docs/Location.md +13 -2
  25. data/docs/Media.md +18 -4
  26. data/docs/MediaFormat.md +16 -0
  27. data/docs/MediaType.md +16 -0
  28. data/docs/Rank.md +12 -1
  29. data/docs/Rankings.md +9 -0
  30. data/docs/RelatedStories.md +18 -3
  31. data/docs/RepresentativeStory.md +23 -0
  32. data/docs/Scope.md +15 -3
  33. data/docs/ScopeLevel.md +16 -0
  34. data/docs/Sentiment.md +11 -1
  35. data/docs/SentimentPolarity.md +16 -0
  36. data/docs/Sentiments.md +12 -2
  37. data/docs/ShareCount.md +10 -0
  38. data/docs/ShareCounts.md +12 -0
  39. data/docs/Source.md +27 -8
  40. data/docs/Stories.md +17 -2
  41. data/docs/Story.md +48 -16
  42. data/docs/StoryCluster.md +14 -1
  43. data/docs/StoryLinks.md +14 -1
  44. data/docs/StoryTranslation.md +19 -0
  45. data/docs/StoryTranslations.md +17 -0
  46. data/docs/StoryTranslationsEn.md +21 -0
  47. data/docs/Summary.md +9 -0
  48. data/docs/TimeSeries.md +11 -1
  49. data/docs/TimeSeriesList.md +15 -3
  50. data/docs/Trend.md +11 -1
  51. data/docs/Trends.md +15 -1
  52. data/docs/Warning.md +21 -0
  53. data/git_push.sh +58 -0
  54. data/lib/aylien_news_api.rb +22 -14
  55. data/lib/aylien_news_api/api/default_api.rb +2407 -1520
  56. data/lib/aylien_news_api/api_client.rb +137 -111
  57. data/lib/aylien_news_api/api_error.rb +37 -18
  58. data/lib/aylien_news_api/configuration.rb +74 -36
  59. data/lib/aylien_news_api/models/author.rb +66 -50
  60. data/lib/aylien_news_api/models/autocomplete.rb +52 -36
  61. data/lib/aylien_news_api/models/autocompletes.rb +51 -35
  62. data/lib/aylien_news_api/models/category.rb +85 -94
  63. data/lib/aylien_news_api/models/category_links.rb +63 -47
  64. data/lib/aylien_news_api/models/category_taxonomy.rb +36 -0
  65. data/lib/aylien_news_api/models/cluster.rb +265 -0
  66. data/lib/aylien_news_api/models/clusters.rb +229 -0
  67. data/lib/aylien_news_api/models/coverages.rb +76 -72
  68. data/lib/aylien_news_api/models/entities.rb +64 -48
  69. data/lib/aylien_news_api/models/entity.rb +93 -79
  70. data/lib/aylien_news_api/models/entity_links.rb +51 -35
  71. data/lib/aylien_news_api/models/error.rb +76 -60
  72. data/lib/aylien_news_api/models/error_links.rb +62 -37
  73. data/lib/aylien_news_api/models/errors.rb +51 -35
  74. data/lib/aylien_news_api/models/histogram_interval.rb +52 -36
  75. data/lib/aylien_news_api/models/histograms.rb +96 -60
  76. data/lib/aylien_news_api/models/location.rb +67 -51
  77. data/lib/aylien_news_api/models/media.rb +83 -114
  78. data/lib/aylien_news_api/models/media_format.rb +44 -0
  79. data/lib/aylien_news_api/models/media_type.rb +36 -0
  80. data/lib/aylien_news_api/models/rank.rb +64 -48
  81. data/lib/aylien_news_api/models/rankings.rb +51 -35
  82. data/lib/aylien_news_api/models/related_stories.rb +84 -60
  83. data/lib/aylien_news_api/models/representative_story.rb +237 -0
  84. data/lib/aylien_news_api/models/scope.rb +73 -91
  85. data/lib/aylien_news_api/models/scope_level.rb +37 -0
  86. data/lib/aylien_news_api/models/sentiment.rb +63 -82
  87. data/lib/aylien_news_api/models/sentiment_polarity.rb +37 -0
  88. data/lib/aylien_news_api/models/sentiments.rb +62 -48
  89. data/lib/aylien_news_api/models/share_count.rb +52 -36
  90. data/lib/aylien_news_api/models/share_counts.rb +54 -38
  91. data/lib/aylien_news_api/models/source.rb +111 -96
  92. data/lib/aylien_news_api/models/stories.rb +86 -50
  93. data/lib/aylien_news_api/models/story.rb +188 -158
  94. data/lib/aylien_news_api/models/story_cluster.rb +68 -52
  95. data/lib/aylien_news_api/models/story_links.rb +70 -44
  96. data/lib/aylien_news_api/models/story_translation.rb +217 -0
  97. data/lib/aylien_news_api/models/story_translations.rb +207 -0
  98. data/lib/aylien_news_api/models/story_translations_en.rb +227 -0
  99. data/lib/aylien_news_api/models/summary.rb +51 -35
  100. data/lib/aylien_news_api/models/time_series.rb +63 -47
  101. data/lib/aylien_news_api/models/time_series_list.rb +72 -56
  102. data/lib/aylien_news_api/models/trend.rb +63 -47
  103. data/lib/aylien_news_api/models/trends.rb +77 -41
  104. data/lib/aylien_news_api/models/warning.rb +226 -0
  105. data/lib/aylien_news_api/version.rb +12 -14
  106. data/spec/api/default_api_spec.rb +620 -284
  107. data/spec/api_client_spec.rb +43 -161
  108. data/spec/configuration_spec.rb +22 -19
  109. data/spec/models/author_spec.rb +21 -34
  110. data/spec/models/autocomplete_spec.rb +17 -26
  111. data/spec/models/autocompletes_spec.rb +16 -21
  112. data/spec/models/category_links_spec.rb +19 -28
  113. data/spec/models/category_spec.rb +31 -50
  114. data/spec/models/category_taxonomy_spec.rb +35 -0
  115. data/spec/models/cluster_spec.rb +77 -0
  116. data/spec/models/clusters_spec.rb +53 -0
  117. data/spec/models/coverages_spec.rb +24 -45
  118. data/spec/models/entities_spec.rb +19 -28
  119. data/spec/models/entity_links_spec.rb +16 -21
  120. data/spec/models/entity_spec.rb +25 -46
  121. data/spec/models/error_links_spec.rb +22 -21
  122. data/spec/models/error_spec.rb +27 -52
  123. data/spec/models/errors_spec.rb +16 -21
  124. data/spec/models/histogram_interval_spec.rb +17 -26
  125. data/spec/models/histograms_spec.rb +36 -45
  126. data/spec/models/location_spec.rb +21 -34
  127. data/spec/models/media_format_spec.rb +35 -0
  128. data/spec/models/media_spec.rb +41 -26
  129. data/spec/models/media_type_spec.rb +35 -0
  130. data/spec/models/rank_spec.rb +20 -21
  131. data/spec/models/rankings_spec.rb +15 -16
  132. data/spec/models/related_stories_spec.rb +33 -38
  133. data/spec/models/representative_story_spec.rb +59 -0
  134. data/spec/models/scope_level_spec.rb +35 -0
  135. data/spec/models/scope_spec.rb +23 -40
  136. data/spec/models/sentiment_polarity_spec.rb +35 -0
  137. data/spec/models/sentiment_spec.rb +17 -26
  138. data/spec/models/sentiments_spec.rb +19 -28
  139. data/spec/models/share_count_spec.rb +17 -26
  140. data/spec/models/share_counts_spec.rb +19 -36
  141. data/spec/models/source_spec.rb +54 -49
  142. data/spec/models/stories_spec.rb +32 -33
  143. data/spec/models/story_cluster_spec.rb +23 -44
  144. data/spec/models/story_links_spec.rb +25 -32
  145. data/spec/models/story_spec.rb +65 -134
  146. data/spec/models/story_translation_spec.rb +47 -0
  147. data/spec/models/story_translations_en_spec.rb +53 -0
  148. data/spec/models/story_translations_spec.rb +41 -0
  149. data/spec/models/summary_spec.rb +16 -21
  150. data/spec/models/time_series_list_spec.rb +22 -39
  151. data/spec/models/time_series_spec.rb +19 -28
  152. data/spec/models/trend_spec.rb +19 -28
  153. data/spec/models/trends_spec.rb +30 -27
  154. data/spec/models/warning_spec.rb +53 -0
  155. data/spec/spec_helper.rb +11 -13
  156. metadata +91 -192
  157. data/Gemfile.lock +0 -65
  158. data/LICENSE +0 -13
  159. data/aylien_news_api-0.2.0.gem +0 -0
  160. data/aylien_news_api-0.3.0.gem +0 -0
@@ -1,23 +1,20 @@
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.
1
+ =begin
2
+ #AYLIEN News API
3
+
4
+ #The AYLIEN News API is the most powerful way of sourcing, searching and syndicating analyzed and enriched news content. It is accessed by sending HTTP requests to our server, which returns information to your client.
5
+
6
+ The version of the OpenAPI document: 3.0
7
+ Contact: support@aylien.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.0.0-SNAPSHOT
10
+
11
+ =end
14
12
 
15
13
  require 'date'
16
14
  require 'json'
17
15
  require 'logger'
18
16
  require 'tempfile'
19
- require 'typhoeus'
20
- require 'uri'
17
+ require 'faraday'
21
18
 
22
19
  module AylienNewsApi
23
20
  class ApiClient
@@ -33,9 +30,9 @@ module AylienNewsApi
33
30
  # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
34
31
  def initialize(config = Configuration.default)
35
32
  @config = config
36
- @user_agent = "aylien-news-api/#{VERSION}/ruby"
33
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
37
34
  @default_headers = {
38
- 'Content-Type' => "application/json",
35
+ 'Content-Type' => 'application/json',
39
36
  'User-Agent' => @user_agent
40
37
  }
41
38
  end
@@ -46,29 +43,49 @@ module AylienNewsApi
46
43
 
47
44
  # Call an API with given options.
48
45
  #
49
- # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
46
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
50
47
  # the data deserialized from response body (could be nil), response status code and response headers.
51
48
  def call_api(http_method, path, opts = {})
52
- request = build_request(http_method, path, opts)
53
- response = request.run
49
+ ssl_options = {
50
+ :ca_file => @config.ssl_ca_file,
51
+ :verify => @config.ssl_verify,
52
+ :verify_mode => @config.ssl_verify_mode,
53
+ :client_cert => @config.ssl_client_cert,
54
+ :client_key => @config.ssl_client_key
55
+ }
54
56
 
55
- if @config.debugging
56
- @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
57
+ connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn|
58
+ conn.basic_auth(config.username, config.password)
59
+ if opts[:header_params]["Content-Type"] == "multipart/form-data"
60
+ conn.request :multipart
61
+ conn.request :url_encoded
62
+ end
63
+ conn.adapter(Faraday.default_adapter)
57
64
  end
58
65
 
59
- unless response.success?
60
- if response.timed_out?
61
- fail ApiError.new('Connection timed out')
62
- elsif response.code == 0
63
- # Errors from libcurl will be made visible here
64
- fail ApiError.new(:code => 0,
65
- :message => response.return_message)
66
- else
67
- fail ApiError.new(:code => response.code,
68
- :response_headers => response.headers,
69
- :response_body => response.body),
70
- response.status_message
66
+ begin
67
+ response = connection.public_send(http_method.to_sym.downcase) do |req|
68
+ build_request(http_method, path, req, opts)
69
+ end
70
+
71
+ if @config.debugging
72
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
71
73
  end
74
+
75
+ unless response.success?
76
+ if response.status == 0
77
+ # Errors from libcurl will be made visible here
78
+ fail ApiError.new(:code => 0,
79
+ :message => response.return_message)
80
+ else
81
+ fail ApiError.new(:code => response.status,
82
+ :response_headers => response.headers,
83
+ :response_body => response.body),
84
+ response.reason_phrase
85
+ end
86
+ end
87
+ rescue Faraday::TimeoutError
88
+ fail ApiError.new('Connection timed out')
72
89
  end
73
90
 
74
91
  if opts[:return_type]
@@ -76,7 +93,7 @@ module AylienNewsApi
76
93
  else
77
94
  data = nil
78
95
  end
79
- return data, response.code, response.headers
96
+ return data, response.status, response.headers
80
97
  end
81
98
 
82
99
  # Builds the HTTP request
@@ -88,7 +105,7 @@ module AylienNewsApi
88
105
  # @option opts [Hash] :form_params Query parameters
89
106
  # @option opts [Object] :body HTTP body (JSON/XML)
90
107
  # @return [Typhoeus::Request] A Typhoeus Request
91
- def build_request(http_method, path, opts = {})
108
+ def build_request(http_method, path, request, opts = {})
92
109
  url = build_request_url(path)
93
110
  http_method = http_method.to_sym.downcase
94
111
 
@@ -98,25 +115,15 @@ module AylienNewsApi
98
115
 
99
116
  update_params_for_auth! header_params, query_params, opts[:auth_names]
100
117
 
101
- # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
102
- _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
103
-
104
118
  req_opts = {
105
119
  :method => http_method,
106
120
  :headers => header_params,
107
121
  :params => query_params,
108
122
  :params_encoding => @config.params_encoding,
109
123
  :timeout => @config.timeout,
110
- :ssl_verifypeer => @config.verify_ssl,
111
- :ssl_verifyhost => _verify_ssl_host,
112
- :sslcert => @config.cert_file,
113
- :sslkey => @config.key_file,
114
124
  :verbose => @config.debugging
115
125
  }
116
126
 
117
- # set custom cert, if provided
118
- req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
119
-
120
127
  if [:post, :patch, :put, :delete].include?(http_method)
121
128
  req_body = build_request_body(header_params, form_params, opts[:body])
122
129
  req_opts.update :body => req_body
@@ -124,8 +131,44 @@ module AylienNewsApi
124
131
  @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
125
132
  end
126
133
  end
134
+ request.headers = header_params
135
+ request.body = req_body
136
+ request.url url
137
+ request.params = query_params
138
+ download_file(request) if opts[:return_type] == 'File'
139
+ request
140
+ end
127
141
 
128
- Typhoeus::Request.new(url, req_opts)
142
+ # Builds the HTTP request body
143
+ #
144
+ # @param [Hash] header_params Header parameters
145
+ # @param [Hash] form_params Query parameters
146
+ # @param [Object] body HTTP body (JSON/XML)
147
+ # @return [String] HTTP body data in the form of string
148
+ def build_request_body(header_params, form_params, body)
149
+ # http form
150
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
151
+ data = URI.encode_www_form(form_params)
152
+ elsif header_params['Content-Type'] == 'multipart/form-data'
153
+ data = {}
154
+ form_params.each do |key, value|
155
+ case value
156
+ when ::File, ::Tempfile
157
+ # TODO hardcode to application/octet-stream, need better way to detect content type
158
+ data[key] = Faraday::UploadIO.new(value.path, 'application/octet-stream', value.path)
159
+ when ::Array, nil
160
+ # let Faraday handle Array and nil parameters
161
+ data[key] = value
162
+ else
163
+ data[key] = value.to_s
164
+ end
165
+ end
166
+ elsif body
167
+ data = body.is_a?(String) ? body : body.to_json
168
+ else
169
+ data = nil
170
+ end
171
+ data
129
172
  end
130
173
 
131
174
  # Check if the given MIME is a JSON MIME.
@@ -133,26 +176,29 @@ module AylienNewsApi
133
176
  # application/json
134
177
  # application/json; charset=UTF8
135
178
  # APPLICATION/JSON
179
+ # */*
136
180
  # @param [String] mime MIME
137
181
  # @return [Boolean] True if the MIME is application/json
138
182
  def json_mime?(mime)
139
- !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
183
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
140
184
  end
141
185
 
142
186
  # Deserialize the response to the given return type.
143
187
  #
144
188
  # @param [Response] response HTTP response
145
- # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
189
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
146
190
  def deserialize(response, return_type)
147
191
  body = response.body
192
+
193
+ # handle file downloading - return the File instance processed in request callbacks
194
+ # note that response body is empty when the file is written in chunks in request on_body callback
195
+ return @tempfile if return_type == 'File'
196
+
148
197
  return nil if body.nil? || body.empty?
149
198
 
150
199
  # return response body directly for String return type
151
200
  return body if return_type == 'String'
152
201
 
153
- # handle file downloading - save response body into a tmp file and return the File instance
154
- return download_file(response) if return_type == 'File'
155
-
156
202
  # ensuring a default content type
157
203
  content_type = response.headers['Content-Type'] || 'application/json'
158
204
 
@@ -184,7 +230,7 @@ module AylienNewsApi
184
230
  data.to_i
185
231
  when 'Float'
186
232
  data.to_f
187
- when 'BOOLEAN'
233
+ when 'Boolean'
188
234
  data == true
189
235
  when 'DateTime'
190
236
  # parse date time (expecting ISO 8601 format)
@@ -198,47 +244,55 @@ module AylienNewsApi
198
244
  when /\AArray<(.+)>\z/
199
245
  # e.g. Array<Pet>
200
246
  sub_type = $1
201
- data.map {|item| convert_to_type(item, sub_type) }
247
+ data.map { |item| convert_to_type(item, sub_type) }
202
248
  when /\AHash\<String, (.+)\>\z/
203
249
  # e.g. Hash<String, Integer>
204
250
  sub_type = $1
205
251
  {}.tap do |hash|
206
- data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
252
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
207
253
  end
208
254
  else
209
255
  # models, e.g. Pet
210
- AylienNewsApi.const_get(return_type).new.tap do |model|
211
- model.build_from_hash data
212
- end
256
+ AylienNewsApi.const_get(return_type).build_from_hash(data)
213
257
  end
214
258
  end
215
259
 
216
260
  # Save response body into a file in (the defined) temporary folder, using the filename
217
261
  # from the "Content-Disposition" header if provided, otherwise a random filename.
262
+ # The response body is written to the file in chunks in order to handle files which
263
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
264
+ # process can use.
218
265
  #
219
266
  # @see Configuration#temp_folder_path
220
- # @return [Tempfile] the file downloaded
221
- def download_file(response)
222
- content_disposition = response.headers['Content-Disposition']
223
- if content_disposition and content_disposition =~ /filename=/i
224
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
225
- prefix = sanitize_filename(filename)
226
- else
227
- prefix = 'download-'
228
- end
229
- prefix = prefix + '-' unless prefix.end_with?('-')
230
-
267
+ def download_file(request)
231
268
  tempfile = nil
232
- encoding = response.body.encoding
233
- Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
234
- file.write(response.body)
235
- tempfile = file
269
+ encoding = nil
270
+ request.on_headers do |response|
271
+ content_disposition = response.headers['Content-Disposition']
272
+ if content_disposition && content_disposition =~ /filename=/i
273
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
274
+ prefix = sanitize_filename(filename)
275
+ else
276
+ prefix = 'download-'
277
+ end
278
+ prefix = prefix + '-' unless prefix.end_with?('-')
279
+ encoding = response.body.encoding
280
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
281
+ @tempfile = tempfile
282
+ end
283
+ request.on_body do |chunk|
284
+ chunk.force_encoding(encoding)
285
+ tempfile.write(chunk)
286
+ end
287
+ request.on_complete do |response|
288
+ if tempfile
289
+ tempfile.close
290
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
291
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
292
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
293
+ "explicitly with `tempfile.delete`"
294
+ end
236
295
  end
237
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
238
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
239
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
240
- "explicitly with `tempfile.delete`"
241
- tempfile
242
296
  end
243
297
 
244
298
  # Sanitize filename by removing path.
@@ -253,35 +307,7 @@ module AylienNewsApi
253
307
  def build_request_url(path)
254
308
  # Add leading and trailing slashes to path
255
309
  path = "/#{path}".gsub(/\/+/, '/')
256
- URI.encode(@config.base_url + path)
257
- end
258
-
259
- # Builds the HTTP request body
260
- #
261
- # @param [Hash] header_params Header parameters
262
- # @param [Hash] form_params Query parameters
263
- # @param [Object] body HTTP body (JSON/XML)
264
- # @return [String] HTTP body data in the form of string
265
- def build_request_body(header_params, form_params, body)
266
- # http form
267
- if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
268
- header_params['Content-Type'] == 'multipart/form-data'
269
- data = {}
270
- form_params.each do |key, value|
271
- case value
272
- when File, Array, nil
273
- # let typhoeus handle File, Array and nil parameters
274
- data[key] = value
275
- else
276
- data[key] = value.to_s
277
- end
278
- end
279
- elsif body
280
- data = body.is_a?(String) ? body : body.to_json
281
- else
282
- data = nil
283
- end
284
- data
310
+ @config.base_url + path
285
311
  end
286
312
 
287
313
  # Update hearder and query params based on authentication settings.
@@ -303,7 +329,7 @@ module AylienNewsApi
303
329
 
304
330
  # Sets user agent in HTTP header
305
331
  #
306
- # @param [String] user_agent User agent
332
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
307
333
  def user_agent=(user_agent)
308
334
  @user_agent = user_agent
309
335
  @default_headers['User-Agent'] = @user_agent
@@ -316,7 +342,7 @@ module AylienNewsApi
316
342
  return nil if accepts.nil? || accepts.empty?
317
343
  # use JSON when present, otherwise use all of the provided
318
344
  json_accept = accepts.find { |s| json_mime?(s) }
319
- return json_accept || accepts.join(',')
345
+ json_accept || accepts.join(',')
320
346
  end
321
347
 
322
348
  # Return Content-Type header based on an array of content types provided.
@@ -327,7 +353,7 @@ module AylienNewsApi
327
353
  return 'application/json' if content_types.nil? || content_types.empty?
328
354
  # use JSON when present, otherwise use the first one
329
355
  json_content_type = content_types.find { |s| json_mime?(s) }
330
- return json_content_type || content_types.first
356
+ json_content_type || content_types.first
331
357
  end
332
358
 
333
359
  # Convert object (array, hash, object, etc) to JSON string.
@@ -337,7 +363,7 @@ module AylienNewsApi
337
363
  return model if model.nil? || model.is_a?(String)
338
364
  local_body = nil
339
365
  if model.is_a?(Array)
340
- local_body = model.map{|m| object_to_hash(m) }
366
+ local_body = model.map { |m| object_to_hash(m) }
341
367
  else
342
368
  local_body = object_to_hash(model)
343
369
  end
@@ -1,16 +1,14 @@
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.
1
+ =begin
2
+ #AYLIEN News API
3
+
4
+ #The AYLIEN News API is the most powerful way of sourcing, searching and syndicating analyzed and enriched news content. It is accessed by sending HTTP requests to our server, which returns information to your client.
5
+
6
+ The version of the OpenAPI document: 3.0
7
+ Contact: support@aylien.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.0.0-SNAPSHOT
10
+
11
+ =end
14
12
 
15
13
  module AylienNewsApi
16
14
  class ApiError < StandardError
@@ -23,16 +21,37 @@ module AylienNewsApi
23
21
  # ApiError.new(:code => 404, :message => "Not Found")
24
22
  def initialize(arg = nil)
25
23
  if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
26
30
  arg.each do |k, v|
27
- if k.to_s == 'message'
28
- super v
29
- else
30
- instance_variable_set "@#{k}", v
31
- end
31
+ instance_variable_set "@#{k}", v
32
32
  end
33
33
  else
34
34
  super arg
35
35
  end
36
36
  end
37
+
38
+ # Override to_s to display a friendly error message
39
+ def to_s
40
+ message
41
+ end
42
+
43
+ def message
44
+ if @message.nil?
45
+ msg = "Error message: the server returns an error"
46
+ else
47
+ msg = @message
48
+ end
49
+
50
+ msg += "\nHTTP status code: #{code}" if code
51
+ msg += "\nResponse headers: #{response_headers}" if response_headers
52
+ msg += "\nResponse body: #{response_body}" if response_body
53
+
54
+ msg
55
+ end
37
56
  end
38
57
  end