microsoft_kiota_faraday 0.22.0 → 0.24.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da9b4001f18252450bece3bdd2402460aa13dfcaa480220610fec1756170f8f5
4
- data.tar.gz: 813405b22fe8212b4660cd9daabc6cd504f26ab0d723e167e0eebebb8a71c74f
3
+ metadata.gz: 9f13843ff9f2f3f96d01e15c535e94acc80a1e50fdecfa4d28aa4d284c77360a
4
+ data.tar.gz: d9f9bc30acbeed92f0205606869140c5a1e0f46f1af4bb2f509511ebdd7543bc
5
5
  SHA512:
6
- metadata.gz: 21b89a9527fbcece787d3c90ad4f64bfe4be8ae57774367025be7bfec531ca23ccb96163a9bd4279655a7366b1a3c3e6ffdb8831194b90cbf557f72e35f6da26
7
- data.tar.gz: 8a0e5a5c0c7ccaefbf1fa0d7eb638c73ae2894cdc422098ee59f64e868167155d8e793b910633729a825dcc0ebc00e02c39a0c35892b2da90fc8e4049aadc8fe
6
+ metadata.gz: e0311088fbe4f243bff7346a99cd947680d45817ac1782c9560954d20ecf745a7cda971083a38ab77c04152895bb7d5e89c614a3bea06ed61d0d7a413e3388d7
7
+ data.tar.gz: 0f55d1082cfb81d2046a9c85a2631a6204b4a7f3ff348db64de3088fd5e6e8c9c34821aeea02e15a4ebc76d7bf0ae74725d2056056baa7db323ec9f9d018bbd9
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
@@ -148,38 +149,27 @@ module MicrosoftKiotaFaraday
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)
163
169
  set_base_url_for_request_information(request_info)
164
170
  case request_info.http_method
165
- when :GET
166
- request = @client.build_request(:get)
167
- when :POST
168
- request = @client.build_request(:post)
169
- when :PATCH
170
- request = @client.build_request(:patch)
171
- when :DELETE
172
- request = @client.build_request(:delete)
173
- when :OPTIONS
174
- request = @client.build_request(:options)
175
- when :CONNECT
176
- request = @client.build_request(:connect)
177
- when :PUT
178
- request = @client.build_request(:put)
179
- when :TRACE
180
- request = @client.build_request(:trace)
181
- when :HEAD
182
- request = @client.build_request(:head)
171
+ when :GET, :POST, :PATCH, :DELETE, :OPTIONS, :CONNECT, :PUT, :TRACE, :HEAD, :QUERY
172
+ request = @client.build_request(request_info.http_method.downcase)
183
173
  else
184
174
  raise StandardError, 'unsupported http method'
185
175
  end
@@ -196,8 +186,7 @@ module MicrosoftKiotaFaraday
196
186
  end
197
187
  end
198
188
  end
199
- request.body = request_info.content unless request_info.content.nil? || request_info.content.empty?
200
- # 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)
201
190
  request_options = request_info.get_request_options
202
191
  if !request_options.nil? && !request_options.empty?
203
192
  request.options = Faraday::RequestOptions.new if request.options.nil?
@@ -229,5 +218,14 @@ module MicrosoftKiotaFaraday
229
218
  def set_base_url_for_request_information(request_info)
230
219
  request_info.path_parameters['baseurl'] = @base_url
231
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
232
230
  end
233
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.22.0' # x-release-please-version
4
+ VERSION = '0.24.0' # 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.22.0
4
+ version: 0.24.0
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.22.0
38
+ version: 0.24.0
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.22.0
45
+ version: 0.24.0
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/