-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2109 from microsoft/feature/ruby-multi-valued-header
- adds support for multi-valued header in Ruby
- Loading branch information
Showing
14 changed files
with
125 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ons/ruby/microsoft_kiota_abstractions/lib/microsoft_kiota_abstractions/request_headers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module MicrosoftKiotaAbstractions | ||
class RequestHeaders | ||
def initialize() | ||
@headers = Hash.new | ||
end | ||
def add(key, value) | ||
if key.nil? || key.empty? || value.nil? || value.empty? then | ||
raise ArgumentError, 'key and value cannot be nil or empty' | ||
end | ||
existing_value = @headers[key] | ||
if existing_value.nil? then | ||
if value.kind_of?(Array) then | ||
@headers[key] = value | ||
else | ||
@headers[key] = Array[value.to_s] | ||
end | ||
else | ||
if value.kind_of?(Array) then | ||
@headers[key] = existing_value | value | ||
else | ||
existing_value << value.to_s | ||
end | ||
end | ||
end | ||
def get(key) | ||
if key.nil? || key.empty? then | ||
raise ArgumentError, 'key cannot be nil or empty' | ||
end | ||
return @headers[key] | ||
end | ||
def remove(key) | ||
if key.nil? || key.empty? then | ||
raise ArgumentError, 'key cannot be nil or empty' | ||
end | ||
@headers.delete(key) | ||
end | ||
def clear() | ||
@headers.clear() | ||
end | ||
def get_all() | ||
return @headers | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
abstractions/ruby/microsoft_kiota_abstractions/lib/microsoft_kiota_abstractions/version.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module MicrosoftKiotaAbstractions | ||
VERSION = "0.10.0" | ||
VERSION = "0.11.0" | ||
end |
42 changes: 42 additions & 0 deletions
42
abstractions/ruby/microsoft_kiota_abstractions/spec/request_headers_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'microsoft_kiota_abstractions' | ||
RSpec.describe MicrosoftKiotaAbstractions do | ||
it "adds a request header to the request information" do | ||
request_info = MicrosoftKiotaAbstractions::RequestInformation.new | ||
request_info.headers.add("key", "value") | ||
expect(request_info.headers.get_all.length).to eq(1) | ||
expect(request_info.headers.get("key").length).to eq(1) | ||
expect(request_info.headers.get("key").first).to eq("value") | ||
end | ||
|
||
it "adds a request header to the request information when one value is already present" do | ||
request_info = MicrosoftKiotaAbstractions::RequestInformation.new | ||
request_info.headers.add("key", "value") | ||
request_info.headers.add("key", "value2") | ||
expect(request_info.headers.get_all.length).to eq(1) | ||
expect(request_info.headers.get("key").length).to eq(2) | ||
expect(request_info.headers.get("key").first).to eq("value") | ||
expect(request_info.headers.get("key").last).to eq("value2") | ||
end | ||
|
||
it "removes a request header from the request information" do | ||
request_info = MicrosoftKiotaAbstractions::RequestInformation.new | ||
request_info.headers.add("key", "value") | ||
expect(request_info.headers.get_all.length).to eq(1) | ||
request_info.headers.remove("key") | ||
expect(request_info.headers.get_all.length).to eq(0) | ||
end | ||
|
||
it "doesnt fail when removing a value if none are present" do | ||
request_info = MicrosoftKiotaAbstractions::RequestInformation.new | ||
request_info.headers.remove("key") | ||
expect(request_info.headers.get_all.length).to eq(0) | ||
end | ||
|
||
it "clears the request headers from the request information" do | ||
request_info = MicrosoftKiotaAbstractions::RequestInformation.new | ||
request_info.headers.add("key", "value") | ||
expect(request_info.headers.get_all.length).to eq(1) | ||
request_info.headers.clear | ||
expect(request_info.headers.get_all.length).to eq(0) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
http/ruby/faraday/microsoft_kiota_faraday/lib/microsoft_kiota_faraday/version.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module MicrosoftKiotaFaraday | ||
VERSION = '0.7.0' | ||
VERSION = '0.8.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters