Class: Handsoap::Http::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/handsoap/http.rb

Overview

Represents a HTTP Request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, http_method = :get) ⇒ Request

Returns a new instance of Request.



11
12
13
14
15
16
# File 'lib/handsoap/http.rb', line 11

def initialize(url, http_method = :get)
  @url = url
  @http_method = http_method
  @headers = {}
  @body = nil
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



9
10
11
# File 'lib/handsoap/http.rb', line 9

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/handsoap/http.rb', line 9

def headers
  @headers
end

#http_methodObject

Returns the value of attribute http_method.



9
10
11
# File 'lib/handsoap/http.rb', line 9

def http_method
  @http_method
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/handsoap/http.rb', line 9

def url
  @url
end

Instance Method Details

#add_header(key, value) ⇒ Object



17
18
19
20
21
22
# File 'lib/handsoap/http.rb', line 17

def add_header(key, value)
  if @headers[key].nil?
    @headers[key] = []
  end
  @headers[key] << value
end

#inspectObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/handsoap/http.rb', line 30

def inspect
  "===============\n" +
    "--- Request ---\n" +
    "#{http_method.to_s.upcase} #{url}\n" +
    (
     if headers.any?
       "---\n" + headers.map { |key,values| values.map {|value| key + ": " + value + "\n" }.join("")  }.join("")
     else
       ""
     end
     ) +
    (
     if body
       "---\n" + body
     else
       ""
     end
     )
end

#set_header(key, value) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/handsoap/http.rb', line 23

def set_header(key, value)
  if value.nil?
    @headers[key] = nil
  else
    @headers[key] = [value]
  end
end