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) #

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

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

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

[View source]

Instance Method Detail

def clear! : Halite::Options #

Reset options


[View source]
def connect_timeout #

[View source]
def connect_timeout=(timeout : Int32 | Float64 | Time::Span) #

[View source]
def cookies : HTTP::Cookies #

[View source]
def cookies=(cookies : HTTP::Cookies) #

[View source]
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.


[View source]
def endpoint : URI | Nil #

[View source]
def endpoint=(endpoint : URI | Nil) #

[View source]
def endpoint=(endpoint : String) #

Set endpoint of request


[View source]
def features : Hash(String, Feature) #

[View source]
def features=(features : Hash(String, Feature)) #

[View source]
def follow : Follow #

[View source]
def follow=(follow : Follow) #

[View source]
def follow=(hops : Int32) #

Alias Follow.hops=


[View source]
def follow_strict #

[View source]
def follow_strict=(strict : Bool) #

[View source]
def form : Hash(String, Type) #

[View source]
def form=(form : Hash(String, Type)) #

[View source]
def headers : HTTP::Headers #

[View source]
def headers=(headers : HTTP::Headers) #

[View source]
def headers=(headers : Hash(String, _) | NamedTuple) #

Set headers of request


[View source]
def json : Hash(String, Type) #

[View source]
def json=(json : Hash(String, Type)) #

[View source]
def logging : Bool #

Get logging status


[View source]
def logging=(enable : Bool) #

Quick enable logging

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


[View source]
def merge(other : Halite::Options) : Halite::Options #

Merge with other Options and return new Halite::Options


[View source]
def merge!(other : Halite::Options) : Halite::Options #

Merge with other Options and return self


[View source]
def params : Hash(String, Type) #

[View source]
def params=(params : Hash(String, Type)) #

[View source]
def raw : String | Nil #

[View source]
def raw=(raw : String | Nil) #

[View source]
def read_timeout #

Alias Timeout.read


[View source]
def read_timeout=(timeout : Int32 | Float64 | Time::Span) #

[View source]
def timeout : Timeout #

[View source]
def timeout=(timeout : Timeout) #

[View source]
def tls : OpenSSL::SSL::Context::Client | Nil #

[View source]
def tls=(tls : OpenSSL::SSL::Context::Client | Nil) #

[View source]
def to_h #

Returns this collection as a plain Hash.


[View source]
def with_cookies(cookies : Hash(String, _) | NamedTuple) : Halite::Options #

Returns Options self with given cookies combined.


[View source]
def with_cookies(cookies : HTTP::Cookies) : Halite::Options #

Returns Options self with given cookies combined.


[View source]
def with_cookies(cookie : HTTP::Cookie) : Halite::Options #

Returns Options self with given cookies combined.


[View source]
def with_cookies(**cookies) : Halite::Options #

Alias #with_cookies method.


[View source]
def with_endpoint(endpoint : String | URI) #

[View source]
def with_features(name : String, opts : NamedTuple) #

Returns Options self with feature name and options.


[View source]
def with_features(name : String, feature : Feature) #

Returns Options self with feature name and feature.


[View source]
def with_features(*features) #

Returns Options self with the name of features.


[View source]
def with_features(feature_name : String, **opts) #

Returns Options self with feature name and options.


[View source]
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)

[View source]
def with_headers(headers : Hash(String, _) | NamedTuple) : Halite::Options #

Returns Options self with given headers combined.


[View source]
def with_headers(**with_headers) : Halite::Options #

Alias #with_headers method.


[View source]
def with_logging(logging : Halite::Logging::Abstract) #

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


[View source]
def with_logging(format : String, **opts) #

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


[View source]
def with_timeout(connect : Int32 | Float64 | Time::Span | Nil = nil, read : Int32 | Float64 | Time::Span | Nil = nil, write : Int32 | Float64 | Time::Span | Nil = nil) : Halite::Options #

Returns Options self with given connect, read timeout.


[View source]
def write_timeout #

[View source]
def write_timeout=(timeout : Int32 | Float64 | Time::Span) #

[View source]