Class: Site
- Inherits:
-
Object
- Object
- Site
- Defined in:
- lib/site.rb
Instance Attribute Summary collapse
-
#data_path ⇒ Object
readonly
Returns the value of attribute data_path.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#subdomain ⇒ Object
readonly
Returns the value of attribute subdomain.
-
#username ⇒ Object
readonly
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.
5 6 7 8 9 10 11 12 13 |
# File 'lib/site.rb', line 5 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) @data_path = [:data_path] || "#{@root}/.vae/data/" login_to_server end |
Instance Attribute Details
#data_path ⇒ Object (readonly)
Returns the value of attribute data_path.
2 3 4 |
# File 'lib/site.rb', line 2 def data_path @data_path end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
2 3 4 |
# File 'lib/site.rb', line 2 def password @password end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
2 3 4 |
# File 'lib/site.rb', line 2 def root @root end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
3 4 5 |
# File 'lib/site.rb', line 3 def secret_key @secret_key end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
2 3 4 |
# File 'lib/site.rb', line 2 def session_id @session_id end |
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
2 3 4 |
# File 'lib/site.rb', line 2 def subdomain @subdomain end |
#username ⇒ Object (readonly)
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
15 16 17 18 19 20 21 22 |
# File 'lib/site.rb', line 15 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
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/site.rb', line 24 def login_to_server req = Net::HTTP::Post.new("/") req.body = "__vae_local=#{session_id}&__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 |