Class: Devtunnel::Account
- Inherits:
-
Object
- Object
- Devtunnel::Account
- Includes:
- ApiModel
- Defined in:
- lib/devtunnel/account.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#email ⇒ Object
Returns the value of attribute email.
-
#port ⇒ Object
Returns the value of attribute port.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
- .forward(port) ⇒ Object
- .from_creds ⇒ Object
- .login(email, password) ⇒ Object
- .logout ⇒ Object
- .signup(email) ⇒ Object
Instance Method Summary collapse
Methods included from ApiModel
#attrs, #errors, #errors=, included, #initialize, #new_record?, #populate, #success?
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/devtunnel/account.rb', line 6 def api_key @api_key end |
#email ⇒ Object
Returns the value of attribute email.
6 7 8 |
# File 'lib/devtunnel/account.rb', line 6 def email @email end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/devtunnel/account.rb', line 6 def port @port end |
#user ⇒ Object
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_creds ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/devtunnel/account.rb', line 24 def self.from_creds fn = File.("~/.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.login(email, password) params = {:basic_username => email, :basic_password => password} Devtunnel::Api.request :post, "/login", params end |
.logout ⇒ Object
33 34 35 36 |
# File 'lib/devtunnel/account.rb', line 33 def self.logout fn = File.("~/.devtunnel_auth") File.unlink(fn) if File.exist? fn end |
Instance Method Details
#write_creds ⇒ Object
18 19 20 21 22 |
# File 'lib/devtunnel/account.rb', line 18 def write_creds File.open(File.("~/.devtunnel_auth"), "w") do |f| f.write({api_key: api_key, email: email}.to_json) end end |