lib/excon/addressable.rb in excon-addressable-0.1.1 vs lib/excon/addressable.rb in excon-addressable-0.2.0

- old
+ new

@@ -3,21 +3,25 @@ require 'excon' require 'excon/addressable/version' Excon.defaults[:uri_parser] = Addressable::URI -# :nodoc: module Excon - # Addressable addition to Excon. - # module Addressable - def new(url, params = {}) - if (template = ::Addressable::Template.new(url)) && template.variables.any? - url = template.expand(params.delete(:expand).to_h) - end + # Middleware + # + # Parses a Templated URI string and merges it with the provided variables. + # + class Middleware < Excon::Middleware::Base + def request_call(datum) + url = ::Addressable::URI.new(datum) - super + if (template = ::Addressable::Template.new(url)) && template.variables.any? + uri = template.expand(datum[:expand].to_h) + datum.merge!(uri.to_hash) + end + + super + end end end - - singleton_class.prepend Addressable end