Class: Site
- Inherits:
-
Object
- Object
- Site
- Defined in:
- lib/site.rb
Instance Attribute Summary collapse
-
#auth_key ⇒ Object
readonly
Returns the value of attribute auth_key.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#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
- #domain ⇒ Object
- #fetch_from_server(req) ⇒ Object
-
#initialize(options) ⇒ Site
constructor
A new instance of Site.
- #login_to_server ⇒ Object
- #subdomain_base ⇒ Object
- #vaeplatform_url ⇒ 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] @auth_key = [:auth_key] if [:auth_key] @session_id = Digest::MD5.hexdigest(rand.to_s) @data_path = [:data_path] || "#{@root}/.vae/data/" end |
Instance Attribute Details
#auth_key ⇒ Object (readonly)
Returns the value of attribute auth_key.
2 3 4 |
# File 'lib/site.rb', line 2 def auth_key @auth_key end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
2 3 4 |
# File 'lib/site.rb', line 2 def data @data end |
#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
#domain ⇒ Object
15 16 17 |
# File 'lib/site.rb', line 15 def domain subdomain =~ /\./ ? subdomain : "#{subdomain}.vaesite.com" end |
#fetch_from_server(req) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/site.rb', line 19 def fetch_from_server(req) http = Net::HTTP.new(domain, 443) http.use_ssl = true http.start { |http| http.read_timeout = 120 http.request(req) } end |
#login_to_server ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/site.rb', line 28 def login_to_server req = Net::HTTP::Post.new("/") body = "__vae_local=#{session_id}&__local_version=#{VER}" if auth_key req.body = "#{body}&__local_auth_key=#{CGI.escape(auth_key)}" else req.body = "#{body}&__local_username2=#{CGI.escape(username)}&__local_password=#{CGI.escape(password)}" end res = fetch_from_server(req) data = JSON.parse(res.body) if data == nil or data == [] VaeLocal.write_auth_key(subdomain, nil) raise VaeError, "Invalid password or insufficient permissions." elsif data['alert'] puts data['alert'] elsif data['valid'] != "valid" VaeLocal.write_auth_key(subdomain, nil) raise VaeError, "Invalid password or insufficient permissions." end if data['auth_key'] and !auth_key VaeLocal.write_auth_key(subdomain, data['auth_key']) @auth_key = data['auth_key'] end @data = data rescue JSON::ParserError raise VaeError, "An unknown error occurred signing into Vae Platform. Please email support for help." end |
#subdomain_base ⇒ Object
56 57 58 |
# File 'lib/site.rb', line 56 def subdomain_base subdomain.split(".").first end |
#vaeplatform_url ⇒ Object
60 61 62 |
# File 'lib/site.rb', line 60 def vaeplatform_url VaeLocal.vaeplatform_url(subdomain) end |