Class: Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Request

Returns a new instance of Request.



17
18
19
20
21
22
23
# File 'lib/request.rb', line 17

def initialize(url, options = {})
  @time_on_page = options[:time_on_page] || 4
  @url = (options[:host] || "") + url
  @method = options[:method] || :get
  @params = options[:params] || {}
  @browser = options[:browser] #|| Mechanize.new
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



14
15
16
# File 'lib/request.rb', line 14

def method
  @method
end

#time_on_pageObject (readonly)

Returns the value of attribute time_on_page.



14
15
16
# File 'lib/request.rb', line 14

def time_on_page
  @time_on_page
end

#urlObject (readonly)

Returns the value of attribute url.



14
15
16
# File 'lib/request.rb', line 14

def url
  @url
end

Instance Method Details

#do_request!Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/request.rb', line 26

def do_request!
  uri = URI.parse(@url) 
  if @method == :post
    Net::HTTP.post_form uri, @params
  else
    #@browser.get(:url => @url, :headers => {'Authorization' => 'Basic ZGV2X3RlYW06RW5lcmd5Mi4w'})
    @browser.get(@url)
    #http = Net::HTTP.new("testing.et-model.com")
    
    
    #@req = req = Net::HTTP::Get.new(
    #Net::HTTP.get_print uri
    #req = Net::HTTP::Get.new(uri)
    #req.basic_auth "dev_team", "Energy2.0"
    #response = http.request(req)
    #puts response.body

  end

end