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
|
||||
|
||||
def plugin(*plugins)
|
||||
Class.new(Client).plugins(plugins).new(default_options)
|
||||
Class.new(Client).plugins(plugins).new
|
||||
end
|
||||
alias :plugins :plugin
|
||||
|
||||
@ -71,6 +71,7 @@ module HTTPX
|
||||
|
||||
# :nodoc:
|
||||
def branch(options)
|
||||
return self.class.new(options) if self.is_a?(Client)
|
||||
Client.new(options)
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ module HTTPX
|
||||
class Client
|
||||
include Chainable
|
||||
|
||||
def initialize(**options)
|
||||
def initialize(options = {})
|
||||
@default_options = self.class.default_options.merge(options)
|
||||
@connection = Connection.new(@default_options)
|
||||
if block_given?
|
||||
@ -34,22 +34,21 @@ module HTTPX
|
||||
private
|
||||
|
||||
def __build_reqs(*args, **options)
|
||||
rklass = @default_options.request_class
|
||||
case args.size
|
||||
when 1
|
||||
reqs = args.first
|
||||
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
|
||||
when 2, 3
|
||||
verb, uris, opts = args
|
||||
opts ||= {}
|
||||
if uris.respond_to?(:each)
|
||||
requests = uris.map do |uri|
|
||||
rklass.new(verb, uri, **@default_options.merge(options.merge(opts)))
|
||||
__build_req(verb, uri, options.merge(opts))
|
||||
end
|
||||
else
|
||||
[rklass.new(verb, uris, **@default_options.merge(options.merge(opts)))]
|
||||
[ __build_req(verb, uris, options.merge(opts)) ]
|
||||
end
|
||||
else
|
||||
raise ArgumentError, "unsupported number of arguments"
|
||||
@ -72,6 +71,11 @@ module HTTPX
|
||||
requests.size == 1 ? responses.first : responses
|
||||
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
|
||||
@plugins = []
|
||||
|
||||
|
@ -24,8 +24,6 @@ module HTTPX
|
||||
@defined_options ||= []
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def def_option(name, &interpreter)
|
||||
defined_options << name.to_sym
|
||||
interpreter ||= lambda { |v| v }
|
||||
|
@ -39,7 +39,7 @@ module HTTPX
|
||||
|
||||
def_delegator :@body, :empty?
|
||||
|
||||
def initialize(verb, uri, **options)
|
||||
def initialize(verb, uri, options = {})
|
||||
@verb = verb.to_s.downcase.to_sym
|
||||
@uri = URI(uri)
|
||||
@options = Options.new(options)
|
||||
|
@ -19,7 +19,7 @@ module HTTPX
|
||||
|
||||
def_delegator :@body, :close
|
||||
|
||||
def initialize(request, status, headers, **options)
|
||||
def initialize(request, status, headers, options = {})
|
||||
@options = Options.new(options)
|
||||
@request = request
|
||||
@status = Integer(status)
|
||||
|
Loading…
x
Reference in New Issue
Block a user