aylien_news_api 0.3.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Gemfile +7 -1
- data/README.md +117 -4
- data/Rakefile +10 -0
- data/aylien_news_api.gemspec +24 -31
- data/docs/Author.md +12 -1
- data/docs/Autocomplete.md +10 -0
- data/docs/Autocompletes.md +9 -0
- data/docs/Category.md +19 -3
- data/docs/CategoryLinks.md +11 -1
- data/docs/CategoryTaxonomy.md +16 -0
- data/docs/Cluster.md +29 -0
- data/docs/Clusters.md +21 -0
- data/docs/Coverages.md +16 -4
- data/docs/DefaultApi.md +1310 -636
- data/docs/Entities.md +11 -1
- data/docs/Entity.md +16 -3
- data/docs/EntityLinks.md +9 -0
- data/docs/Error.md +16 -2
- data/docs/ErrorLinks.md +11 -0
- data/docs/Errors.md +9 -0
- data/docs/HistogramInterval.md +10 -0
- data/docs/Histograms.md +20 -3
- data/docs/Location.md +13 -2
- data/docs/Media.md +19 -1
- data/docs/MediaFormat.md +16 -0
- data/docs/MediaType.md +16 -0
- data/docs/Rank.md +12 -1
- data/docs/Rankings.md +9 -0
- data/docs/RelatedStories.md +18 -3
- data/docs/RepresentativeStory.md +23 -0
- data/docs/Scope.md +15 -3
- data/docs/ScopeLevel.md +16 -0
- data/docs/Sentiment.md +11 -1
- data/docs/SentimentPolarity.md +16 -0
- data/docs/Sentiments.md +12 -2
- data/docs/ShareCount.md +10 -0
- data/docs/ShareCounts.md +12 -0
- data/docs/Source.md +27 -8
- data/docs/Stories.md +17 -2
- data/docs/Story.md +48 -16
- data/docs/StoryCluster.md +14 -1
- data/docs/StoryLinks.md +14 -1
- data/docs/StoryTranslation.md +19 -0
- data/docs/StoryTranslations.md +17 -0
- data/docs/StoryTranslationsEn.md +21 -0
- data/docs/Summary.md +9 -0
- data/docs/TimeSeries.md +11 -1
- data/docs/TimeSeriesList.md +15 -3
- data/docs/Trend.md +11 -1
- data/docs/Trends.md +15 -1
- data/docs/Warning.md +21 -0
- data/git_push.sh +58 -0
- data/lib/aylien_news_api.rb +22 -14
- data/lib/aylien_news_api/api/default_api.rb +2631 -1120
- data/lib/aylien_news_api/api_client.rb +139 -105
- data/lib/aylien_news_api/api_error.rb +37 -18
- data/lib/aylien_news_api/configuration.rb +80 -42
- data/lib/aylien_news_api/models/author.rb +69 -53
- data/lib/aylien_news_api/models/autocomplete.rb +55 -39
- data/lib/aylien_news_api/models/autocompletes.rb +54 -38
- data/lib/aylien_news_api/models/category.rb +88 -97
- data/lib/aylien_news_api/models/category_links.rb +66 -50
- data/lib/aylien_news_api/models/category_taxonomy.rb +36 -0
- data/lib/aylien_news_api/models/cluster.rb +265 -0
- data/lib/aylien_news_api/models/clusters.rb +229 -0
- data/lib/aylien_news_api/models/coverages.rb +79 -75
- data/lib/aylien_news_api/models/entities.rb +67 -51
- data/lib/aylien_news_api/models/entity.rb +96 -83
- data/lib/aylien_news_api/models/entity_links.rb +54 -38
- data/lib/aylien_news_api/models/error.rb +79 -63
- data/lib/aylien_news_api/models/error_links.rb +65 -40
- data/lib/aylien_news_api/models/errors.rb +54 -38
- data/lib/aylien_news_api/models/histogram_interval.rb +55 -39
- data/lib/aylien_news_api/models/histograms.rb +99 -63
- data/lib/aylien_news_api/models/location.rb +70 -54
- data/lib/aylien_news_api/models/media.rb +97 -76
- data/lib/aylien_news_api/models/media_format.rb +44 -0
- data/lib/aylien_news_api/models/media_type.rb +36 -0
- data/lib/aylien_news_api/models/rank.rb +67 -51
- data/lib/aylien_news_api/models/rankings.rb +54 -38
- data/lib/aylien_news_api/models/related_stories.rb +87 -63
- data/lib/aylien_news_api/models/representative_story.rb +237 -0
- data/lib/aylien_news_api/models/scope.rb +76 -94
- data/lib/aylien_news_api/models/scope_level.rb +37 -0
- data/lib/aylien_news_api/models/sentiment.rb +66 -86
- data/lib/aylien_news_api/models/sentiment_polarity.rb +37 -0
- data/lib/aylien_news_api/models/sentiments.rb +65 -51
- data/lib/aylien_news_api/models/share_count.rb +55 -39
- data/lib/aylien_news_api/models/share_counts.rb +57 -41
- data/lib/aylien_news_api/models/source.rb +114 -99
- data/lib/aylien_news_api/models/stories.rb +89 -53
- data/lib/aylien_news_api/models/story.rb +191 -161
- data/lib/aylien_news_api/models/story_cluster.rb +71 -55
- data/lib/aylien_news_api/models/story_links.rb +73 -47
- data/lib/aylien_news_api/models/story_translation.rb +217 -0
- data/lib/aylien_news_api/models/story_translations.rb +207 -0
- data/lib/aylien_news_api/models/story_translations_en.rb +227 -0
- data/lib/aylien_news_api/models/summary.rb +54 -38
- data/lib/aylien_news_api/models/time_series.rb +66 -50
- data/lib/aylien_news_api/models/time_series_list.rb +75 -59
- data/lib/aylien_news_api/models/trend.rb +66 -50
- data/lib/aylien_news_api/models/trends.rb +80 -44
- data/lib/aylien_news_api/models/warning.rb +226 -0
- data/lib/aylien_news_api/version.rb +12 -14
- data/spec/api/default_api_spec.rb +620 -284
- data/spec/api_client_spec.rb +43 -161
- data/spec/configuration_spec.rb +22 -19
- data/spec/models/author_spec.rb +21 -34
- data/spec/models/autocomplete_spec.rb +17 -26
- data/spec/models/autocompletes_spec.rb +16 -21
- data/spec/models/category_links_spec.rb +19 -28
- data/spec/models/category_spec.rb +31 -50
- data/spec/models/category_taxonomy_spec.rb +35 -0
- data/spec/models/cluster_spec.rb +77 -0
- data/spec/models/clusters_spec.rb +53 -0
- data/spec/models/coverages_spec.rb +24 -45
- data/spec/models/entities_spec.rb +19 -28
- data/spec/models/entity_links_spec.rb +16 -21
- data/spec/models/entity_spec.rb +25 -46
- data/spec/models/error_links_spec.rb +22 -21
- data/spec/models/error_spec.rb +27 -52
- data/spec/models/errors_spec.rb +16 -21
- data/spec/models/histogram_interval_spec.rb +17 -26
- data/spec/models/histograms_spec.rb +36 -45
- data/spec/models/location_spec.rb +21 -34
- data/spec/models/media_format_spec.rb +35 -0
- data/spec/models/media_spec.rb +41 -26
- data/spec/models/media_type_spec.rb +35 -0
- data/spec/models/rank_spec.rb +20 -21
- data/spec/models/rankings_spec.rb +15 -16
- data/spec/models/related_stories_spec.rb +33 -38
- data/spec/models/representative_story_spec.rb +59 -0
- data/spec/models/scope_level_spec.rb +35 -0
- data/spec/models/scope_spec.rb +23 -40
- data/spec/models/sentiment_polarity_spec.rb +35 -0
- data/spec/models/sentiment_spec.rb +17 -26
- data/spec/models/sentiments_spec.rb +19 -28
- data/spec/models/share_count_spec.rb +17 -26
- data/spec/models/share_counts_spec.rb +19 -36
- data/spec/models/source_spec.rb +54 -49
- data/spec/models/stories_spec.rb +32 -33
- data/spec/models/story_cluster_spec.rb +23 -44
- data/spec/models/story_links_spec.rb +25 -32
- data/spec/models/story_spec.rb +65 -134
- data/spec/models/story_translation_spec.rb +47 -0
- data/spec/models/story_translations_en_spec.rb +53 -0
- data/spec/models/story_translations_spec.rb +41 -0
- data/spec/models/summary_spec.rb +16 -21
- data/spec/models/time_series_list_spec.rb +22 -39
- data/spec/models/time_series_spec.rb +19 -28
- data/spec/models/trend_spec.rb +19 -28
- data/spec/models/trends_spec.rb +30 -27
- data/spec/models/warning_spec.rb +53 -0
- data/spec/spec_helper.rb +11 -13
- metadata +92 -195
- data/Gemfile.lock +0 -65
- data/LICENSE +0 -13
- data/aylien_news_api-0.2.0.gem +0 -0
@@ -1,23 +1,20 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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 '
|
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 = "
|
33
|
+
@user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
|
37
34
|
@default_headers = {
|
38
|
-
'Content-Type' =>
|
35
|
+
'Content-Type' => 'application/json',
|
39
36
|
'User-Agent' => @user_agent
|
40
37
|
}
|
41
38
|
end
|
@@ -46,21 +43,49 @@ module AylienNewsApi
|
|
46
43
|
|
47
44
|
# Call an API with given options.
|
48
45
|
#
|
49
|
-
# @return [Array<(Object,
|
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
|
-
|
53
|
-
|
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
|
-
|
56
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
86
|
+
end
|
87
|
+
rescue Faraday::TimeoutError
|
88
|
+
fail ApiError.new('Connection timed out')
|
64
89
|
end
|
65
90
|
|
66
91
|
if opts[:return_type]
|
@@ -68,7 +93,7 @@ module AylienNewsApi
|
|
68
93
|
else
|
69
94
|
data = nil
|
70
95
|
end
|
71
|
-
return data, response.
|
96
|
+
return data, response.status, response.headers
|
72
97
|
end
|
73
98
|
|
74
99
|
# Builds the HTTP request
|
@@ -80,7 +105,7 @@ module AylienNewsApi
|
|
80
105
|
# @option opts [Hash] :form_params Query parameters
|
81
106
|
# @option opts [Object] :body HTTP body (JSON/XML)
|
82
107
|
# @return [Typhoeus::Request] A Typhoeus Request
|
83
|
-
def build_request(http_method, path, opts = {})
|
108
|
+
def build_request(http_method, path, request, opts = {})
|
84
109
|
url = build_request_url(path)
|
85
110
|
http_method = http_method.to_sym.downcase
|
86
111
|
|
@@ -90,25 +115,15 @@ module AylienNewsApi
|
|
90
115
|
|
91
116
|
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
92
117
|
|
93
|
-
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
94
|
-
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
95
|
-
|
96
118
|
req_opts = {
|
97
119
|
:method => http_method,
|
98
120
|
:headers => header_params,
|
99
121
|
:params => query_params,
|
100
122
|
:params_encoding => @config.params_encoding,
|
101
123
|
:timeout => @config.timeout,
|
102
|
-
:ssl_verifypeer => @config.verify_ssl,
|
103
|
-
:ssl_verifyhost => _verify_ssl_host,
|
104
|
-
:sslcert => @config.cert_file,
|
105
|
-
:sslkey => @config.key_file,
|
106
124
|
:verbose => @config.debugging
|
107
125
|
}
|
108
126
|
|
109
|
-
# set custom cert, if provided
|
110
|
-
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
111
|
-
|
112
127
|
if [:post, :patch, :put, :delete].include?(http_method)
|
113
128
|
req_body = build_request_body(header_params, form_params, opts[:body])
|
114
129
|
req_opts.update :body => req_body
|
@@ -116,8 +131,44 @@ module AylienNewsApi
|
|
116
131
|
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
117
132
|
end
|
118
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
|
119
141
|
|
120
|
-
|
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
|
121
172
|
end
|
122
173
|
|
123
174
|
# Check if the given MIME is a JSON MIME.
|
@@ -125,26 +176,29 @@ module AylienNewsApi
|
|
125
176
|
# application/json
|
126
177
|
# application/json; charset=UTF8
|
127
178
|
# APPLICATION/JSON
|
179
|
+
# */*
|
128
180
|
# @param [String] mime MIME
|
129
|
-
# @return [Boolean] True if the MIME is
|
181
|
+
# @return [Boolean] True if the MIME is application/json
|
130
182
|
def json_mime?(mime)
|
131
|
-
|
183
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
132
184
|
end
|
133
185
|
|
134
186
|
# Deserialize the response to the given return type.
|
135
187
|
#
|
136
188
|
# @param [Response] response HTTP response
|
137
|
-
# @param [String] return_type some examples: "User", "Array
|
189
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
138
190
|
def deserialize(response, return_type)
|
139
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
|
+
|
140
197
|
return nil if body.nil? || body.empty?
|
141
198
|
|
142
199
|
# return response body directly for String return type
|
143
200
|
return body if return_type == 'String'
|
144
201
|
|
145
|
-
# handle file downloading - save response body into a tmp file and return the File instance
|
146
|
-
return download_file(response) if return_type == 'File'
|
147
|
-
|
148
202
|
# ensuring a default content type
|
149
203
|
content_type = response.headers['Content-Type'] || 'application/json'
|
150
204
|
|
@@ -176,7 +230,7 @@ module AylienNewsApi
|
|
176
230
|
data.to_i
|
177
231
|
when 'Float'
|
178
232
|
data.to_f
|
179
|
-
when '
|
233
|
+
when 'Boolean'
|
180
234
|
data == true
|
181
235
|
when 'DateTime'
|
182
236
|
# parse date time (expecting ISO 8601 format)
|
@@ -190,47 +244,55 @@ module AylienNewsApi
|
|
190
244
|
when /\AArray<(.+)>\z/
|
191
245
|
# e.g. Array<Pet>
|
192
246
|
sub_type = $1
|
193
|
-
data.map {|item| convert_to_type(item, sub_type) }
|
247
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
194
248
|
when /\AHash\<String, (.+)\>\z/
|
195
249
|
# e.g. Hash<String, Integer>
|
196
250
|
sub_type = $1
|
197
251
|
{}.tap do |hash|
|
198
|
-
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) }
|
199
253
|
end
|
200
254
|
else
|
201
255
|
# models, e.g. Pet
|
202
|
-
AylienNewsApi.const_get(return_type).
|
203
|
-
model.build_from_hash data
|
204
|
-
end
|
256
|
+
AylienNewsApi.const_get(return_type).build_from_hash(data)
|
205
257
|
end
|
206
258
|
end
|
207
259
|
|
208
260
|
# Save response body into a file in (the defined) temporary folder, using the filename
|
209
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.
|
210
265
|
#
|
211
266
|
# @see Configuration#temp_folder_path
|
212
|
-
|
213
|
-
def download_file(response)
|
214
|
-
content_disposition = response.headers['Content-Disposition']
|
215
|
-
if content_disposition and content_disposition =~ /filename=/i
|
216
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
217
|
-
prefix = sanitize_filename(filename)
|
218
|
-
else
|
219
|
-
prefix = 'download-'
|
220
|
-
end
|
221
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
222
|
-
|
267
|
+
def download_file(request)
|
223
268
|
tempfile = nil
|
224
|
-
encoding =
|
225
|
-
|
226
|
-
|
227
|
-
|
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
|
228
295
|
end
|
229
|
-
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
230
|
-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
231
|
-
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
232
|
-
"explicitly with `tempfile.delete`"
|
233
|
-
tempfile
|
234
296
|
end
|
235
297
|
|
236
298
|
# Sanitize filename by removing path.
|
@@ -245,35 +307,7 @@ module AylienNewsApi
|
|
245
307
|
def build_request_url(path)
|
246
308
|
# Add leading and trailing slashes to path
|
247
309
|
path = "/#{path}".gsub(/\/+/, '/')
|
248
|
-
|
249
|
-
end
|
250
|
-
|
251
|
-
# Builds the HTTP request body
|
252
|
-
#
|
253
|
-
# @param [Hash] header_params Header parameters
|
254
|
-
# @param [Hash] form_params Query parameters
|
255
|
-
# @param [Object] body HTTP body (JSON/XML)
|
256
|
-
# @return [String] HTTP body data in the form of string
|
257
|
-
def build_request_body(header_params, form_params, body)
|
258
|
-
# http form
|
259
|
-
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
260
|
-
header_params['Content-Type'] == 'multipart/form-data'
|
261
|
-
data = {}
|
262
|
-
form_params.each do |key, value|
|
263
|
-
case value
|
264
|
-
when File, Array, nil
|
265
|
-
# let typhoeus handle File, Array and nil parameters
|
266
|
-
data[key] = value
|
267
|
-
else
|
268
|
-
data[key] = value.to_s
|
269
|
-
end
|
270
|
-
end
|
271
|
-
elsif body
|
272
|
-
data = body.is_a?(String) ? body : body.to_json
|
273
|
-
else
|
274
|
-
data = nil
|
275
|
-
end
|
276
|
-
data
|
310
|
+
@config.base_url + path
|
277
311
|
end
|
278
312
|
|
279
313
|
# Update hearder and query params based on authentication settings.
|
@@ -295,7 +329,7 @@ module AylienNewsApi
|
|
295
329
|
|
296
330
|
# Sets user agent in HTTP header
|
297
331
|
#
|
298
|
-
# @param [String] user_agent User agent
|
332
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
299
333
|
def user_agent=(user_agent)
|
300
334
|
@user_agent = user_agent
|
301
335
|
@default_headers['User-Agent'] = @user_agent
|
@@ -308,7 +342,7 @@ module AylienNewsApi
|
|
308
342
|
return nil if accepts.nil? || accepts.empty?
|
309
343
|
# use JSON when present, otherwise use all of the provided
|
310
344
|
json_accept = accepts.find { |s| json_mime?(s) }
|
311
|
-
|
345
|
+
json_accept || accepts.join(',')
|
312
346
|
end
|
313
347
|
|
314
348
|
# Return Content-Type header based on an array of content types provided.
|
@@ -319,7 +353,7 @@ module AylienNewsApi
|
|
319
353
|
return 'application/json' if content_types.nil? || content_types.empty?
|
320
354
|
# use JSON when present, otherwise use the first one
|
321
355
|
json_content_type = content_types.find { |s| json_mime?(s) }
|
322
|
-
|
356
|
+
json_content_type || content_types.first
|
323
357
|
end
|
324
358
|
|
325
359
|
# Convert object (array, hash, object, etc) to JSON string.
|
@@ -329,7 +363,7 @@ module AylienNewsApi
|
|
329
363
|
return model if model.nil? || model.is_a?(String)
|
330
364
|
local_body = nil
|
331
365
|
if model.is_a?(Array)
|
332
|
-
local_body = model.map{|m| object_to_hash(m) }
|
366
|
+
local_body = model.map { |m| object_to_hash(m) }
|
333
367
|
else
|
334
368
|
local_body = object_to_hash(model)
|
335
369
|
end
|
@@ -1,16 +1,14 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
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
|