Class: TheDude::Http

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = nil) ⇒ TheDude::Http

Initalizes a new instance

Parameters:

  • url (String) (defaults to: nil)

    The url to connect to



13
14
15
# File 'lib/the_dude/http.rb', line 13

def initialize url=nil
  visit url if url
end

Instance Attribute Details

#urlObject (readonly)

The current url being visited



6
7
8
# File 'lib/the_dude/http.rb', line 6

def url
  @url
end

Instance Method Details

#sourceObject

Returns the HTML source for the current url



18
19
20
21
# File 'lib/the_dude/http.rb', line 18

def source
  raise 'No url' unless @url
  Net::HTTP.get(URI.parse(@url)).to_s
end

#visit(url) ⇒ Object

Sets the current url



24
25
26
# File 'lib/the_dude/http.rb', line 24

def visit url
  @url = url
end