class KisHttp::Headers

A header builder class for outgoing requests

Public Class Methods

new(args = {}) click to toggle source
# File lib/kis_http/headers.rb, line 19
def initialize(args = {})
  build(args)
end

Public Instance Methods

+(other) click to toggle source

Add the values of one `Headers` into another

@param other [Headers] instance of `Headers` @return [Headers]

# File lib/kis_http/headers.rb, line 57
def +(other)
  raise TypeError, "Headers type expected, #{other.class} given" \
    unless other.is_a? Headers

  @heads.merge(other.instance_variable_get(:@heads))

  self
end
assign_each_to(obj) click to toggle source

Assign each header to object via :[]

# File lib/kis_http/headers.rb, line 37
def assign_each_to(obj)
  each_pair do |header, value|
    obj[header] = value
  end

  obj
end
build(args = {}) click to toggle source

Add or update the request headers

@return [Headers] self

# File lib/kis_http/headers.rb, line 26
def build(args = {})
  @heads ||= {}

  args.to_h.each do |(key, value)|
    @heads[key] = value
  end

  self
end
remove(key) click to toggle source

Remove key/value from headers via key

@param key [Symbol, String] key to look up @return [String, Symbol, nil] returns value if key found, `nil` otherwise.

# File lib/kis_http/headers.rb, line 49
def remove(key)
  @heads.delete(key)
end
to_h() click to toggle source

@return [Hash] hash of the `Headers`

# File lib/kis_http/headers.rb, line 67
def to_h
  @heads
end