Class: Auger::HttpRequest

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

Direct Known Subclasses

HttpGet, HttpPost

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.



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

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

Instance Attribute Details

#data(hash) ⇒ Object

Returns the value of attribute data.



64
65
66
# File 'lib/auger/plugin/http.rb', line 64

def data
  @data
end

#headersObject

Returns the value of attribute headers.



64
65
66
# File 'lib/auger/plugin/http.rb', line 64

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



64
65
66
# File 'lib/auger/plugin/http.rb', line 64

def method
  @method
end

#password(password) ⇒ Object

Returns the value of attribute password.



64
65
66
# File 'lib/auger/plugin/http.rb', line 64

def password
  @password
end

#user(user) ⇒ Object

Returns the value of attribute user.



64
65
66
# File 'lib/auger/plugin/http.rb', line 64

def user
  @user
end

Instance Method Details

#header(h) ⇒ Object



78
79
80
81
# File 'lib/auger/plugin/http.rb', line 78

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

#run(http, url) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/auger/plugin/http.rb', line 91

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)
  http.request(request)
end