lib/relax/performer.rb in tylerhunt-relax-0.1.1 vs lib/relax/performer.rb in tylerhunt-relax-0.1.2

- old
+ new

@@ -1,17 +1,21 @@ module Relax class Performer - def initialize(method, url, values, credentials) + def initialize(method, url, values, options={}) @method = method @url = url @values = values - @credentials = credentials + @credentials = options.delete(:credentials) + @proxy = options.delete(:proxy) + @options = options parse_url_tokens end def perform + RestClient.proxy = @proxy if @proxy + case @method when :delete, :get, :head then RestClient.send(@method, url) when :post, :put then RestClient.send(@method, url, query) end end @@ -28,16 +32,18 @@ end private :url def query @values.collect do |name, value| - "#{name}=#{value}" if value + "#{name}=#{value}" if value || @options[:include_blank_values] end.compact.join('&') end private :query def parse_url_tokens - @url_values = @url.scan(/(?:\:)([a-z_]+)/).flatten.inject({}) do |values, name| + tokens = @url.scan(/(?:\:)([a-z_]+)/).flatten + + @url_values = tokens.inject({}) do |values, name| name = name.to_sym values[name] = @values.delete(name) if @values.key?(name) values end end