class Trav3::Headers

A header builder class for outgoing requests

Public Class Methods

new(args = {}) click to toggle source
# File lib/trav3/headers.rb, line 18
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/trav3/headers.rb, line 47
def +(other)
  raise TypeError, "Headers type expected, #{other.class} given" unless other.is_a? Headers

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

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

Add or update the request headers

@return [Headers] self

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

  args.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/trav3/headers.rb, line 39
def remove(key)
  @heads.delete(key)
end
to_h() click to toggle source

@return [Hash] hash of the `Headers`

# File lib/trav3/headers.rb, line 56
def to_h
  @heads
end