class Vonage::HTTP::Options

Public Class Methods

new(hash) click to toggle source
# File lib/vonage/http.rb, line 11
def initialize(hash)
  raise ArgumentError, 'hash parameter cannot be empty or nil' if hash == {} || hash.nil?

  @hash = T.let(@hash, T::Hash[Symbol, T.untyped]) if defined? @hash
  @hash = hash

  @hash.each_key do |name|
    next if defined_options.key?(name)

    raise ArgumentError, "#{name.inspect} is not a valid option"
  end
end

Public Instance Methods

set(http) click to toggle source
# File lib/vonage/http.rb, line 25
def set(http)
  @hash.each do |name, value|
    http.public_send(defined_options.fetch(name), value)
  end
end

Private Instance Methods

defined_options() click to toggle source
# File lib/vonage/http.rb, line 34
def defined_options
  @defined_options = T.let(@defined_options, T.nilable(T::Hash[Symbol, T.untyped]))

  @defined_options ||= Net::HTTP.instance_methods.grep(/\w=\z/).each_with_object({}) do |name, hash|
    hash[name.to_s.chomp('=').to_sym] = name
  end
end