Class: Harborapp::Account
- Inherits:
-
Object
- Object
- Harborapp::Account
show all
- Includes:
- ApiModel
- Defined in:
- lib/harborapp/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_key ⇒ Object
Returns the value of attribute api_key.
6
7
8
|
# File 'lib/harborapp/account.rb', line 6
def api_key
@api_key
end
|
#email ⇒ Object
Returns the value of attribute email.
6
7
8
|
# File 'lib/harborapp/account.rb', line 6
def email
@email
end
|
Class Method Details
.from_creds ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/harborapp/account.rb', line 25
def self.from_creds
fn = File.expand_path("~/.harbor_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/harborapp/account.rb', line 8
def self.login(email, password)
params = {:basic_username => email, :basic_password => password}
Harborapp::Api.request :post, "/login", params
end
|
.logout ⇒ Object
34
35
36
37
|
# File 'lib/harborapp/account.rb', line 34
def self.logout
fn = File.expand_path("~/.harbor_auth")
File.unlink(fn) if File.exist? fn
end
|
.signup(email, password, password_confirmation) ⇒ Object
13
14
15
16
17
|
# File 'lib/harborapp/account.rb', line 13
def self.signup(email, password, password_confirmation)
params = {:email => email, :password => password,
:password_confirmation => password_confirmation}
Harborapp::Api.request :post, "/signup", params
end
|
Instance Method Details
#write_creds ⇒ Object
19
20
21
22
23
|
# File 'lib/harborapp/account.rb', line 19
def write_creds
File.open(File.expand_path("~/.harbor_auth"), "w") do |f|
f.write({api_key: api_key, email: email}.to_json)
end
end
|