Class: Site

Inherits:
Object
  • Object
show all
Defined in:
lib/site.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(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]
  @session_id = Digest::MD5.hexdigest(rand.to_s)
  
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



2
3
4
# File 'lib/site.rb', line 2

def password
  @password
end

#rootObject

Returns the value of attribute root.



2
3
4
# File 'lib/site.rb', line 2

def root
  @root
end

#session_idObject

Returns the value of attribute session_id.



2
3
4
# File 'lib/site.rb', line 2

def session_id
  @session_id
end

#subdomainObject

Returns the value of attribute subdomain.



2
3
4
# File 'lib/site.rb', line 2

def subdomain
  @subdomain
end

#usernameObject

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_serverObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/site.rb', line 22

def 
  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