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)



67
68
69
70
71
72
73
74
75
# File 'lib/httpx/chainable.rb', line 67

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



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

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

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



38
39
40
41
42
43
# File 'lib/httpx/chainable.rb', line 38

def plugin(pl, options = nil, &blk)
  klass = is_a?(S) ? 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

#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

#with(options, &blk) ⇒ Object



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

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

#wrap(&blk) ⇒ Object



34
35
36
# File 'lib/httpx/chainable.rb', line 34

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