Sha256: 21cff696e5751a201d2a3d0e27a973ec2c462a813f71ba68b445dbd64bd3c176

Contents?: true

Size: 725 Bytes

Versions: 1

Compression:

Stored size: 725 Bytes

Contents

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

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

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.3.1 lib/excon/addressable.rb