lib/patron/request.rb in patron-0.3.2 vs lib/patron/request.rb in patron-0.4.0
- old
+ new
@@ -28,24 +28,26 @@
# Represents the information necessary for an HTTP request.
# This is basically a data object with validation. Not all fields will be
# used in every request.
class Request
+ VALID_ACTIONS = [:get, :put, :post, :delete, :head, :copy]
+
def initialize
@action = :get
@headers = {}
@timeout = 0
@connect_timeout = 0
@max_redirects = -1
end
- attr_accessor :url, :username, :password, :upload_data
+ attr_accessor :url, :username, :password, :upload_data, :file_name, :proxy
attr_reader :action, :timeout, :connect_timeout, :max_redirects, :headers
def action=(new_action)
- if ![:get, :put, :post, :delete, :head].include?(new_action)
- raise ArgumentError, "Action must be one of :get, :put, :post, :delete or :head"
+ if !VALID_ACTIONS.include?(new_action)
+ raise ArgumentError, "Action must be one of #{VALID_ACTIONS.join(', ')}"
end
@action = new_action
end
@@ -77,9 +79,13 @@
if !new_headers.kind_of?(Hash)
raise ArgumentError, "Headers must be a hash"
end
@headers = new_headers
+ end
+
+ def action_name
+ @action.to_s.upcase
end
def credentials
return nil if username.nil? || password.nil?
"#{username}:#{password}"