Class: Chicanery::Site

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

Direct Known Subclasses

Cctray::Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url, options = {}) ⇒ Site

Returns a new instance of Site.



9
10
11
# File 'lib/chicanery/site.rb', line 9

def initialize name, url, options={}
  @name, @uri, @options = name, URI(url), options
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/chicanery/site.rb', line 7

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



7
8
9
# File 'lib/chicanery/site.rb', line 7

def code
  @code
end

#durationObject (readonly)

Returns the value of attribute duration.



7
8
9
# File 'lib/chicanery/site.rb', line 7

def duration
  @duration
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/chicanery/site.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/chicanery/site.rb', line 7

def options
  @options
end

#uriObject (readonly)

Returns the value of attribute uri.



7
8
9
# File 'lib/chicanery/site.rb', line 7

def uri
  @uri
end

Instance Method Details

#getObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/chicanery/site.rb', line 17

def get
  req = Net::HTTP::Get.new path
  req.basic_auth options[:user], options[:password] if options[:user] and options[:password]
  http_opts = { use_ssl: uri.scheme == 'https' }
  http_opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE unless options[:verify_ssl]
  start = Time.now
  res = Net::HTTP.start uri.host, uri.port, http_opts do |https|
    https.request req
  end
  @duration, @code, @body = (Time.now - start), res.code, res.body
  res.value #check for success via a spectactularly poorly named method
  res.body
end

#pathObject



13
14
15
# File 'lib/chicanery/site.rb', line 13

def path
  uri.query ? "#{uri.path}?#{uri.query}" : uri.path
end