microsoft_kiota_faraday 0.23.0 → 0.24.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a0c0c510b70a06940555374f95a4fa8390e439b8219f0c0e2c80305386ec6ae
4
- data.tar.gz: ec465be8e91057f9f39e4fe91af9636facb5574ef1c10d130be24d119c650bda
3
+ metadata.gz: 4a68a845f0887c47484b1e228b72cd33f3cfc8fcffdcfb6f7e3594deba1030ed
4
+ data.tar.gz: '03395094f438a7bfc4f4711c65b1dafc73587eac817395677ea2e3dc4f9db2bf'
5
5
  SHA512:
6
- metadata.gz: 36dd13115681ee764d725e0dc955dcc9c9d99d9aa99af434fb4b57a0f022ad999c3d070b4e8365b9c6bcd84a254e8ba9e8d95aefe54ccb58d25b1b5868fdcd61
7
- data.tar.gz: 13782fcf9a3e7e0afe85b563d7fe3a59e2826267f1af84e0b04e908bc8d8301b02d8b4dc15505e4e8f57d67e7c0cd1b9008d05e5d886fd5e6bc35d48b77c8fc6
6
+ metadata.gz: dac37551824aa2f994cd6e2fff4c3cf0cc07c1e461f6204eb62c807c96e00413da6200271e926536fa92e86ee919496d71f5e47cfa93bc2e58b287bc14901aa8
7
+ data.tar.gz: 4063ca45152405abccb8fa823f4fbc2173bd4950ab33bc164521ce0110df4b67fd9cb0bfbfc1046f1fc92591fe07baf0e165b623d556477adde53a54034e5fc0
data/Gemfile CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
+ ruby '>= 3.3.0'
6
+
5
7
  gem 'microsoft_kiota_abstractions', path: '../abstractions'
6
8
 
7
9
  gemspec
@@ -5,6 +5,7 @@ require 'faraday'
5
5
  require 'net/http'
6
6
  require 'stringio'
7
7
  require_relative 'kiota_client_factory'
8
+ require_relative 'request_body'
8
9
  require_relative 'middleware/response_handler_option'
9
10
 
10
11
  module MicrosoftKiotaFaraday
@@ -140,23 +141,28 @@ module MicrosoftKiotaFaraday
140
141
  return if status_code < 400
141
142
 
142
143
  error_factory = errors_mapping[status_code.to_s] unless errors_mapping.nil?
143
- error_factory = errors_mapping['4XX'] unless !error_factory.nil? || errors_mapping.nil? || status_code > 500
144
- unless !error_factory.nil? || errors_mapping.nil? || status_code < 500 || status_code > 600
144
+ error_factory = errors_mapping['4XX'] unless !error_factory.nil? || errors_mapping.nil? || status_code >= 500
145
+ unless !error_factory.nil? || errors_mapping.nil? || status_code < 500 || status_code >= 600
145
146
  error_factory = errors_mapping['5XX']
146
147
  end
147
- unless !error_factory.nil? || errors_mapping.nil? || status_code < 400 || status_code > 600
148
+ unless !error_factory.nil? || errors_mapping.nil? || status_code < 400 || status_code >= 600
148
149
  error_factory = errors_mapping['XXX']
149
150
  end
150
151
  if error_factory.nil?
151
- raise MicrosoftKiotaAbstractions::ApiError,
152
- "The server returned an unexpected status code and no error factory is registered for this code:#{status_code}"
152
+ raise MicrosoftKiotaAbstractions::ApiError.new(
153
+ "The server returned an unexpected status code and no error factory is registered for this code:#{status_code}",
154
+ response_status_code: status_code, response_headers: response.headers
155
+ )
153
156
  end
154
157
 
155
158
  root_node = get_root_parse_node(response)
156
159
  error = root_node.get_object_value(error_factory) unless root_node.nil?
157
- raise error unless error.nil?
160
+ if error.nil?
161
+ raise MicrosoftKiotaAbstractions::ApiError.new("The server returned an unexpected status code:#{status_code}",
162
+ response_status_code: status_code, response_headers: response.headers)
163
+ end
158
164
 
