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)



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

def method_missing(meth, *args, **options)
  if meth =~ /\Awith_(.+)/
    option = Regexp.last_match(1).to_sym
    with(option => (args.first || options))
  else
    super
  end
end

Instance Method Details

#accept(type) ⇒ Object

:nocov:



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

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

#headers(headers) ⇒ Object



23
24
25
26
# File 'lib/httpx/chainable.rb', line 23

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

#plugin(*args, **opts) ⇒ Object



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

def plugin(*args, **opts)
  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(*args, **opts).new
end

#plugins(*args, **opts) ⇒ Object

deprecated



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

def plugins(*args, **opts)
  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(*args, **opts).new
end

#request(verb, uri, **options) ⇒ Object



13
14
15
# File 'lib/httpx/chainable.rb', line 13

def request(verb, uri, **options)
  branch(default_options).request(verb, uri, **options)
end

#timeout(**args) ⇒ Object

:nocov:



18
19
20
21
# File 'lib/httpx/chainable.rb', line 18

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

#with(options, &blk) ⇒ Object



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

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

#wrap(&blk) ⇒ Object



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

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