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.
- checksums.yaml +5 -5
- data/Gemfile +7 -1
- data/README.md +117 -4
- data/Rakefile +10 -0
- data/aylien_news_api.gemspec +20 -28
- 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 +1299 -826
- 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 +18 -4
- 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 +2407 -1520
- data/lib/aylien_news_api/api_client.rb +137 -111
- data/lib/aylien_news_api/api_error.rb +37 -18
- data/lib/aylien_news_api/configuration.rb +74 -36
- data/lib/aylien_news_api/models/author.rb +66 -50
- data/lib/aylien_news_api/models/autocomplete.rb +52 -36
- data/lib/aylien_news_api/models/autocompletes.rb +51 -35
- data/lib/aylien_news_api/models/category.rb +85 -94
- data/lib/aylien_news_api/models/category_links.rb +63 -47
- 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 +76 -72
- data/lib/aylien_news_api/models/entities.rb +64 -48
- data/lib/aylien_news_api/models/entity.rb +93 -79
- data/lib/aylien_news_api/models/entity_links.rb +51 -35
- data/lib/aylien_news_api/models/error.rb +76 -60
- data/lib/aylien_news_api/models/error_links.rb +62 -37
- data/lib/aylien_news_api/models/errors.rb +51 -35
- data/lib/aylien_news_api/models/histogram_interval.rb +52 -36
- data/lib/aylien_news_api/models/histograms.rb +96 -60
- data/lib/aylien_news_api/models/location.rb +67 -51
- data/lib/aylien_news_api/models/media.rb +83 -114
- 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 +64 -48
- data/lib/aylien_news_api/models/rankings.rb +51 -35
- data/lib/aylien_news_api/models/related_stories.rb +84 -60
- data/lib/aylien_news_api/models/representative_story.rb +237 -0
- data/lib/aylien_news_api/models/scope.rb +73 -91
- data/lib/aylien_news_api/models/scope_level.rb +37 -0
- data/lib/aylien_news_api/models/sentiment.rb +63 -82
- data/lib/aylien_news_api/models/sentiment_polarity.rb +37 -0
- data/lib/aylien_news_api/models/sentiments.rb +62 -48
- data/lib/aylien_news_api/models/share_count.rb +52 -36
- data/lib/aylien_news_api/models/share_counts.rb +54 -38
- data/lib/aylien_news_api/models/source.rb +111 -96
- data/lib/aylien_news_api/models/stories.rb +86 -50
- data/lib/aylien_news_api/models/story.rb +188 -158
- data/lib/aylien_news_api/models/story_cluster.rb +68 -52
- data/lib/aylien_news_api/models/story_links.rb +70 -44
- 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 +51 -35
- data/lib/aylien_news_api/models/time_series.rb +63 -47
- data/lib/aylien_news_api/models/time_series_list.rb +72 -56
- data/lib/aylien_news_api/models/trend.rb +63 -47
- data/lib/aylien_news_api/models/trends.rb +77 -41
- 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 +91 -192
- data/Gemfile.lock +0 -65
- data/LICENSE +0 -13
- data/aylien_news_api-0.2.0.gem +0 -0
- data/aylien_news_api-0.3.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,29 +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
|
-
|
64
|
-
|
65
|
-
|
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.
|
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
|
-
|
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
|
-
|
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
|
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 '
|
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).
|
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
|
-
|
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 =
|
233
|
-
|
234
|
-
|
235
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|