class Halite::Options

Overview

Options class

Init with splats options

o = Options.new(
  headers: {
    user_agent: "foobar"
  }
}
o.headers.class # => HTTP::Headers
o.cookies.class # => HTTP::Cookies

Set/Get timeout

Set it with #connect_timeout/#read_timeout/#write_timeout keys, but get it call Timeout class.

o = Options.new(connect_timeout: 30, read_timeout: 30)
o.timeout.connect # => 30.0
o.timeout.read    # => 30.0
o.timeout.write   # => nil

Set/Get follow

Set it with #follow/#follow_strict keys, but get it call Follow class.

o = Options.new(follow: 3, follow_strict: false)
o.follow.hops   # => 3
o.follow.strict # => false

Defined in:

halite/options.cr
halite/options/follow.cr
halite/options/timeout.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(options : Halite::Options) #

def self.new(endpoint : String | URI? = nil, headers : Hash(String, _) | NamedTuple? = nil, cookies : Hash(String, _) | NamedTuple? = nil, params : Hash(String, _) | NamedTuple? = nil, form : Hash(String, _) | NamedTuple? = nil, json : Hash(String, _) | NamedTuple? = nil, raw : String? = nil, connect_timeout : Int32 | Float64 | Time::Span? = nil, read_timeout : Int32 | Float64 | Time::Span? = nil, write_timeout : Int32 | Float64 | Time::Span? = nil, follow : Int32? = nil, follow_strict : Bool? = nil, tls : OpenSSL::SSL::Context::Client? = nil, features = {} of String => Feature) #

def self.new(*, endpoint : String | URI? = nil, headers : Hash(String, _) | NamedTuple? = nil, cookies : Hash(String, _) | NamedTuple? = nil, params : Hash(String, _) | NamedTuple? = nil, form : Hash(String, _) | NamedTuple? = nil, json : Hash(String, _) | NamedTuple? = nil, raw : String? = nil, timeout = Timeout.new, follow = Follow.new, tls : OpenSSL::SSL::Context::Client? = nil, features = {} of String => Feature) #

def self.new(*, endpoint : URI?, headers : HTTP::Headers, cookies : HTTP::Cookies, params : Hash(String, Type), form : Hash(String, Type), json : Hash(String, Type), raw : String? = nil, timeout = Timeout.new, follow = Follow.new, tls : OpenSSL::SSL::Context::Client? = nil, features = {} of String => Feature) #

Instance Method Detail

def clear! : Halite::Options #

Reset options


def connect_timeout #

def connect_timeout=(timeout : Int32 | Float64 | Time::Span) #

def cookies : HTTP::Cookies #

def cookies=(cookies : HTTP::Cookies) #

def dup #

Produces a shallow copy of obj—the instance variables of obj are copied, but not the objects they reference. dup copies the tainted state of obj.


def endpoint : URI? #

def endpoint=(endpoint : URI?) #

def endpoint=(endpoint : String) #

Set endpoint of request


def features : Hash(String, Feature) #

def features=(features : Hash(String, Feature)) #

def follow : Follow #

def follow=(follow : Follow) #

def follow=(hops : Int32) #

Alias Follow.hops=


def follow_strict #

def follow_strict=(strict : Bool) #

def form : Hash(String, Type) #

def form=(form : Hash(String, Type)) #

def headers : HTTP::Headers #

def headers=(headers : HTTP::Headers) #

def headers=(headers : Hash(String, _) | NamedTuple) #

Set headers of request


def json : Hash(String, Type) #

def json=(json : Hash(String, Type)) #

def logging : Bool #

Get logging status


def logging=(enable : Bool) #

Quick enable logging

By defaults, use Logging::Common as logging output.


def merge(other : Halite::Options) : Halite::Options #

Merge with other Options and return new Halite::Options


def merge!(other : Halite::Options) : Halite::Options #

Merge with other Options and return self


def params : Hash(String, Type) #

def params=(params : Hash(String, Type)) #

def raw : String? #

def raw=(raw : String?) #

def read_timeout #

Alias Timeout.read


def read_timeout=(timeout : Int32 | Float64 | Time::Span) #

def timeout : Timeout #

def timeout=(timeout : Timeout) #

def tls : OpenSSL::SSL::Context::Client? #

def tls=(tls : OpenSSL::SSL::Context::Client?) #

def to_h #

Returns this collection as a plain Hash.


def with_cookies(cookies : Hash(String, _) | NamedTuple) : Halite::Options #

Returns Options self with given cookies combined.


def with_cookies(cookies : HTTP::Cookies) : Halite::Options #

Returns Options self with given cookies combined.


def with_cookies(cookie : HTTP::Cookie) : Halite::Options #

Returns Options self with given cookies combined.


def with_cookies(**cookies) : Halite::Options #

Alias #with_cookies method.


def with_endpoint(endpoint : String | URI) #

def with_features(name : String, opts : NamedTuple) #

Returns Options self with feature name and options.


def with_features(name : String, feature : Feature) #

Returns Options self with feature name and feature.


def with_features(*features) #

Returns Options self with the name of features.


def with_features(feature_name : String, **opts) #

Returns Options self with feature name and options.


def with_follow(follow = Follow::MAX_HOPS, strict = Follow::STRICT) : Halite::Options #

Returns Options self with given max hops of redirect times.

# Automatically following redirects
options.with_follow
# A maximum of 3 subsequent redirects
options.with_follow(3)
# Set subsequent redirects
options.with_follow(3)

def with_headers(headers : Hash(String, _) | NamedTuple) : Halite::Options #

Returns Options self with given headers combined.


def with_headers(**with_headers) : Halite::Options #

Alias #with_headers method.


def with_logging(logging : Halite::Logging::Abstract) #

Returns Options self with given logging, depend on #with_features.


def with_logging(format : String, **opts) #

Returns Options iitself with given format and the options of format.


def with_timeout(connect : Int32 | Float64 | Time::Span? = nil, read : Int32 | Float64 | Time::Span? = nil, write : Int32 | Float64 | Time::Span? = nil) : Halite::Options #

Returns Options self with given connect, read timeout.


def write_timeout #

def write_timeout=(timeout : Int32 | Float64 | Time::Span) #