aylien_news_api 1.0.0 → 3.0.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.
Files changed (135) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +6 -0
  3. data/README.md +117 -4
  4. data/Rakefile +2 -0
  5. data/aylien_news_api.gemspec +16 -27
  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 +17 -3
  10. data/docs/CategoryLinks.md +11 -1
  11. data/docs/Cluster.md +29 -0
  12. data/docs/Clusters.md +21 -0
  13. data/docs/Coverages.md +16 -4
  14. data/docs/DefaultApi.md +1250 -1117
  15. data/docs/Entities.md +11 -1
  16. data/docs/Entity.md +16 -3
  17. data/docs/EntityLinks.md +9 -0
  18. data/docs/Error.md +16 -2
  19. data/docs/ErrorLinks.md +9 -0
  20. data/docs/Errors.md +9 -0
  21. data/docs/HistogramInterval.md +10 -0
  22. data/docs/Histograms.md +16 -3
  23. data/docs/Location.md +13 -2
  24. data/docs/Media.md +17 -3
  25. data/docs/Rank.md +12 -1
  26. data/docs/Rankings.md +9 -0
  27. data/docs/RelatedStories.md +14 -3
  28. data/docs/RepresentativeStory.md +23 -0
  29. data/docs/Scope.md +14 -2
  30. data/docs/Sentiment.md +10 -0
  31. data/docs/Sentiments.md +12 -2
  32. data/docs/ShareCount.md +10 -0
  33. data/docs/ShareCounts.md +12 -0
  34. data/docs/Source.md +27 -8
  35. data/docs/Stories.md +11 -2
  36. data/docs/Story.md +48 -16
  37. data/docs/StoryCluster.md +14 -1
  38. data/docs/StoryLinks.md +14 -2
  39. data/docs/StoryTranslations.md +17 -0
  40. data/docs/StoryTranslationsEn.md +21 -0
  41. data/docs/Summary.md +9 -0
  42. data/docs/TimeSeries.md +11 -1
  43. data/docs/TimeSeriesList.md +15 -3
  44. data/docs/Trend.md +11 -1
  45. data/docs/Trends.md +11 -1
  46. data/git_push.sh +58 -0
  47. data/lib/aylien_news_api.rb +11 -10
  48. data/lib/aylien_news_api/api/default_api.rb +2065 -1801
  49. data/lib/aylien_news_api/api_client.rb +129 -108
  50. data/lib/aylien_news_api/api_error.rb +25 -10
  51. data/lib/aylien_news_api/configuration.rb +69 -33
  52. data/lib/aylien_news_api/models/author.rb +50 -46
  53. data/lib/aylien_news_api/models/autocomplete.rb +36 -32
  54. data/lib/aylien_news_api/models/autocompletes.rb +35 -31
  55. data/lib/aylien_news_api/models/category.rb +63 -59
  56. data/lib/aylien_news_api/models/category_links.rb +47 -43
  57. data/lib/aylien_news_api/models/cluster.rb +255 -0
  58. data/lib/aylien_news_api/models/clusters.rb +219 -0
  59. data/lib/aylien_news_api/models/coverages.rb +60 -68
  60. data/lib/aylien_news_api/models/entities.rb +48 -44
  61. data/lib/aylien_news_api/models/entity.rb +71 -69
  62. data/lib/aylien_news_api/models/entity_links.rb +35 -31
  63. data/lib/aylien_news_api/models/error.rb +60 -56
  64. data/lib/aylien_news_api/models/error_links.rb +35 -31
  65. data/lib/aylien_news_api/models/errors.rb +35 -31
  66. data/lib/aylien_news_api/models/histogram_interval.rb +36 -32
  67. data/lib/aylien_news_api/models/histograms.rb +62 -58
  68. data/lib/aylien_news_api/models/location.rb +51 -47
  69. data/lib/aylien_news_api/models/media.rb +81 -76
  70. data/lib/aylien_news_api/models/rank.rb +48 -44
  71. data/lib/aylien_news_api/models/rankings.rb +35 -31
  72. data/lib/aylien_news_api/models/related_stories.rb +53 -61
  73. data/lib/aylien_news_api/models/representative_story.rb +227 -0
  74. data/lib/aylien_news_api/models/scope.rb +59 -54
  75. data/lib/aylien_news_api/models/sentiment.rb +41 -37
  76. data/lib/aylien_news_api/models/sentiments.rb +46 -44
  77. data/lib/aylien_news_api/models/share_count.rb +36 -32
  78. data/lib/aylien_news_api/models/share_counts.rb +38 -34
  79. data/lib/aylien_news_api/models/source.rb +95 -92
  80. data/lib/aylien_news_api/models/stories.rb +47 -55
  81. data/lib/aylien_news_api/models/story.rb +172 -154
  82. data/lib/aylien_news_api/models/story_cluster.rb +52 -48
  83. data/lib/aylien_news_api/models/story_links.rb +58 -54
  84. data/lib/aylien_news_api/models/story_translations.rb +197 -0
  85. data/lib/aylien_news_api/models/story_translations_en.rb +217 -0
  86. data/lib/aylien_news_api/models/summary.rb +35 -31
  87. data/lib/aylien_news_api/models/time_series.rb +47 -43
  88. data/lib/aylien_news_api/models/time_series_list.rb +56 -52
  89. data/lib/aylien_news_api/models/trend.rb +47 -43
  90. data/lib/aylien_news_api/models/trends.rb +48 -44
  91. data/lib/aylien_news_api/version.rb +7 -11
  92. data/spec/api/default_api_spec.rb +569 -533
  93. data/spec/api_client_spec.rb +34 -76
  94. data/spec/configuration_spec.rb +14 -18
  95. data/spec/models/author_spec.rb +15 -18
  96. data/spec/models/autocomplete_spec.rb +11 -14
  97. data/spec/models/autocompletes_spec.rb +10 -13
  98. data/spec/models/category_links_spec.rb +13 -16
  99. data/spec/models/category_spec.rb +24 -27
  100. data/spec/models/cluster_spec.rb +77 -0
  101. data/spec/models/clusters_spec.rb +53 -0
  102. data/spec/models/coverages_spec.rb +17 -26
  103. data/spec/models/entities_spec.rb +13 -16
  104. data/spec/models/entity_links_spec.rb +10 -13
  105. data/spec/models/entity_spec.rb +19 -22
  106. data/spec/models/error_links_spec.rb +10 -13
  107. data/spec/models/error_spec.rb +21 -24
  108. data/spec/models/errors_spec.rb +10 -13
  109. data/spec/models/histogram_interval_spec.rb +11 -14
  110. data/spec/models/histograms_spec.rb +18 -21
  111. data/spec/models/location_spec.rb +15 -18
  112. data/spec/models/media_spec.rb +29 -32
  113. data/spec/models/rank_spec.rb +15 -18
  114. data/spec/models/rankings_spec.rb +10 -13
  115. data/spec/models/related_stories_spec.rb +15 -24
  116. data/spec/models/representative_story_spec.rb +59 -0
  117. data/spec/models/scope_spec.rb +21 -24
  118. data/spec/models/sentiment_spec.rb +15 -18
  119. data/spec/models/sentiments_spec.rb +13 -16
  120. data/spec/models/share_count_spec.rb +11 -14
  121. data/spec/models/share_counts_spec.rb +13 -16
  122. data/spec/models/source_spec.rb +29 -32
  123. data/spec/models/stories_spec.rb +13 -22
  124. data/spec/models/story_cluster_spec.rb +17 -20
  125. data/spec/models/story_links_spec.rb +17 -20
  126. data/spec/models/story_spec.rb +59 -50
  127. data/spec/models/story_translations_en_spec.rb +53 -0
  128. data/spec/models/story_translations_spec.rb +41 -0
  129. data/spec/models/summary_spec.rb +10 -13
  130. data/spec/models/time_series_list_spec.rb +16 -19
  131. data/spec/models/time_series_spec.rb +13 -16
  132. data/spec/models/trend_spec.rb +13 -16
  133. data/spec/models/trends_spec.rb +13 -16
  134. data/spec/spec_helper.rb +6 -10
  135. metadata +68 -194
