Class: HTTPX::Session
- Inherits:
-
Object
- Object
- HTTPX::Session
- Defined in:
- lib/httpx/session.rb
Direct Known Subclasses
Constant Summary
Constants included from Loggable
Class Attribute Summary collapse
-
.default_options ⇒ Object
readonly
Returns the value of attribute default_options.
Class Method Summary collapse
- .inherited(klass) ⇒ Object
- .plugin(pl, options = nil, &block) ⇒ Object
-
.plugins(pls) ⇒ Object
:nocov:.
Instance Method Summary collapse
- #close(*args) ⇒ Object
-
#initialize(options = {}, &blk) ⇒ Session
constructor
A new instance of Session.
- #request(*args, **options) ⇒ Object
- #wrap ⇒ Object
Methods included from Chainable
#accept, #headers, #plugin, #plugins, #timeout, #with
Methods included from Loggable
Constructor Details
#initialize(options = {}, &blk) ⇒ Session
Returns a new instance of Session.
8 9 10 11 12 13 |
# File 'lib/httpx/session.rb', line 8 def initialize( = {}, &blk) @options = self.class..merge() @responses = {} @persistent = @options.persistent wrap(&blk) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class HTTPX::Chainable
Class Attribute Details
.default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
211 212 213 |
# File 'lib/httpx/session.rb', line 211 def @default_options end |
Class Method Details
.inherited(klass) ⇒ Object
213 214 215 216 217 |
# File 'lib/httpx/session.rb', line 213 def inherited(klass) super klass.instance_variable_set(:@default_options, @default_options) klass.instance_variable_set(:@plugins, @plugins.dup) end |
.plugin(pl, options = nil, &block) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/httpx/session.rb', line 219 def plugin(pl, = nil, &block) # raise Error, "Cannot add a plugin to a frozen config" if frozen? pl = Plugins.load_plugin(pl) if pl.is_a?(Symbol) unless @plugins.include?(pl) @plugins << pl pl.load_dependencies(self, &block) if pl.respond_to?(:load_dependencies) @default_options = @default_options.dup @default_options = pl.(@default_options, &block) if pl.respond_to?(:extra_options) @default_options = @default_options.merge() if include(pl::InstanceMethods) if defined?(pl::InstanceMethods) extend(pl::ClassMethods) if defined?(pl::ClassMethods) opts = @default_options opts.request_class.__send__(:include, pl::RequestMethods) if defined?(pl::RequestMethods) opts.request_class.extend(pl::RequestClassMethods) if defined?(pl::RequestClassMethods) opts.response_class.__send__(:include, pl::ResponseMethods) if defined?(pl::ResponseMethods) opts.response_class.extend(pl::ResponseClassMethods) if defined?(pl::ResponseClassMethods) opts.headers_class.__send__(:include, pl::HeadersMethods) if defined?(pl::HeadersMethods) opts.headers_class.extend(pl::HeadersClassMethods) if defined?(pl::HeadersClassMethods) opts.request_body_class.__send__(:include, pl::RequestBodyMethods) if defined?(pl::RequestBodyMethods) opts.request_body_class.extend(pl::RequestBodyClassMethods) if defined?(pl::RequestBodyClassMethods) opts.response_body_class.__send__(:include, pl::ResponseBodyMethods) if defined?(pl::ResponseBodyMethods) opts.response_body_class.extend(pl::ResponseBodyClassMethods) if defined?(pl::ResponseBodyClassMethods) opts.connection_class.__send__(:include, pl::ConnectionMethods) if defined?(pl::ConnectionMethods) pl.configure(self, &block) if pl.respond_to?(:configure) @default_options.freeze end self end |
.plugins(pls) ⇒ Object
:nocov:
252 253 254 255 256 257 258 |
# File 'lib/httpx/session.rb', line 252 def plugins(pls) warn ":#{__method__} is deprecated, use :plugin instead" pls.each do |pl, *args| plugin(pl, *args) end self end |
Instance Method Details
#close(*args) ⇒ Object
27 28 29 |
# File 'lib/httpx/session.rb', line 27 def close(*args) pool.close(*args) end |
#request(*args, **options) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/httpx/session.rb', line 31 def request(*args, **) requests = build_requests(*args, ) responses = send_requests(*requests, ) return responses.first if responses.size == 1 responses end |
#wrap ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/httpx/session.rb', line 15 def wrap return unless block_given? begin prev_persistent = @persistent @persistent = true yield self ensure @persistent = prev_persistent end end |