Class: Patron::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/patron/request.rb,
ext/patron/session_ext.c

Overview

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.

Constant Summary collapse

VALID_ACTIONS =
[:get, :put, :post, :delete, :head, :copy]
AuthBasic =
INT2FIX(CURLAUTH_BASIC)
AuthDigest =
INT2FIX(CURLAUTH_DIGEST)
AuthAny =
INT2FIX(CURLAUTH_ANY)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequest

Returns a new instance of Request.



37
38
39
40
41
42
43
# File 'lib/patron/request.rb', line 37

def initialize
  @action = :get
  @headers = {}
  @timeout = 0
  @connect_timeout = 0
  @max_redirects = -1
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



46
47
48
# File 'lib/patron/request.rb', line 46

def action
  @action
end

#auth_typeObject

Returns the value of attribute auth_type.



45
46
47
# File 'lib/patron/request.rb', line 45

def auth_type
  @auth_type
end

#buffer_sizeObject

Returns the value of attribute buffer_size.



46
47
48
# File 'lib/patron/request.rb', line 46

def buffer_size
  @buffer_size
end

#connect_timeoutObject

Returns the value of attribute connect_timeout.



46
47
48
# File 'lib/patron/request.rb', line 46

def connect_timeout
  @connect_timeout
end

#file_nameObject

Returns the value of attribute file_name.



45
46
47
# File 'lib/patron/request.rb', line 45

def file_name
  @file_name
end

#headersObject

Returns the value of attribute headers.



46
47
48
# File 'lib/patron/request.rb', line 46

def headers
  @headers
end

#insecureObject

Returns the value of attribute insecure.



45
46
47
# File 'lib/patron/request.rb', line 45

def insecure
  @insecure
end

#max_redirectsObject

Returns the value of attribute max_redirects.



46
47
48
# File 'lib/patron/request.rb', line 46

def max_redirects
  @max_redirects
end

#multipartObject

Returns the value of attribute multipart.



45
46
47
# File 'lib/patron/request.rb', line 45

def multipart
  @multipart
end

#passwordObject

Returns the value of attribute password.



45
46
47
# File 'lib/patron/request.rb', line 45

def password
  @password
end

#proxyObject

Returns the value of attribute proxy.



45
46
47
# File 'lib/patron/request.rb', line 45

def proxy
  @proxy
end

#proxy_typeObject

Returns the value of attribute proxy_type.



45
46
47
# File 'lib/patron/request.rb', line 45

def proxy_type
  @proxy_type
end

#timeoutObject

Returns the value of attribute timeout.



46
47
48
# File 'lib/patron/request.rb', line 46

def timeout
  @timeout
end

#urlObject

Returns the value of attribute url.



45
46
47
# File 'lib/patron/request.rb', line 45

def url
  @url
end

#usernameObject

Returns the value of attribute username.



45
46
47
# File 'lib/patron/request.rb', line 45

def username
  @username
end

Instance Method Details

#action_nameObject



132
133
134
# File 'lib/patron/request.rb', line 132

def action_name
  @action.to_s.upcase
end

#credentialsObject



136
137
138
139
# File 'lib/patron/request.rb', line 136

def credentials
  return nil if username.nil? || password.nil?
  "#{username}:#{password}"
end

#upload_dataObject



80
81
82
# File 'lib/patron/request.rb', line 80

def upload_data
  @upload_data
end

#upload_data=(data) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/patron/request.rb', line 71

def upload_data=(data)
  @upload_data = case data
  when Hash
    self.multipart ? data : Util.build_query_string_from_hash(data, @action == :post)
  else
    data
  end
end