Class: Chicanery::Site
- Inherits:
-
Object
- Object
- Chicanery::Site
- Defined in:
- lib/chicanery/site.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(name, url, options = {}) ⇒ Site
constructor
A new instance of Site.
- #path ⇒ Object
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, ={} @name, @uri, @options = name, URI(url), end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/chicanery/site.rb', line 7 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/chicanery/site.rb', line 7 def code @code end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
7 8 9 |
# File 'lib/chicanery/site.rb', line 7 def duration @duration end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/chicanery/site.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/chicanery/site.rb', line 7 def @options end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/chicanery/site.rb', line 7 def uri @uri end |
Instance Method Details
#get ⇒ Object
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 [:user], [:password] if [:user] and [:password] http_opts = { use_ssl: uri.scheme == 'https' } http_opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE unless [: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 |
#path ⇒ Object
13 14 15 |
# File 'lib/chicanery/site.rb', line 13 def path uri.query ? "#{uri.path}?#{uri.query}" : uri.path end |