Class: MicrosoftKiotaAbstractions::RequestHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/microsoft_kiota_abstractions/request_headers.rb

Instance Method Summary collapse

Constructor Details

#initializeRequestHeaders

Returns a new instance of RequestHeaders.



3
4
5
# File 'lib/microsoft_kiota_abstractions/request_headers.rb', line 3

def initialize()
    @headers = Hash.new
end

Instance Method Details

#add(key, value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/microsoft_kiota_abstractions/request_headers.rb', line 6

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

#clearObject



49
50
51
# File 'lib/microsoft_kiota_abstractions/request_headers.rb', line 49

def clear()
    @headers.clear()
end

#get(key) ⇒ Object



37
38
39
40
41
42
# File 'lib/microsoft_kiota_abstractions/request_headers.rb', line 37

def get(key)
    if key.nil? || key.empty? then
      raise ArgumentError, 'key cannot be nil or empty'
    end
    return @headers[key]
end

#get_allObject



52
53
54
# File 'lib/microsoft_kiota_abstractions/request_headers.rb', line 52

def get_all()
    return @headers
end

#remove(key) ⇒ Object



43
44
45
46
47
48
# File 'lib/microsoft_kiota_abstractions/request_headers.rb', line 43

def remove(key)
    if key.nil? || key.empty? then
      raise ArgumentError, 'key cannot be nil or empty'
    end
    @headers.delete(key)
end

#try_add(key, value) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/microsoft_kiota_abstractions/request_headers.rb', line 25

def try_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? || existing_value.empty? then
    @headers[key] = Array[value.to_s]
    return true
  else
    return false
  end
end