Class: Patron::Request

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.

Attributes

Instance Attributes

action [R] public

Returns the value of attribute action.

auth_type [R] public

Returns the value of attribute auth_type.

connect_timeout [R] public

Returns the value of attribute connect_timeout.

file_name [RW] public

Sets the attribute file_name.

headers [R] public

Returns the value of attribute headers.

insecure [RW] public

Sets the attribute insecure.

max_redirects [R] public

Returns the value of attribute max_redirects.

password [RW] public

Sets the attribute password.

proxy [RW] public

Sets the attribute proxy.

timeout [R] public

Returns the value of attribute timeout.

url [RW] public

Sets the attribute url.

username [RW] public

Sets the attribute username.

Constants

VALID_ACTIONS
[:get, :put, :post, :delete, :head, :copy]

Constructor Summary

public initialize
[View source]


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

Public Visibility

Public Instance Method Summary

#action=(new_action)
#action_name
#auth_type=(type = :basic)

Set the type of authentication to use for this request.

#connect_timeout=(new_timeout)
#credentials
#headers=(new_headers)
#max_redirects=(new_max_redirects)
#timeout=(new_timeout)
#upload_data
#upload_data=(data)

Public Instance Method Details

action=

public action=(new_action)
[View source]


82
83
84
85
86
87
88
# File 'lib/patron/request.rb', line 82

def action=(new_action)
  if !VALID_ACTIONS.include?(new_action)
    raise ArgumentError, "Action must be one of #{VALID_ACTIONS.join(', ')}"
  end

  @action = new_action
end

action_name

public action_name
[View source]


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

def action_name
  @action.to_s.upcase
end

auth_type=

public auth_type=(type = :basic)

Set the type of authentication to use for this request.

Meta Tags

Example:

  sess.username = "foo"
  sess.password = "sekrit"
  sess.auth_type = :digest

Parameters:

[String, Symbol] type
  • The type of authentication to use for this request, can be one of :basic, :digest, or :any
[View source]


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/patron/request.rb', line 56

def auth_type=(type=:basic)
  @auth_type = case type
  when :basic, "basic"
    Request::AuthBasic
  when :digest, "digest"
    Request::AuthDigest
  when :any, "any"
    Request::AuthAny
  else
    raise "#{type.inspect} is an unknown authentication type"
  end
end

connect_timeout=

public connect_timeout=(new_timeout)
[View source]


98
99
100
101
102
103
104
# File 'lib/patron/request.rb', line 98

def connect_timeout=(new_timeout)
  if new_timeout && new_timeout.to_i < 1
    raise ArgumentError, "Timeout must be a positive integer greater than 0"
  end

  @connect_timeout = new_timeout.to_i
end

credentials

public credentials
[View source]


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

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

headers=

public headers=(new_headers)
[View source]


114
115
116
117
118
119
120
# File 'lib/patron/request.rb', line 114

def headers=(new_headers)
  if !new_headers.kind_of?(Hash)
    raise ArgumentError, "Headers must be a hash"
  end

  @headers = new_headers
end

max_redirects=

public max_redirects=(new_max_redirects)
[View source]


106
107
108
109
110
111
112
# File 'lib/patron/request.rb', line 106

def max_redirects=(new_max_redirects)
  if new_max_redirects.to_i < -1
    raise ArgumentError, "Max redirects must be a positive integer, 0 or -1"
  end

  @max_redirects = new_max_redirects.to_i
end

timeout=

public timeout=(new_timeout)
[View source]


90
91
92
93
94
95
96
# File 'lib/patron/request.rb', line 90

def timeout=(new_timeout)
  if new_timeout && new_timeout.to_i < 1
    raise ArgumentError, "Timeout must be a positive integer greater than 0"
  end

  @timeout = new_timeout.to_i
end

upload_data

public upload_data
[View source]


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

def upload_data
  @upload_data
end

upload_data=

public upload_data=(data)
[View source]


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
Generated on Sunday, August 30 2009 at 08:18:36 PM by YARD 0.2.3.5 (ruby-1.8.6).