Sha256: 40fff7fdae80b0e66a78fe01e36137869e6e3e06904616871df9b85347fdf4f3

Contents?: true

Size: 680 Bytes

Versions: 1

Compression:

Stored size: 680 Bytes

Contents

# frozen_string_literal: true
require 'addressable/template'
require 'addressable/uri'
require 'excon'
require 'excon/addressable/version'

Excon.defaults[:uri_parser] = Addressable::URI

module Excon
  module Addressable
    # 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)

        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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
excon-addressable-0.2.1 lib/excon/addressable.rb