class Site

Attributes

auth_key[R]
data[R]
data_path[R]
password[R]
root[R]
secret_key[RW]
session_id[R]
subdomain[R]
username[R]

Public Class Methods

new(options) click to toggle source
# File lib/site.rb, line 5
def initialize(options)
  @root = options[:root] if options[:root]
  @subdomain = options[:subdomain] if options[:subdomain]
  @username = options[:username] if options[:username]
  @password = options[:password] if options[:password]
  @auth_key = options[:auth_key] if options[:auth_key]
  @session_id = Digest::MD5.hexdigest(rand.to_s)
  @data_path = options[:data_path] || "#{@root}/.vae/data/"
end

Public Instance Methods

domain() click to toggle source
# File lib/site.rb, line 15
def domain
  subdomain =~ /\./ ? subdomain : "#{subdomain}.vaesite.com"
end
fetch_from_server(req) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/site.rb, line 56
def subdomain_base
  subdomain.split(".").first
end
vaeplatform_url() click to toggle source
# File lib/site.rb, line 60
def vaeplatform_url
  VaeLocal.vaeplatform_url(subdomain)
end