Class: HTTP::Session::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/http/session/options.rb,
lib/http/session/options/optionable.rb,
lib/http/session/options/cache_option.rb,
lib/http/session/options/cookies_option.rb,
lib/http/session/options/persistent_option.rb

Defined Under Namespace

Modules: Optionable Classes: CacheOption, CookiesOption, PersistentOption

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Options

Returns a new instance of Options.

Parameters:

  • options (Hash)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/http/session/options.rb', line 20

def initialize(options)
  @cookies = HTTP::Session::Options::CookiesOption.new(options.fetch(:cookies, false))
  @cache = HTTP::Session::Options::CacheOption.new(options.fetch(:cache, false))
  @persistent = HTTP::Session::Options::PersistentOption.new(options.fetch(:persistent, false))
  @http = HTTP::Options.new(
    options.fetch(:http, {}).slice(
      :cookies,
      :encoding,
      :features,
      :follow,
      :headers,
      :keep_alive_timeout,
      :nodelay,
      :proxy,
      :response,
      :ssl,
      :ssl_socket_class,
      :socket_class,
      :timeout_class,
      :timeout_options
    )
  )
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



9
10
11
# File 'lib/http/session/options.rb', line 9

def cache
  @cache
end

#cookiesObject (readonly)

Returns the value of attribute cookies.



5
6
7
# File 'lib/http/session/options.rb', line 5

def cookies
  @cookies
end

#httpObject (readonly)

Returns the value of attribute http.



17
18
19
# File 'lib/http/session/options.rb', line 17

def http
  @http
end

#persistentObject (readonly)

Returns the value of attribute persistent.



13
14
15
# File 'lib/http/session/options.rb', line 13

def persistent
  @persistent
end

Instance Method Details

#merge(other) ⇒ Options

Returns:



45
46
47
# File 'lib/http/session/options.rb', line 45

def merge(other)
  tap { @http = @http.merge(other) }
end

#with_cookies(cookies) ⇒ Options

Returns:



50
51
52
# File 'lib/http/session/options.rb', line 50

def with_cookies(cookies)
  tap { @http = @http.with_cookies(cookies) }
end

#with_encoding(encoding) ⇒ Options

Returns:



55
56
57
# File 'lib/http/session/options.rb', line 55

def with_encoding(encoding)
  tap { @http = @http.with_encoding(encoding) }
end

#with_features(features) ⇒ Options

Returns:

Raises:

  • (ArgumentError)


60
61
62
63
# File 'lib/http/session/options.rb', line 60

def with_features(features)
  raise ArgumentError, "feature :auto_inflate is not supported, use :hsf_auto_inflate instead" if features.include?(:auto_inflate)
  tap { @http = @http.with_features(features) }
end

#with_follow(follow) ⇒ Options

Returns:



66
67
68
# File 'lib/http/session/options.rb', line 66

def with_follow(follow)
  tap { @http = @http.with_follow(follow) }
end

#with_headers(headers) ⇒ Options

Returns:



71
72
73
# File 'lib/http/session/options.rb', line 71

def with_headers(headers)
  tap { @http = @http.with_headers(headers) }
end

#with_nodelay(nodelay) ⇒ Options

Returns:



76
77
78
# File 'lib/http/session/options.rb', line 76

def with_nodelay(nodelay)
  tap { @http = @http.with_nodelay(nodelay) }
end

#with_proxy(proxy) ⇒ Options

Returns:



81
82
83
# File 'lib/http/session/options.rb', line 81

def with_proxy(proxy)
  tap { @http = @http.with_proxy(proxy) }
end