microsoft_kiota_faraday 0.16.0 → 0.18.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 +4 -4
- data/Gemfile +3 -1
- data/Rakefile +0 -2
- data/lib/microsoft_kiota_faraday/faraday_request_adapter.rb +78 -67
- data/lib/microsoft_kiota_faraday/kiota_client_factory.rb +30 -29
- data/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_handler.rb +26 -24
- data/lib/microsoft_kiota_faraday/middleware/parameters_name_decoding_option.rb +15 -13
- data/lib/microsoft_kiota_faraday/middleware/response_handler_option.rb +11 -9
- data/lib/microsoft_kiota_faraday/middleware/user_agent_handler.rb +25 -21
- data/lib/microsoft_kiota_faraday/middleware/user_agent_option.rb +18 -15
- data/lib/microsoft_kiota_faraday/version.rb +1 -1
- data/microsoft_kiota_faraday.gemspec +13 -14
- metadata +22 -49
- data/.github/CODEOWNERS +0 -1
- data/.github/copilot-instructions.md +0 -25
- data/.github/dependabot.yml +0 -12
- data/.github/policies/kiota-http-ruby-branch-protection.yml +0 -40
- data/.github/policies/resourceManagement.yml +0 -101
- data/.github/release-please.yml +0 -3
- data/.github/workflows/auto-merge-dependabot.yml +0 -33
- data/.github/workflows/code-ql.yml +0 -77
- data/.github/workflows/conflicting-pr-label.yml +0 -39
- data/.github/workflows/release-please-gha.yml +0 -49
- data/.github/workflows/release.yml +0 -36
- data/.github/workflows/ruby.yml +0 -48
- data/.gitignore +0 -58
- data/.release-please-manifest.json +0 -3
- data/CHANGELOG.md +0 -69
- data/CODE_OF_CONDUCT.md +0 -10
- data/CONTRIBUTING.md +0 -56
- data/LICENSE +0 -21
- data/README.md +0 -51
- data/SECURITY.md +0 -41
- data/SUPPORT.md +0 -25
- data/release-please-config.json +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 717b22f6f3562793465d61ebe8bf88d2909d2d1fbd5b4e47729c85ac9e469b3e
|
|
4
|
+
data.tar.gz: 22fdfebc5bd4e55f98a3de55dda86bc4f5792a4729d3bc14b797d4cf1bd32185
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9edb2dcd5e4ac1bc7f72b24c46b5518e3b03c55e1bceeeea067df407e6caf35cc123c38cadabdefeb20b4e6c53e42e27ddb344101b277e569a6301107379f73a
|
|
7
|
+
data.tar.gz: adb0de7e99832ffbd896ba00662dbd4d2b2b9b9f6d5f66c8c1b56ef23d2b2927b7a07255fe372eaa983e0b7a5f059f99068cc048181be6bcfd40b75447c9a238
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'microsoft_kiota_abstractions'
|
|
2
4
|
require 'faraday'
|
|
3
5
|
require 'net/http'
|
|
@@ -8,13 +10,13 @@ module MicrosoftKiotaFaraday
|
|
|
8
10
|
class FaradayRequestAdapter
|
|
9
11
|
include MicrosoftKiotaAbstractions::RequestAdapter
|
|
10
12
|
|
|
11
|
-
attr_accessor :authentication_provider, :content_type_header_key, :parse_node_factory,
|
|
13
|
+
attr_accessor :authentication_provider, :content_type_header_key, :parse_node_factory,
|
|
14
|
+
:serialization_writer_factory, :client
|
|
12
15
|
|
|
13
|
-
def initialize(authentication_provider,
|
|
16
|
+
def initialize(authentication_provider,
|
|
17
|
+
parse_node_factory = MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance, serialization_writer_factory = MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance, client = KiotaClientFactory.get_default_http_client)
|
|
18
|
+
raise StandardError, 'authentication provider cannot be null' unless authentication_provider
|
|
14
19
|
|
|
15
|
-
if !authentication_provider
|
|
16
|
-
raise StandardError , 'authentication provider cannot be null'
|
|
17
|
-
end
|
|
18
20
|
@authentication_provider = authentication_provider
|
|
19
21
|
@content_type_header_key = 'Content-Type'
|
|
20
22
|
@parse_node_factory = parse_node_factory
|
|
@@ -26,9 +28,7 @@ module MicrosoftKiotaFaraday
|
|
|
26
28
|
@serialization_writer_factory = MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance
|
|
27
29
|
end
|
|
28
30
|
@client = client
|
|
29
|
-
if @client.nil?
|
|
30
|
-
@client = KiotaClientFactory::get_default_http_client
|
|
31
|
-
end
|
|
31
|
+
@client = KiotaClientFactory.get_default_http_client if @client.nil?
|
|
32
32
|
@base_url = ''
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -36,11 +36,11 @@ module MicrosoftKiotaFaraday
|
|
|
36
36
|
@base_url = base_url
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def get_base_url
|
|
39
|
+
def get_base_url
|
|
40
40
|
@base_url
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def get_serialization_writer_factory
|
|
43
|
+
def get_serialization_writer_factory
|
|
44
44
|
@serialization_writer_factory
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -51,89 +51,101 @@ module MicrosoftKiotaFaraday
|
|
|
51
51
|
Fiber.new do
|
|
52
52
|
set_base_url_for_request_information(request_info)
|
|
53
53
|
@authentication_provider.authenticate_request(request_info).resume
|
|
54
|
-
request =
|
|
54
|
+
request = get_request_from_request_info(request_info)
|
|
55
55
|
response = @client.run_request(request.http_method, request.path, request.body, request.headers)
|
|
56
56
|
|
|
57
|
-
response_handler =
|
|
58
|
-
response_handler
|
|
59
|
-
|
|
60
|
-
root_node =
|
|
57
|
+
response_handler = get_response_handler(request_info)
|
|
58
|
+
response_handler&.call(response)&.resume
|
|
59
|
+
throw_if_failed_reponse(response, errors_mapping)
|
|
60
|
+
root_node = get_root_parse_node(response)
|
|
61
61
|
root_node.get_object_value(factory)
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def get_response_handler(request_info)
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
unless request_info.nil?
|
|
67
|
+
option = request_info.get_request_option(MicrosoftKiotaFaraday::Middleware::ResponseHandlerOption::RESPONSE_HANDLER_KEY)
|
|
68
|
+
end
|
|
69
|
+
option.async_callback unless !option || option.nil?
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
def get_root_parse_node(response)
|
|
71
73
|
raise StandardError, 'response cannot be null' unless response
|
|
72
|
-
|
|
74
|
+
|
|
75
|
+
response_content_type = get_response_content_type(response)
|
|
73
76
|
raise StandardError, 'no response content type found for deserialization' unless response_content_type
|
|
74
77
|
return if response.body.nil? || response.body.empty?
|
|
75
|
-
|
|
78
|
+
|
|
79
|
+
@parse_node_factory.get_parse_node(response_content_type, response.body)
|
|
76
80
|
end
|
|
77
81
|
|
|
78
82
|
def throw_if_failed_reponse(response, errors_mapping)
|
|
79
83
|
raise StandardError, 'response cannot be null' unless response
|
|
80
84
|
|
|
81
|
-
status_code = response.status
|
|
82
|
-
if status_code < 400
|
|
83
|
-
|
|
84
|
-
end
|
|
85
|
+
status_code = response.status
|
|
86
|
+
return if status_code < 400
|
|
87
|
+
|
|
85
88
|
error_factory = errors_mapping[status_code] unless errors_mapping.nil?
|
|
86
89
|
error_factory = errors_mapping['4XX'] unless !error_factory.nil? || errors_mapping.nil? || status_code > 500
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
unless !error_factory.nil? || errors_mapping.nil? || status_code < 500 || status_code > 600
|
|
91
|
+
error_factory = errors_mapping['5XX']
|
|
92
|
+
end
|
|
93
|
+
unless !error_factory.nil? || errors_mapping.nil? || status_code < 400 || status_code > 600
|
|
94
|
+
error_factory = errors_mapping['XXX']
|
|
95
|
+
end
|
|
96
|
+
if error_factory.nil?
|
|
97
|
+
raise MicrosoftKiotaAbstractions::ApiError,
|
|
98
|
+
"The server returned an unexpected status code and no error factory is registered for this code:#{status_code}"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
root_node = get_root_parse_node(response)
|
|
91
102
|
error = root_node.get_object_value(error_factory) unless root_node.nil?
|
|
92
103
|
raise error unless error.nil?
|
|
93
|
-
|
|
104
|
+
|
|
105
|
+
raise MicrosoftKiotaAbstractions::ApiError, "The server returned an unexpected status code:#{status_code}"
|
|
94
106
|
end
|
|
95
107
|
|
|
96
108
|
def get_request_from_request_info(request_info)
|
|
97
109
|
set_base_url_for_request_information(request_info)
|
|
98
110
|
case request_info.http_method
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
when :GET
|
|
112
|
+
request = @client.build_request(:get)
|
|
113
|
+
when :POST
|
|
114
|
+
request = @client.build_request(:post)
|
|
115
|
+
when :PATCH
|
|
116
|
+
request = @client.build_request(:patch)
|
|
117
|
+
when :DELETE
|
|
118
|
+
request = @client.build_request(:delete)
|
|
119
|
+
when :OPTIONS
|
|
120
|
+
request = @client.build_request(:options)
|
|
121
|
+
when :CONNECT
|
|
122
|
+
request = @client.build_request(:connect)
|
|
123
|
+
when :PUT
|
|
124
|
+
request = @client.build_request(:put)
|
|
125
|
+
when :TRACE
|
|
126
|
+
request = @client.build_request(:trace)
|
|
127
|
+
when :HEAD
|
|
128
|
+
request = @client.build_request(:head)
|
|
129
|
+
else
|
|
130
|
+
raise StandardError, 'unsupported http method'
|
|
119
131
|
end
|
|
120
132
|
request.path = request_info.uri
|
|
121
|
-
unless request_info.headers.nil?
|
|
133
|
+
unless request_info.headers.nil?
|
|
122
134
|
request.headers = Faraday::Utils::Headers.new
|
|
123
|
-
request_info.headers.get_all.select
|
|
124
|
-
if v.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
request_info.headers.get_all.select do |k, v|
|
|
136
|
+
request.headers[k] = if v.is_a? Array
|
|
137
|
+
v.join(',')
|
|
138
|
+
elsif v.is_a? String
|
|
139
|
+
v
|
|
140
|
+
else
|
|
141
|
+
v.to_s
|
|
142
|
+
end
|
|
143
|
+
end
|
|
132
144
|
end
|
|
133
145
|
request.body = request_info.content unless request_info.content.nil? || request_info.content.empty?
|
|
134
|
-
# TODO the json serialization writer returns a string at the moment, change to body_stream when this is fixed
|
|
146
|
+
# TODO: the json serialization writer returns a string at the moment, change to body_stream when this is fixed
|
|
135
147
|
request_options = request_info.get_request_options
|
|
136
|
-
if !request_options.nil? && !request_options.empty?
|
|
148
|
+
if !request_options.nil? && !request_options.empty?
|
|
137
149
|
request.options = Faraday::RequestOptions.new if request.options.nil?
|
|
138
150
|
request_options.each do |value|
|
|
139
151
|
request.options.context[value.get_key] = value
|
|
@@ -143,19 +155,18 @@ module MicrosoftKiotaFaraday
|
|
|
143
155
|
end
|
|
144
156
|
|
|
145
157
|
def get_response_content_type(response)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return nil
|
|
150
|
-
end
|
|
158
|
+
response.headers['content-type'].split(';')[0].downcase
|
|
159
|
+
rescue StandardError
|
|
160
|
+
nil
|
|
151
161
|
end
|
|
152
162
|
|
|
153
163
|
def convert_to_native_request_async(request_info)
|
|
154
164
|
raise StandardError, 'request_info cannot be null' unless request_info
|
|
155
|
-
|
|
165
|
+
|
|
166
|
+
Fiber.new do
|
|
156
167
|
set_base_url_for_request_information(request_info)
|
|
157
168
|
@authentication_provider.authenticate_request(request_info).resume
|
|
158
|
-
return
|
|
169
|
+
return get_request_from_request_info(request_info)
|
|
159
170
|
end
|
|
160
171
|
end
|
|
161
172
|
|
|
@@ -1,37 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'net/https'
|
|
2
4
|
require 'faraday'
|
|
3
5
|
require_relative 'middleware/parameters_name_decoding_handler'
|
|
4
6
|
require_relative 'middleware/user_agent_handler'
|
|
5
7
|
module MicrosoftKiotaFaraday
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
class KiotaClientFactory
|
|
9
|
+
def self.get_default_middleware
|
|
10
|
+
[
|
|
11
|
+
MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler,
|
|
12
|
+
MicrosoftKiotaFaraday::Middleware::UserAgentHandler
|
|
13
|
+
]
|
|
14
|
+
end
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
conn
|
|
16
|
+
def self.get_default_http_client(middleware = nil, default_middleware_options = [])
|
|
17
|
+
if middleware.nil? # empty is fine in case the user doesn't want to use any middleware
|
|
18
|
+
middleware = get_default_middleware
|
|
19
|
+
end
|
|
20
|
+
connection_options = {}
|
|
21
|
+
connection_options[:request] = {}
|
|
22
|
+
connection_options[:request][:context] = {}
|
|
23
|
+
unless default_middleware_options.nil? || default_middleware_options.empty?
|
|
24
|
+
default_middleware_options.each do |value|
|
|
25
|
+
connection_options[:request][:context][value.get_key] = value
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
Faraday::Connection.new(nil, connection_options) do |builder|
|
|
29
|
+
builder.adapter Faraday.default_adapter
|
|
30
|
+
builder.ssl.verify = true
|
|
31
|
+
builder.ssl.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
32
|
+
middleware.each do |handler|
|
|
33
|
+
builder.use handler
|
|
35
34
|
end
|
|
35
|
+
end
|
|
36
36
|
end
|
|
37
|
-
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'faraday'
|
|
2
4
|
require_relative 'parameters_name_decoding_option'
|
|
3
5
|
module MicrosoftKiotaFaraday
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
unless request_env[:url].nil? || !request_option.enabled || request_option.characters_to_decode.nil? || request_option.characters_to_decode.empty? then
|
|
11
|
-
request_url = request_env[:url].to_s
|
|
12
|
-
request_option.characters_to_decode.each do |character|
|
|
13
|
-
request_url = request_url.gsub(get_regex_for_character(character), character)
|
|
14
|
-
end
|
|
15
|
-
request_env[:url] = URI.parse(request_url)
|
|
16
|
-
end
|
|
17
|
-
@app.call(request_env) unless @app.nil?
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def get_regex_for_character(character)
|
|
21
|
-
@regex_cache ||= Hash.new
|
|
22
|
-
if @regex_cache[character].nil? then
|
|
23
|
-
@regex_cache[character] = Regexp.new("%#{character.ord.to_s(16)}", true)
|
|
24
|
-
end
|
|
25
|
-
return @regex_cache[character]
|
|
26
|
-
end
|
|
6
|
+
module Middleware
|
|
7
|
+
class ParametersNameDecodingHandler < Faraday::Middleware
|
|
8
|
+
@@default_option = ParametersNameDecodingOption.new
|
|
9
|
+
def call(request_env)
|
|
10
|
+
unless request_env[:request].nil? || request_env[:request][:context].nil?
|
|
11
|
+
request_option = request_env[:request][:context][@@default_option.get_key]
|
|
27
12
|
end
|
|
13
|
+
request_option = @@default_option if request_option.nil?
|
|
14
|
+
unless request_env[:url].nil? || !request_option.enabled || request_option.characters_to_decode.nil? || request_option.characters_to_decode.empty?
|
|
15
|
+
request_url = request_env[:url].to_s
|
|
16
|
+
request_option.characters_to_decode.each do |character|
|
|
17
|
+
request_url = request_url.gsub(get_regex_for_character(character), character)
|
|
18
|
+
end
|
|
19
|
+
request_env[:url] = URI.parse(request_url)
|
|
20
|
+
end
|
|
21
|
+
@app&.call(request_env)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def get_regex_for_character(character)
|
|
25
|
+
@regex_cache ||= {}
|
|
26
|
+
@regex_cache[character] = Regexp.new("%#{character.ord.to_s(16)}", true) if @regex_cache[character].nil?
|
|
27
|
+
@regex_cache[character]
|
|
28
|
+
end
|
|
28
29
|
end
|
|
29
|
-
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'microsoft_kiota_abstractions'
|
|
3
4
|
module MicrosoftKiotaFaraday
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
module Middleware
|
|
6
|
+
class ParametersNameDecodingOption
|
|
7
|
+
include MicrosoftKiotaAbstractions::RequestOption
|
|
8
|
+
|
|
9
|
+
attr_accessor :enabled, :characters_to_decode
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
def initialize(enabled = true, characters_to_decode = ['$', '.', '-', '~'])
|
|
12
|
+
@enabled = enabled
|
|
13
|
+
@characters_to_decode = characters_to_decode
|
|
14
|
+
end
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
16
|
+
def get_key
|
|
17
|
+
'parametersNameDecoding'
|
|
18
|
+
end
|
|
18
19
|
end
|
|
19
|
-
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'microsoft_kiota_abstractions'
|
|
3
4
|
module MicrosoftKiotaFaraday
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
module Middleware
|
|
6
|
+
class ResponseHandlerOption
|
|
7
|
+
RESPONSE_HANDLER_KEY = 'responseHandler'
|
|
8
|
+
# a lambda that takes the native response type and returns a Fiber with a MicrosoftKiotaAbstractions::Parsable
|
|
9
|
+
attr_accessor :async_callback
|
|
10
|
+
|
|
11
|
+
def get_key
|
|
12
|
+
RESPONSE_HANDLER_KEY
|
|
13
|
+
end
|
|
13
14
|
end
|
|
15
|
+
end
|
|
14
16
|
end
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'faraday'
|
|
2
4
|
require_relative 'user_agent_option'
|
|
3
5
|
module MicrosoftKiotaFaraday
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end
|
|
6
|
+
module Middleware
|
|
7
|
+
class UserAgentHandler < Faraday::Middleware
|
|
8
|
+
@@default_option = UserAgentOption.new
|
|
9
|
+
@@user_agent_key = 'User-Agent'
|
|
10
|
+
def call(request_env)
|
|
11
|
+
unless request_env[:request].nil? || request_env[:request][:context].nil?
|
|
12
|
+
request_option = request_env[:request][:context][@@default_option.get_key]
|
|
13
|
+
end
|
|
14
|
+
request_option = @@default_option if request_option.nil?
|
|
15
|
+
unless request_env[:request_headers].nil? || !request_option.enabled || request_option.product_name.nil? || request_option.product_name.empty? || request_option.product_version.nil? || request_option.product_version.empty?
|
|
16
|
+
existing_value = request_env[:request_headers][@@user_agent_key]
|
|
17
|
+
additional_value = "#{request_option.product_name}/#{request_option.product_version}"
|
|
18
|
+
if !existing_value || existing_value.empty?
|
|
19
|
+
request_env[:request_headers][@@user_agent_key] = additional_value
|
|
20
|
+
elsif !existing_value.include? additional_value
|
|
21
|
+
request_env[:request_headers][@@user_agent_key] = "#{existing_value} #{additional_value}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
@app&.call(request_env)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'microsoft_kiota_abstractions'
|
|
3
|
-
require_relative '../version
|
|
4
|
+
require_relative '../version'
|
|
4
5
|
module MicrosoftKiotaFaraday
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
module Middleware
|
|
7
|
+
class UserAgentOption
|
|
8
|
+
include MicrosoftKiotaAbstractions::RequestOption
|
|
9
|
+
|
|
10
|
+
attr_accessor :enabled, :product_name, :product_version
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@enabled = true
|
|
14
|
+
@product_name = 'kiota-ruby'
|
|
15
|
+
@product_version = MicrosoftKiotaFaraday::VERSION
|
|
16
|
+
end
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
def get_key
|
|
19
|
+
'userAgent'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
20
23
|
end
|
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
3
|
+
require_relative 'lib/microsoft_kiota_faraday/version'
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name =
|
|
6
|
+
spec.name = 'microsoft_kiota_faraday'
|
|
7
7
|
spec.version = MicrosoftKiotaFaraday::VERSION
|
|
8
8
|
spec.authors = 'Microsoft Corporation'
|
|
9
9
|
spec.email = 'graphsdkpub+ruby@microsoft.com'
|
|
10
10
|
spec.description = 'Kiota HttpCore implementation with Faraday'
|
|
11
|
-
spec.summary =
|
|
12
|
-
spec.homepage = 'https://microsoft.
|
|
11
|
+
spec.summary = 'Microsoft Kiota Faraday - Kiota Ruby http request adapter for running requests'
|
|
12
|
+
spec.homepage = 'https://learn.microsoft.com/openapi/kiota/'
|
|
13
13
|
spec.license = 'MIT'
|
|
14
14
|
spec.metadata = {
|
|
15
|
-
'bug_tracker_uri' => 'https://github.com/microsoft/kiota-
|
|
16
|
-
'changelog_uri'
|
|
17
|
-
'homepage_uri'
|
|
18
|
-
'source_code_uri' => 'https://github.com/microsoft/kiota-http
|
|
19
|
-
'github_repo'
|
|
15
|
+
'bug_tracker_uri' => 'https://github.com/microsoft/kiota-ruby/issues',
|
|
16
|
+
'changelog_uri' => 'https://github.com/microsoft/kiota-ruby/blob/main/CHANGELOG.md',
|
|
17
|
+
'homepage_uri' => spec.homepage,
|
|
18
|
+
'source_code_uri' => 'https://github.com/microsoft/kiota-ruby/tree/main/components/http',
|
|
19
|
+
'github_repo' => 'ssh://github.com/microsoft/kiota-ruby',
|
|
20
|
+
'rubygems_mfa_required' => 'true'
|
|
20
21
|
}
|
|
21
|
-
spec.required_ruby_version =
|
|
22
|
+
spec.required_ruby_version = '>= 3.3.0'
|
|
22
23
|
|
|
23
|
-
# Specify which files should be added to the gem when it is released.
|
|
24
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
24
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
26
25
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
27
26
|
end
|
|
28
27
|
spec.bindir = 'bin'
|
|
29
28
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
29
|
spec.require_paths = ['lib']
|
|
31
|
-
spec.
|
|
32
|
-
spec.
|
|
30
|
+
spec.add_dependency 'faraday', '~> 2.7', '>= 2.7.2'
|
|
31
|
+
spec.add_dependency 'microsoft_kiota_abstractions', MicrosoftKiotaFaraday::VERSION
|
|
33
32
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
34
33
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
35
34
|
spec.add_development_dependency 'rubocop'
|