@@ -1,25 +1,20 @@
1
1
  =begin
2
- Copyright 2017 Aylien, Inc. All Rights Reserved.
2
+ #AYLIEN News API
3
3
 
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
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.
7
5
 
8
- http://www.apache.org/licenses/LICENSE-2.0
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: 4.1.3-SNAPSHOT
9
10
 
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
11
  =end
16
12
 
17
13
  require 'date'
18
14
  require 'json'
19
15
  require 'logger'
20
16
  require 'tempfile'
21
- require 'typhoeus'
22
- require 'uri'
17
+ require 'faraday'
23
18
 
24
19
  module AylienNewsApi
25
20
  class ApiClient
@@ -35,9 +30,9 @@ module AylienNewsApi
35
30
  # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
36
31
  def initialize(config = Configuration.default)
37
32
  @config = config
38
- @user_agent = "aylien-news-api/#{VERSION}/ruby"
33
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
39
34
  @default_headers = {
40
- 'Content-Type' => "application/json",
35
+ 'Content-Type' => 'application/json',
41
36
  'User-Agent' => @user_agent
42
37
  }
43
38
  end
@@ -48,29 +43,49 @@ module AylienNewsApi
48
43
 
49
44
  # Call an API with given options.
50
45
  #
51
- # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
46
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
52
47
  # the data deserialized from response body (could be nil), response status code and response headers.
