Class: Lastpass::Account
- Inherits:
-
Object
- Object
- Lastpass::Account
- Defined in:
- lib/lastpass-api/account.rb
Overview
Interact with a Lastpass account
Instance Attribute Summary collapse
- #group ⇒ Object readonly
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#password ⇒ Object
Returns the value of attribute password.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete the account.
-
#initialize(params) ⇒ Account
constructor
A new instance of Account.
-
#inspect ⇒ Object
private
Hide instance variables and values.
-
#save ⇒ Object
Either create or update an account, depending on what was changed on the account object before this method was called.
-
#to_hash ⇒ Hash
(also: #to_h)
Hash representation of the account object.
-
#update(params) ⇒ Object
Update the account details.
Constructor Details
#initialize(params) ⇒ Account
Returns a new instance of Account.
11 12 13 |
# File 'lib/lastpass-api/account.rb', line 11 def initialize( params ) params_to_account( params ) end |
Instance Attribute Details
#group ⇒ Object (readonly)
Make group editable eventually
7 8 9 |
# File 'lib/lastpass-api/account.rb', line 7 def group @group end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/lastpass-api/account.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/lastpass-api/account.rb', line 8 def name @name end |
#notes ⇒ Object
Returns the value of attribute notes.
8 9 10 |
# File 'lib/lastpass-api/account.rb', line 8 def notes @notes end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/lastpass-api/account.rb', line 8 def password @password end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/lastpass-api/account.rb', line 8 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
8 9 10 |
# File 'lib/lastpass-api/account.rb', line 8 def username @username end |
Instance Method Details
#delete ⇒ Object
Delete the account
78 79 80 81 |
# File 'lib/lastpass-api/account.rb', line 78 def delete Cli.rm( @id ) @deleted = true end |
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Hide instance variables and values
106 107 108 109 |
# File 'lib/lastpass-api/account.rb', line 106 def inspect original_inspect = super original_inspect.split( ' ' ).first << '>' end |
#save ⇒ Object
This does not support changing groups yet!
Either create or update an account, depending on what was changed on the account object before this method was called.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lastpass-api/account.rb', line 48 def save deleted! if @deleted # If there is an ID, update that entry if @id Cli.edit( @id, name: @name, username: @username, password: @password, url: @url, notes: @notes, group: @group ) else # If no ID, that means this is a new entry Cli.add( @name, username: @username, password: @password, url: @url, notes: @notes, group: @group ) set_id_after_save end self end |
#to_hash ⇒ Hash Also known as: to_h
Hash representation of the account object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/lastpass-api/account.rb', line 89 def to_hash params = {} params[:id] = @id if @id params[:name] = @name if @name params[:username] = @username if @username params[:password] = @password if @password params[:url] = @url if @url params[:notes] = @notes if @notes params[:group] = @group if @group params end |
#update(params) ⇒ Object
Update the account details
27 28 29 30 31 32 33 |
# File 'lib/lastpass-api/account.rb', line 27 def update( params ) deleted! if @deleted params.delete( :id ) # Prevent overwriting ID params.delete( :group ) # Prevent overwriting group params_to_account( params ) save end |