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.



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

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

Instance Attribute Details

#actionObject

Returns the value of attribute action.



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

def action
  @action
end

#auth_typeObject

Returns the value of attribute auth_type.



43
44
45
# File 'lib/patron/request.rb', line 43

def auth_type
  @auth_type
end

#connect_timeoutObject

Returns the value of attribute connect_timeout.



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

def connect_timeout
  @connect_timeout
end

#file_nameObject

Returns the value of attribute file_name.



43
44
45
# File 'lib/patron/request.rb', line 43

def file_name
  @file_name
end

#headersObject

Returns the value of attribute headers.



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

def headers
  @headers
end

#insecureObject

Returns the value of attribute insecure.



43
44
45
# File 'lib/patron/request.rb', line 43

def insecure
  @insecure
end

#max_redirectsObject

Returns the value of attribute max_redirects.



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

def max_redirects
  @max_redirects
end

#passwordObject

Returns the value of attribute password.



43
44
45
# File 'lib/patron/request.rb', line 43

def password
  @password
end

#proxyObject

Returns the value of attribute proxy.



43
44
45
# File 'lib/patron/request.rb', line 43

def proxy
  @proxy
end

#timeoutObject

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

#urlObject

Returns the value of attribute url.



43
44
45
# File 'lib/patron/request.rb', line 43

def url
  @url
end

#usernameObject

Returns the value of attribute username.



43
44
45
# File 'lib/patron/request.rb', line 43

def username
  @username
end

Instance Method Details

#action_nameObject



122
123
124
# File 'lib/patron/request.rb', line 122

def action_name
  @action.to_s.upcase
end

#credentialsObject



126
127
128
129
# File 'lib/patron/request.rb', line 126

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

#upload_dataObject



78
79
80
# File 'lib/patron/request.rb', line 78

def upload_data
  @upload_data
end

#upload_data=(data) ⇒ Object



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

def upload_data=(data)
  @upload_data = case data
  when Hash
    hash_to_string(data)
  else
    data
  end
end