53
48
  def call_api(http_method, path, opts = {})
54
- request = build_request(http_method, path, opts)
55
- 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
+ }
56
56
 
57
- if @config.debugging
58
- @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)
59
64
  end
60
65
 
61
- unless response.success?
62
- if response.timed_out?
63
- fail ApiError.new('Connection timed out')
64
- elsif response.code == 0
65
- # Errors from libcurl will be made visible here
66
- fail ApiError.new(:code => 0,
67
- :message => response.return_message)
68
- else
69
- fail ApiError.new(:code => response.code,
70
- :response_headers => response.headers,
71
- :response_body => response.body),
72
- 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"
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
73
86
  end
87
+ rescue Faraday::TimeoutError
88
+ fail ApiError.new('Connection timed out')
74
89
  end
75
90
 
76
91
  if opts[:return_type]
@@ -78,7 +93,7 @@ module AylienNewsApi
78
93
  else
79
94
  data = nil
80
95
  end
81
- return data, response.code, response.headers
96
+ return data, response.status, response.headers
82
97
  end
83
98
 
84
99
  # Builds the HTTP request
@@ -90,7 +105,7 @@ module AylienNewsApi
90
105
  # @option opts [Hash] :form_params Query parameters
91
106
  # @option opts [Object] :body HTTP body (JSON/XML)
92
107
  # @return [Typhoeus::Request] A Typhoeus Request
93
- def build_request(http_method, path, opts = {})
108
+ def build_request(http_method, path, request, opts = {})
94
109
  url = build_request_url(path)
95
110
  http_method = http_method.to_sym.downcase
96
111
 
@@ -100,25 +115,15 @@ module AylienNewsApi
100
115
 
101
116
  update_params_for_auth! header_params, query_params, opts[:auth_names]
102
117
 
103
- # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
104
- _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
105
-
106
118
  req_opts = {
107
119
  :method => http_method,
108
120
  :headers => header_params,
109
121
  :params => query_params,
110
122
  :params_encoding => @config.params_encoding,
111
123
  :timeout => @config.timeout,
112
- :ssl_verifypeer => @config.verify_ssl,
113
- :ssl_verifyhost => _verify_ssl_host,
114
- :sslcert => @config.cert_file,
115
- :sslkey => @config.key_file,
116
124
  :verbose => @config.debugging
117
125
  }
118
126
 
119
- # set custom cert, if provided
120
- req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
121
-
122
127
  if [:post, :patch, :put, :delete].include?(http_method)
123
128
  req_body = build_request_body(header_params, form_params, opts[:body])
