Class: Site
- Inherits:
-
Object
- Object
- Site
- Defined in:
- lib/site.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#root ⇒ Object
Returns the value of attribute root.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#subdomain ⇒ Object
Returns the value of attribute subdomain.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #fetch_from_server(req) ⇒ Object
-
#initialize(options) ⇒ Site
constructor
A new instance of Site.
- #login_to_server ⇒ Object
Constructor Details
#initialize(options) ⇒ Site
Returns a new instance of Site.
13 14 15 16 17 18 19 20 |
# File 'lib/site.rb', line 13 def initialize() @root = [:root] if [:root] @subdomain = [:subdomain] if [:subdomain] @username = [:username] if [:username] @password = [:password] if [:password] @session_id = Digest::MD5.hexdigest(rand.to_s) login_to_server end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
2 3 4 |
# File 'lib/site.rb', line 2 def password @password end |
#root ⇒ Object
Returns the value of attribute root.
2 3 4 |
# File 'lib/site.rb', line 2 def root @root end |
#session_id ⇒ Object
Returns the value of attribute session_id.
2 3 4 |
# File 'lib/site.rb', line 2 def session_id @session_id end |
#subdomain ⇒ Object
Returns the value of attribute subdomain.
2 3 4 |
# File 'lib/site.rb', line 2 def subdomain @subdomain end |
#username ⇒ Object
Returns the value of attribute username.
2 3 4 |
# File 'lib/site.rb', line 2 def username @username end |
Instance Method Details
#fetch_from_server(req) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/site.rb', line 4 def fetch_from_server(req) http = Net::HTTP.new("#{subdomain}.vaesite.com") http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.start { |http| http.read_timeout = 120 http.request(req) } end |
#login_to_server ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/site.rb', line 22 def login_to_server req = Net::HTTP::Post.new("/?__vae_local=#{session_id}") req.body = "__local_username=#{CGI.escape(username)}&__local_password=#{CGI.escape(password)}&__local_version=#{VER}" res = fetch_from_server(req) if res.body == "BAD" raise VaeError, "Invalid password or insufficient permissions." elsif res.body =~ /MSG/ puts res.body.gsub(/MSG/, "") elsif res.body != "GOOD" raise VaeError, "Could not connect to Vae servers. Please check your Internet connection." end end |