Module: HTTPX::Chainable
Overview
Session mixin, implements most of the APIs that the users call. delegates to a default session when extended.
Instance Method Summary collapse
- #accept(type) ⇒ Object
-
#plugin(pl, options = nil, &blk) ⇒ Object
returns a new instance loaded with the
pl
plugin andoptions
. -
#request(*args, **options) ⇒ Object
delegates to the default session (see HTTPX::Session#request).
-
#with(options, &blk) ⇒ Object
returns a new instance loaded with
options
. -
#wrap(&blk) ⇒ Object
delegates to the default session (see HTTPX::Session#wrap).
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, **options, &blk) ⇒ Object (private)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/httpx/chainable.rb', line 56 def method_missing(meth, *args, **, &blk) case meth when /\Awith_(.+)/ option = Regexp.last_match(1) return super unless option with(option.to_sym => args.first || ) when /\Aon_(.+)/ callback = Regexp.last_match(1) return super unless %w[ connection_opened connection_closed request_error request_started request_body_chunk request_completed response_started response_body_chunk response_completed ].include?(callback) warn "DEPRECATION WARNING: calling `.#{meth}` on plain HTTPX sessions is deprecated. " \ "Use `HTTPX.plugin(:callbacks).#{meth}` instead." plugin(:callbacks).__send__(meth, *args, **, &blk) else super end end |
Instance Method Details
#accept(type) ⇒ Object
20 21 22 |
# File 'lib/httpx/chainable.rb', line 20 def accept(type) with(headers: { "accept" => String(type) }) end |
#plugin(pl, options = nil, &blk) ⇒ Object
returns a new instance loaded with the pl
plugin and options
.
30 31 32 33 34 35 |
# File 'lib/httpx/chainable.rb', line 30 def plugin(pl, = nil, &blk) klass = is_a?(S) ? self.class : Session klass = Class.new(klass) klass.instance_variable_set(:@default_options, klass..merge()) klass.plugin(pl, , &blk).new end |
#request(*args, **options) ⇒ Object
delegates to the default session (see HTTPX::Session#request).
16 17 18 |
# File 'lib/httpx/chainable.rb', line 16 def request(*args, **) branch().request(*args, **) end |
#with(options, &blk) ⇒ Object
returns a new instance loaded with options
.
38 39 40 |
# File 'lib/httpx/chainable.rb', line 38 def with(, &blk) branch(.merge(), &blk) end |
#wrap(&blk) ⇒ Object
delegates to the default session (see HTTPX::Session#wrap).
25 26 27 |
# File 'lib/httpx/chainable.rb', line 25 def wrap(&blk) branch().wrap(&blk) end |