124
129
  req_opts.update :body => req_body
@@ -126,8 +131,44 @@ module AylienNewsApi
126
131
  @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
127
132
  end
128
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
129
141
 
130
- 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
131
172
  end
132
173
 
133
174
  # Check if the given MIME is a JSON MIME.
@@ -139,23 +180,25 @@ module AylienNewsApi
139
180
  # @param [String] mime MIME
140
181
  # @return [Boolean] True if the MIME is application/json
141
182
  def json_mime?(mime)
142
- (mime == "*/*") || !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
183
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
143
184
  end
144
185
 
145
186
  # Deserialize the response to the given return type.
146
187
  #
147
188
  # @param [Response] response HTTP response
148
- # @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>"
149
190
  def deserialize(response, return_type)
150
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
+
151
197
  return nil if body.nil? || body.empty?
152
198
 
153
199
  # return response body directly for String return type
154
200
  return body if return_type == 'String'
155
201
 
156
- # handle file downloading - save response body into a tmp file and return the File instance
157
- return download_file(response) if return_type == 'File'
158
-
159
202
  # ensuring a default content type
160
203
  content_type = response.headers['Content-Type'] || 'application/json'
161
204
 
@@ -187,7 +230,7 @@ module AylienNewsApi
187
230
  data.to_i
188
231
  when 'Float'
189
232
  data.to_f
190
- when 'BOOLEAN'
233
+ when 'Boolean'
191
234
  data == true
192
235
  when 'DateTime'
193
236
  # parse date time (expecting ISO 8601 format)
@@ -201,47 +244,53 @@ module AylienNewsApi
201
244
  when /\AArray<(.+)>\z/
202
245
  # e.g. Array<Pet>
203
246
  sub_type = $1
204
- data.map {|item| convert_to_type(item, sub_type) }
247
+ data.map { |item| convert_to_type(item, sub_type) }
205
248
  when /\AHash\<String, (.+)\>\z/
206
249
  # e.g. Hash<String, Integer>
207
250
  sub_type = $1
208
251
  {}.tap do |hash|
209
- 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) }
210
253
  end
211
254
  else
212
255
  # models, e.g. Pet
213
- AylienNewsApi.const_get(return_type).new.tap do |model|
214
- model.build_from_hash data
215
- end
256
+ AylienNewsApi.const_get(return_type).build_from_hash(data)
216
257
  end
217
258
  end
218
259
 
219
260
  # Save response body into a file in (the defined) temporary folder, using the filename
220
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.
221
265
  #
222
266
  # @see Configuration#temp_folder_path
223
- # @return [Tempfile] the file downloaded
224
- def download_file(response)
225
- content_disposition = response.headers['Content-Disposition']
226
- if content_disposition and content_disposition =~ /filename=/i
227
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
228
- prefix = sanitize_filename(filename)
229
- else
230
- prefix = 'download-'
231
- end
232
- prefix = prefix + '-' unless prefix.end_with?('-')
233
-
267
+ def download_file(request)
234
268
  tempfile = nil
235
- encoding = response.body.encoding
236
- Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
237
- file.write(response.body)
238
- 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
+ tempfile.close if tempfile
289
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
290
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
291
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
292
+ "explicitly with `tempfile.delete`"
239
293
  end
240
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
241
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
242
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
243
- "explicitly with `tempfile.delete`"
244
- tempfile
245
294
  end
246
295
 
247
296
  # Sanitize filename by removing path.
@@ -256,35 +305,7 @@ module AylienNewsApi
256
305
  def build_request_url(path)
257
306
  # Add leading and trailing slashes to path
258
307
  path = "/#{path}".gsub(/\/+/, '/')