159
- raise MicrosoftKiotaAbstractions::ApiError, "The server returned an unexpected status code:#{status_code}"
165
+ raise add_response_details(error, response)
160
166
  end
161
167
 
162
168
  def get_request_from_request_info(request_info)
@@ -180,8 +186,7 @@ module MicrosoftKiotaFaraday
180
186
  end
181
187
  end
182
188
  end
183
- request.body = request_info.content unless request_info.content.nil? || request_info.content.empty?
184
- # TODO: the json serialization writer returns a string at the moment, change to body_stream when this is fixed
189
+ RequestBody.apply(request, request_info.content)
185
190
  request_options = request_info.get_request_options
186
191
  if !request_options.nil? && !request_options.empty?
187
192
  request.options = Faraday::RequestOptions.new if request.options.nil?
@@ -213,5 +218,14 @@ module MicrosoftKiotaFaraday
213
218
  def set_base_url_for_request_information(request_info)
214
219
  request_info.path_parameters['baseurl'] = @base_url
215
220
  end
221
+
222
+ # an error the factory built learns the response details only once it is deserialized
223
+ def add_response_details(error, response)
224
+ return error unless error.is_a?(MicrosoftKiotaAbstractions::ApiError)
225
+
226
+ error.response_status_code = response.status
227
+ error.response_headers = response.headers
228
+ error
229
+ end
216
230
  end
217
231
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MicrosoftKiotaFaraday
4
+ # Faraday sends an IO body as a Net::HTTP body_stream, which needs its length up front, so a
5
+ # stream is passed through and measured rather than read into memory.
6
+ module RequestBody
7
+ FRAMING_HEADERS = %w[Content-Length Transfer-Encoding].freeze
8
+
9
+ module_function
10
+
11
+ def apply(request, content)
12
+ # the request owns its framing, so whatever the caller sent is dropped and then set from the
13
+ # body that is actually written, which leaves every early return below safe
14
+ FRAMING_HEADERS.each { |header| request.headers.delete(header) }
15
+ return if content.nil?
16
+
17
+ unless content.respond_to?(:read)
18
+ request.body = content unless content.respond_to?(:empty?) && content.empty?
19
+ return
20
+ end
21
+
22
+ length = stream_length(content)
23
+ return if length&.zero?
24
+
25
+ if length.nil?
26
+ request.headers['Transfer-Encoding'] = 'chunked'
27
+ else
28
+ request.headers['Content-Length'] = length.to_s
29
+ end
30
+ request.body = content
31
+ end
32
+
33
+ # a stream that cannot report a size, such as a pipe or $stdin, is sent chunked instead
34
+ def stream_length(content)
35
+ return nil unless content.respond_to?(:size) && content.respond_to?(:pos)
36
+
37
+ size = content.size
38
+ # a stream can be positioned past its end, which leaves nothing to send rather than a
39
+ # negative number of bytes
40
+ size.nil? ? nil : [size - content.pos, 0].max
41
+ rescue StandardError
42
+ nil
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MicrosoftKiotaFaraday
4
- VERSION = '0.23.0' # x-release-please-version
4
+ VERSION = '0.24.1' # x-release-please-version
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microsoft_kiota_faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.0
4
+ version: 0.24.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Microsoft Corporation
@@ -35,14 +35,14 @@ dependencies:
35
35
  requirements:
36
36
  - - '='
37
37
  - !ruby/object:Gem::Version
38
- version: 0.23.0
38
+ version: 0.24.1
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - '='
44
44
  - !ruby/object:Gem::Version
45
- version: 0.23.0
45
+ version: 0.24.1
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rake
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +102,7 @@ files:
102
102
  - lib/microsoft_kiota_faraday/middleware/response_handler_option.rb
103
103
  - lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb
104
104
  - lib/microsoft_kiota_faraday/middleware/user_agent_option.rb
105
+ - lib/microsoft_kiota_faraday/request_body.rb
105
106
  - lib/microsoft_kiota_faraday/version.rb
106
107
  - microsoft_kiota_faraday.gemspec
107
108
  homepage: https://learn.microsoft.com/openapi/kiota/