mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-05 00:02:38 -04:00
removing usage of ** params, as this forces typecast to hash, and one loses the options silently keeping the object passed in init, which is a big part of the plugins
This commit is contained in:
parent
95508ac4d5
commit
3c72a20d46
@ -59,7 +59,7 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
|
|
||||||
def plugin(*plugins)
|
def plugin(*plugins)
|
||||||
Class.new(Client).plugins(plugins).new(default_options)
|
Class.new(Client).plugins(plugins).new
|
||||||
end
|
end
|
||||||
alias :plugins :plugin
|
alias :plugins :plugin
|
||||||
|
|
||||||
@ -71,6 +71,7 @@ module HTTPX
|
|||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
def branch(options)
|
def branch(options)
|
||||||
|
return self.class.new(options) if self.is_a?(Client)
|
||||||
Client.new(options)
|
Client.new(options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@ module HTTPX
|
|||||||
class Client
|
class Client
|
||||||
include Chainable
|
include Chainable
|
||||||
|
|
||||||
def initialize(**options)
|
def initialize(options = {})
|
||||||
@default_options = self.class.default_options.merge(options)
|
@default_options = self.class.default_options.merge(options)
|
||||||
@connection = Connection.new(@default_options)
|
@connection = Connection.new(@default_options)
|
||||||
if block_given?
|
if block_given?
|
||||||
@ -34,22 +34,21 @@ module HTTPX
|
|||||||
private
|
private
|
||||||
|
|
||||||
def __build_reqs(*args, **options)
|
def __build_reqs(*args, **options)
|
||||||
rklass = @default_options.request_class
|
|
||||||
case args.size
|
case args.size
|
||||||
when 1
|
when 1
|
||||||
reqs = args.first
|
reqs = args.first
|
||||||
requests = reqs.map do |verb, uri, opts = {}|
|
requests = reqs.map do |verb, uri, opts = {}|
|
||||||
rklass.new(verb, uri, **@default_options.merge(options.merge(opts)))
|
__build_req(verb, uri, options.merge(opts))
|
||||||
end
|
end
|
||||||
when 2, 3
|
when 2, 3
|
||||||
verb, uris, opts = args
|
verb, uris, opts = args
|
||||||
opts ||= {}
|
opts ||= {}
|
||||||
if uris.respond_to?(:each)
|
if uris.respond_to?(:each)
|
||||||
requests = uris.map do |uri|
|
requests = uris.map do |uri|
|
||||||
rklass.new(verb, uri, **@default_options.merge(options.merge(opts)))
|
__build_req(verb, uri, options.merge(opts))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
[rklass.new(verb, uris, **@default_options.merge(options.merge(opts)))]
|
[ __build_req(verb, uris, options.merge(opts)) ]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise ArgumentError, "unsupported number of arguments"
|
raise ArgumentError, "unsupported number of arguments"
|
||||||
@ -72,6 +71,11 @@ module HTTPX
|
|||||||
requests.size == 1 ? responses.first : responses
|
requests.size == 1 ? responses.first : responses
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def __build_req(verb, uri, options = {})
|
||||||
|
rklass = @default_options.request_class
|
||||||
|
rklass.new(verb, uri, @default_options.merge(options))
|
||||||
|
end
|
||||||
|
|
||||||
@default_options = Options.new
|
@default_options = Options.new
|
||||||
@plugins = []
|
@plugins = []
|
||||||
|
|
||||||
|
@ -24,8 +24,6 @@ module HTTPX
|
|||||||
@defined_options ||= []
|
@defined_options ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def def_option(name, &interpreter)
|
def def_option(name, &interpreter)
|
||||||
defined_options << name.to_sym
|
defined_options << name.to_sym
|
||||||
interpreter ||= lambda { |v| v }
|
interpreter ||= lambda { |v| v }
|
||||||
|
@ -39,7 +39,7 @@ module HTTPX
|
|||||||
|
|
||||||
def_delegator :@body, :empty?
|
def_delegator :@body, :empty?
|
||||||
|
|
||||||
def initialize(verb, uri, **options)
|
def initialize(verb, uri, options = {})
|
||||||
@verb = verb.to_s.downcase.to_sym
|
@verb = verb.to_s.downcase.to_sym
|
||||||
@uri = URI(uri)
|
@uri = URI(uri)
|
||||||
@options = Options.new(options)
|
@options = Options.new(options)
|
||||||
|
@ -19,7 +19,7 @@ module HTTPX
|
|||||||
|
|
||||||
def_delegator :@body, :close
|
def_delegator :@body, :close
|
||||||
|
|
||||||
def initialize(request, status, headers, **options)
|
def initialize(request, status, headers, options = {})
|
||||||
@options = Options.new(options)
|
@options = Options.new(options)
|
||||||
@request = request
|
@request = request
|
||||||
@status = Integer(status)
|
@status = Integer(status)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user