259
- URI.encode(@config.base_url + path)
260
- end
261
-
262
- # Builds the HTTP request body
263
- #
264
- # @param [Hash] header_params Header parameters
265
- # @param [Hash] form_params Query parameters
266
- # @param [Object] body HTTP body (JSON/XML)
267
- # @return [String] HTTP body data in the form of string
268
- def build_request_body(header_params, form_params, body)
269
- # http form
270
- if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
271
- header_params['Content-Type'] == 'multipart/form-data'
272
- data = {}
273
- form_params.each do |key, value|
274
- case value
275
- when File, Array, nil
276
- # let typhoeus handle File, Array and nil parameters
277
- data[key] = value
278
- else
279
- data[key] = value.to_s
280
- end
281
- end
282
- elsif body
283
- data = body.is_a?(String) ? body : body.to_json
284
- else
285
- data = nil
286
- end
287
- data
308
+ @config.base_url + path
288
309
  end
289
310
 
290
311
  # Update hearder and query params based on authentication settings.
@@ -306,7 +327,7 @@ module AylienNewsApi
306
327
 
307
328
  # Sets user agent in HTTP header
308
329
  #
309
- # @param [String] user_agent User agent (e.g. aylien-news-api/ruby/1.0.0)
330
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
310
331
  def user_agent=(user_agent)
311
332
  @user_agent = user_agent
312
333
  @default_headers['User-Agent'] = @user_agent
@@ -319,7 +340,7 @@ module AylienNewsApi
319
340
  return nil if accepts.nil? || accepts.empty?
320
341
  # use JSON when present, otherwise use all of the provided
321
342
  json_accept = accepts.find { |s| json_mime?(s) }
322
- return json_accept || accepts.join(',')
343
+ json_accept || accepts.join(',')
323
344
  end
324
345
 
325
346
  # Return Content-Type header based on an array of content types provided.
@@ -330,7 +351,7 @@ module AylienNewsApi
330
351
  return 'application/json' if content_types.nil? || content_types.empty?
331
352
  # use JSON when present, otherwise use the first one
332
353
  json_content_type = content_types.find { |s| json_mime?(s) }
333
- return json_content_type || content_types.first
354
+ json_content_type || content_types.first
334
355
  end
335
356
 
336
357
  # Convert object (array, hash, object, etc) to JSON string.
@@ -340,7 +361,7 @@ module AylienNewsApi
340
361
  return model if model.nil? || model.is_a?(String)
341
362
  local_body = nil
342
363
  if model.is_a?(Array)
343
- local_body = model.map{|m| object_to_hash(m) }
364
+ local_body = model.map { |m| object_to_hash(m) }
344
365
  else
345
366
  local_body = object_to_hash(model)
346
367
  end
@@ -1,17 +1,13 @@
1
1
  =begin
2
- Copyright 2017 Aylien, Inc. All Rights Reserved.
2
+ #AYLIEN News API
3
3
 
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
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.
7
5
 
8
- http://www.apache.org/licenses/LICENSE-2.0
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: 4.1.3-SNAPSHOT
9
10
 
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
11
  =end
16
12
 
17
13
  module AylienNewsApi
@@ -38,5 +34,24 @@ module AylienNewsApi
38
34
  super arg
39
35
  end
40
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
41
56
  end
42
57
  end
@@ -1,21 +1,15 @@
1
1
  =begin
2
- Copyright 2017 Aylien, Inc. All Rights Reserved.
2
+ #AYLIEN News API
3
3
 
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
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.
7
5
 
8
- http://www.apache.org/licenses/LICENSE-2.0
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: 4.1.3-SNAPSHOT
9
10
 
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
11
  =end
16
12
 
17
- require 'uri'
18
-
19
13
  module AylienNewsApi
20
14
  class Configuration
21
15
  # Defines url scheme
@@ -80,6 +74,11 @@ module AylienNewsApi
80
74
  # Default to 0 (never times out).
81
75
  attr_accessor :timeout
82
76
 
77
+ # Set this to false to skip client side validation in the operation.
78
+ # Default to true.
79
+ # @return [true, false]
80
+ attr_accessor :client_side_validation
81
+
83
82
  ### TLS/SSL setting
84
83
  # Set this to false to skip verifying SSL certificate when calling API from https server.
85
84
  # Default to true.
@@ -87,33 +86,28 @@ module AylienNewsApi
87
86
  # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
88
87
  #
