Class: Auger::HttpRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/auger/plugin/http.rb

Direct Known Subclasses

HttpGet, HttpPost, HttpPropfind

Instance Attribute Summary collapse

Attributes inherited from Request

#arg, #before_request_proc, #before_tests_proc, #tests

Instance Method Summary collapse

Methods inherited from Request

#Result, #Status, #before_request, #before_tests, load, #test, #try_run

Constructor Details

#initialize(url) ⇒ HttpRequest

Returns a new instance of HttpRequest.



71
72
73
74
75
76
# File 'lib/auger/plugin/http.rb', line 71

def initialize(url)
  @method ||= :get          # default
  @headers = {}
  @data = {}
  super
end

Instance Attribute Details

#body(string) ⇒ Object

Returns the value of attribute body.



68
69
70
# File 'lib/auger/plugin/http.rb', line 68

def body
  @body
end

#data(hash) ⇒ Object

Returns the value of attribute data.



68
69
70
# File 'lib/auger/plugin/http.rb', line 68

def data
  @data
end

#headersObject

Returns the value of attribute headers.



68
69
70
# File 'lib/auger/plugin/http.rb', line 68

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



68
69
70
# File 'lib/auger/plugin/http.rb', line 68

def method
  @method
end

#password(password) ⇒ Object

Returns the value of attribute password.



68
69
70
# File 'lib/auger/plugin/http.rb', line 68

def password
  @password
end

#user(user) ⇒ Object

Returns the value of attribute user.



68
69
70
# File 'lib/auger/plugin/http.rb', line 68

def user
  @user
end

Instance Method Details

#header(h) ⇒ Object



86
87
88
89
# File 'lib/auger/plugin/http.rb', line 86

def header(h)
  key, value = h.split /\s*:\s*/
  @headers[key] = value
end

#run(http, url) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/auger/plugin/http.rb', line 99

def run(http, url)
  request = Net::HTTP::const_get(@method.capitalize).new(url) # e.g. Net::HTTP::Get
  request.basic_auth(@user, @password || '') if @user
  @headers.each { |k,v| request[k] = v }
  request.set_form_data(@data)
  request.body = @body
  http.request(request)
end