Module: HTTPX::Chainable

Included in:
HTTPX, Session
Defined in:
lib/httpx/chainable.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, **options) ⇒ Object (private)



90
91
92
93
94
95
96
97
98
# File 'lib/httpx/chainable.rb', line 90

def method_missing(meth, *args, **options)
  return super unless meth =~ /\Awith_(.+)/

  option = Regexp.last_match(1)

  return super unless option

  with(option.to_sym => (args.first || options))
end

Instance Method Details

#accept(type) ⇒ Object

:nocov:



42
43
44
# File 'lib/httpx/chainable.rb', line 42

def accept(type)
  with(headers: { "accept" => String(type) })
end

#headers(headers) ⇒ Object



36
37
38
39
# File 'lib/httpx/chainable.rb', line 36

def headers(headers)
  warn ":#{__method__} is deprecated, use :with_headers instead"
  with(headers: headers)
end

#plugin(pl, options = nil, &blk) ⇒ Object



50
51
52
53
54
55
# File 'lib/httpx/chainable.rb', line 50

def plugin(pl, options = nil, &blk)
  klass = is_a?(Session) ? self.class : Session
  klass = Class.new(klass)
  klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
  klass.plugin(pl, options, &blk).new
end

#plugins(pls) ⇒ Object

deprecated :nocov:



59
60
61
62
63
64
65
# File 'lib/httpx/chainable.rb', line 59

def plugins(pls)
  warn ":#{__method__} is deprecated, use :plugin instead"
  klass = is_a?(Session) ? self.class : Session
  klass = Class.new(klass)
  klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
  klass.plugins(pls).new
end

#request(*args, **options) ⇒ Object



26
27
28
# File 'lib/httpx/chainable.rb', line 26

def request(*args, **options)
  branch(default_options).request(*args, **options)
end

#timeout(**args) ⇒ Object

:nocov:



31
32
33
34
# File 'lib/httpx/chainable.rb', line 31

def timeout(**args)
  warn ":#{__method__} is deprecated, use :with_timeout instead"
  with(timeout: args)
end

#with(options, &blk) ⇒ Object

:nocov:



68
69
70
# File 'lib/httpx/chainable.rb', line 68

def with(options, &blk)
  branch(default_options.merge(options), &blk)
end

#wrap(&blk) ⇒ Object



46
47
48
# File 'lib/httpx/chainable.rb', line 46

def wrap(&blk)
  branch(default_options).wrap(&blk)
end