Class: Lastpass::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/lastpass-api/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Account

Returns a new instance of Account.



6
7
8
# File 'lib/lastpass-api/account.rb', line 6

def initialize( params )
  ( params )
end

Instance Attribute Details

#groupObject (readonly)

TODO: Make group editable eventually



3
4
5
# File 'lib/lastpass-api/account.rb', line 3

def group
  @group
end

#idObject (readonly)

TODO: Make group editable eventually



3
4
5
# File 'lib/lastpass-api/account.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/lastpass-api/account.rb', line 4

def name
  @name
end

#notesObject

Returns the value of attribute notes.



4
5
6
# File 'lib/lastpass-api/account.rb', line 4

def notes
  @notes
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/lastpass-api/account.rb', line 4

def password
  @password
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/lastpass-api/account.rb', line 4

def url
  @url
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/lastpass-api/account.rb', line 4

def username
  @username
end

Instance Method Details

#deleteObject



44
45
46
47
# File 'lib/lastpass-api/account.rb', line 44

def delete
  Cli.rm( @id )
  @deleted = true
end

#inspectObject

Hide instance variables and values



64
65
66
67
# File 'lib/lastpass-api/account.rb', line 64

def inspect
  original_inspect = super
  original_inspect.split( ' ' ).first << '>'
end

#saveObject

TODO: This does not support changing groups yet!



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lastpass-api/account.rb', line 19

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_hashObject Also known as: to_h



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lastpass-api/account.rb', line 49

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



10
11
12
13
14
15
16
# File 'lib/lastpass-api/account.rb', line 10

def update( params )
  deleted! if @deleted
  params.delete( :id ) # Prevent overwriting ID
  params.delete( :group ) # Prevent overwriting group
  ( params )
  save
end