89
88
  # @return [true, false]
90
- attr_accessor :verify_ssl
89
+ attr_accessor :ssl_verify
91
90
 
92
91
  ### TLS/SSL setting
93
- # Set this to false to skip verifying SSL host name
94
- # Default to true.
92
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
95
93
  #
96
94
  # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
97
95
  #
98
- # @return [true, false]
99
- attr_accessor :verify_ssl_host
96
+ attr_accessor :ssl_verify_mode
100
97
 
101
98
  ### TLS/SSL setting
102
99
  # Set this to customize the certificate file to verify the peer.
103
100
  #
104
101
  # @return [String] the path to the certificate file
105
- #
106
- # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
107
- # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
108
- attr_accessor :ssl_ca_cert
102
+ attr_accessor :ssl_ca_file
109
103
 
110
104
  ### TLS/SSL setting
111
105
  # Client certificate file (for client certificate)
112
- attr_accessor :cert_file
106
+ attr_accessor :ssl_client_cert
113
107
 
114
108
  ### TLS/SSL setting
115
109
  # Client private key file (for client certificate)
116
- attr_accessor :key_file
110
+ attr_accessor :ssl_client_key
117
111
 
118
112
  # Set this to customize parameters encoding of array parameter with multi collectionFormat.
119
113
  # Default to nil.
@@ -128,16 +122,17 @@ module AylienNewsApi
128
122
 
129
123
  def initialize
130
124
  @scheme = 'https'
131
- @host = 'api.newsapi.aylien.com'
132
- @base_path = '/api/v1'
125
+ @host = 'api.aylien.com'
126
+ @base_path = '/news'
133
127
  @api_key = {}
134
128
  @api_key_prefix = {}
135
129
  @timeout = 0
136
- @verify_ssl = true
137
- @verify_ssl_host = true
138
- @params_encoding = :multi
139
- @cert_file = nil
140
- @key_file = nil
130
+ @client_side_validation = true
131
+ @ssl_verify = true
132
+ @ssl_verify_mode = nil
133
+ @ssl_ca_file = nil
134
+ @ssl_client_cert = nil
135
+ @ssl_client_key = nil
141
136
  @debugging = false
142
137
  @inject_format = false
143
138
  @force_ending_format = false
@@ -168,12 +163,11 @@ module AylienNewsApi
168
163
  def base_path=(base_path)
169
164
  # Add leading and trailing slashes to base_path
170
165
  @base_path = "/#{base_path}".gsub(/\/+/, '/')
171
- @base_path = "" if @base_path == "/"
166
+ @base_path = '' if @base_path == '/'
172
167
  end
173
168
 
174
169
  def base_url
175
- url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
176
- URI.encode(url)
170
+ "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
177
171
  end
178
172
 
179
173
  # Gets API key (with prefix if set).
@@ -210,5 +204,47 @@ module AylienNewsApi
210
204
  },
211
205
  }
212
206
  end
207
+
208
+ # Returns an array of Server setting
209
+ def server_settings
210
+ [
211
+ {
212
+ url: "https://api.aylien.com/news",
213
+ description: "No descriptoin provided",
214
+ }
215
+ ]
216
+ end
217
+
218
+ # Returns URL based on server settings
219
+ #
220
+ # @param index array index of the server settings
221
+ # @param variables hash of variable and the corresponding value
222
+ def server_url(index, variables = {})
223
+ servers = server_settings
224
+
225
+ # check array index out of bound
226
+ if (index < 0 || index >= servers.size)
227
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
228
+ end
229
+
230
+ server = servers[index]
231
+ url = server[:url]
232
+
233
+ # go through variable and assign a value
234
+ server[:variables].each do |name, variable|
235
+ if variables.key?(name)
236
+ if (server[:variables][name][:enum_values].include? variables[name])
237
+ url.gsub! "{" + name.to_s + "}", variables[name]
238
+ else
239
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
240
+ end
241
+ else
242
+ # use default value
243
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
244
+ end
245
+ end
246
+
247
+ url
248
+ end
213
249
  end
214
250
  end