Class: Devtunnel::Account

Inherits:
Object
  • Object
show all
Includes:
ApiModel
Defined in:
lib/devtunnel/account.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiModel

#attrs, #errors, #errors=, included, #initialize, #new_record?, #populate, #success?

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/devtunnel/account.rb', line 6

def api_key
  @api_key
end

#emailObject

Returns the value of attribute email.



6
7
8
# File 'lib/devtunnel/account.rb', line 6

def email
  @email
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/devtunnel/account.rb', line 6

def port
  @port
end

#userObject

Returns the value of attribute user.



6
7
8
# File 'lib/devtunnel/account.rb', line 6

def user
  @user
end

Class Method Details

.forward(port) ⇒ Object



38
39
40
41
# File 'lib/devtunnel/account.rb', line 38

def self.forward port
    params = {:port => port}
    Devtunnel::Api.request :post, "/forward", params
end

.from_credsObject

Raises:

  • (Exception)


24
25
26
27
28
29
30
31
# File 'lib/devtunnel/account.rb', line 24

def self.from_creds
	fn = File.expand_path("~/.devtunnel_auth")
	raise Exception.new("Please log in first") unless File.exist? fn
	File.open(fn, "r") do |f|
		hash = JSON.parse f.read
		self.new hash
	end
end

.login(email, password) ⇒ Object



8
9
10
11
# File 'lib/devtunnel/account.rb', line 8

def self.(email, password)
  params = {:basic_username => email, :basic_password => password}
  Devtunnel::Api.request :post, "/login", params
end

.logoutObject



33
34
35
36
# File 'lib/devtunnel/account.rb', line 33

def self.logout
	fn = File.expand_path("~/.devtunnel_auth")
	File.unlink(fn) if File.exist? fn
end

.signup(email) ⇒ Object



13
14
15
16
# File 'lib/devtunnel/account.rb', line 13

def self.(email)
  params = {:email => email}
  Devtunnel::Api.request :post, "/signup", params
end

Instance Method Details

#write_credsObject



18
19
20
21
22
# File 'lib/devtunnel/account.rb', line 18

def write_creds
	File.open(File.expand_path("~/.devtunnel_auth"), "w") do |f|
		f.write({api_key: api_key, email: email}.to_json)
	end
end