Class: HTTP::Options
- Inherits:
-
Object
- Object
- HTTP::Options
- Defined in:
- lib/http/options.rb
Class Attribute Summary collapse
-
.default_socket_class ⇒ Object
Returns the value of attribute default_socket_class.
-
.default_ssl_socket_class ⇒ Object
Returns the value of attribute default_ssl_socket_class.
Instance Attribute Summary collapse
-
#body ⇒ Object
Explicit request body of the request.
-
#follow ⇒ Object
readonly
Follow redirects.
-
#form ⇒ Object
readonly
Form data to embed in the request.
-
#headers ⇒ Object
readonly
HTTP headers to include in the request.
-
#json ⇒ Object
readonly
JSON data to embed in the request.
-
#params ⇒ Object
readonly
Query string params to add to the url.
-
#proxy ⇒ Object
readonly
HTTP proxy to route request.
-
#response ⇒ Object
readonly
How to format the response [:object, :body, :parse_body].
-
#socket_class ⇒ Object
Socket classes.
-
#ssl_context ⇒ Object
SSL context.
-
#ssl_socket_class ⇒ Object
Socket classes.
Class Method Summary collapse
Instance Method Summary collapse
- #[](option) ⇒ Object
- #dup {|dupped| ... } ⇒ Object
-
#initialize(options = {}) ⇒ Options
constructor
A new instance of Options.
- #merge(other) ⇒ Object
- #to_hash ⇒ Object
- #with_headers(headers) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Options
Returns a new instance of Options.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/http/options.rb', line 51 def initialize( = {}) @response = [:response] || :auto @proxy = [:proxy] || {} @body = [:body] @params = [:params] @form = [:form] @json = [:json] @follow = [:follow] @headers = HTTP::Headers.coerce([:headers] || {}) @socket_class = [:socket_class] || self.class.default_socket_class @ssl_socket_class = [:ssl_socket_class] || self.class.default_ssl_socket_class @ssl_context = [:ssl_context] end |
Class Attribute Details
.default_socket_class ⇒ Object
Returns the value of attribute default_socket_class.
43 44 45 |
# File 'lib/http/options.rb', line 43 def default_socket_class @default_socket_class end |
.default_ssl_socket_class ⇒ Object
Returns the value of attribute default_ssl_socket_class.
43 44 45 |
# File 'lib/http/options.rb', line 43 def default_ssl_socket_class @default_ssl_socket_class end |
Instance Attribute Details
#body ⇒ Object
Explicit request body of the request
23 24 25 |
# File 'lib/http/options.rb', line 23 def body @body end |
#follow ⇒ Object
Follow redirects
35 36 37 |
# File 'lib/http/options.rb', line 35 def follow @follow end |
#form ⇒ Object
Form data to embed in the request
17 18 19 |
# File 'lib/http/options.rb', line 17 def form @form end |
#headers ⇒ Object
HTTP headers to include in the request
11 12 13 |
# File 'lib/http/options.rb', line 11 def headers @headers end |
#json ⇒ Object
JSON data to embed in the request
20 21 22 |
# File 'lib/http/options.rb', line 20 def json @json end |
#params ⇒ Object
Query string params to add to the url
14 15 16 |
# File 'lib/http/options.rb', line 14 def params @params end |
#proxy ⇒ Object
HTTP proxy to route request
26 27 28 |
# File 'lib/http/options.rb', line 26 def proxy @proxy end |
#response ⇒ Object
How to format the response [:object, :body, :parse_body]
8 9 10 |
# File 'lib/http/options.rb', line 8 def response @response end |
#socket_class ⇒ Object
Socket classes
29 30 31 |
# File 'lib/http/options.rb', line 29 def socket_class @socket_class end |
#ssl_context ⇒ Object
SSL context
32 33 34 |
# File 'lib/http/options.rb', line 32 def ssl_context @ssl_context end |
#ssl_socket_class ⇒ Object
Socket classes
29 30 31 |
# File 'lib/http/options.rb', line 29 def ssl_socket_class @ssl_socket_class end |
Class Method Details
.new(options = {}) ⇒ Object
45 46 47 48 |
# File 'lib/http/options.rb', line 45 def new( = {}) return if .is_a?(self) super end |
Instance Method Details
#[](option) ⇒ Object
81 82 83 |
# File 'lib/http/options.rb', line 81 def [](option) send(option) rescue nil end |
#dup {|dupped| ... } ⇒ Object
118 119 120 121 122 |
# File 'lib/http/options.rb', line 118 def dup dupped = super yield(dupped) if block_given? dupped end |
#merge(other) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/http/options.rb', line 85 def merge(other) h1, h2 = to_hash, other.to_hash merged = h1.merge(h2) do |k, v1, v2| case k when :headers v1.merge(v2) else v2 end end self.class.new(merged) end |
#to_hash ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/http/options.rb', line 99 def to_hash # FIXME: hardcoding these fields blows! We should have a declarative # way of specifying all the options fields, and ensure they *all* # get serialized here, rather than manually having to add them each time { :response => response, :headers => headers.to_h, :proxy => proxy, :params => params, :form => form, :json => json, :body => body, :follow => follow, :socket_class => socket_class, :ssl_socket_class => ssl_socket_class, :ssl_context => ssl_context } end |
#with_headers(headers) ⇒ Object
67 68 69 70 71 |
# File 'lib/http/options.rb', line 67 def with_headers(headers) dup do |opts| opts.headers = self.headers.merge(headers) end end |