Class: Lastpass::Groups

Inherits:
Collection show all
Defined in:
lib/lastpass-api/groups.rb

Overview

Interact with Lastpass groups/folders

Instance Method Summary collapse

Instance Method Details

#create(params) ⇒ Lastpass::Group

Create a new group

Examples:

group = @lastpass.groups.create( name: 'Group1' )
puts group.id

Parameters:

  • params (Hash)

Returns:



54
55
56
57
# File 'lib/lastpass-api/groups.rb', line 54

def create( params )
  params.delete( :id ) # Prevent overwriting ID
  Group.new( params ).save
end

#find(search_text, with_password: false) ⇒ Lastpass::Group, NilClass

Find a specific group by name or by ID

Examples:

# Find a specific group by name
group = @lastpass.groups.find( 'Group1' )

# Find a specific group by ID
group = @lastpass.groups.find( '1234' )

Parameters:

  • search_text (String)

    Group name or ID

  • with_password (Boolean) (defaults to: false)

    Fetch the account passwords along with the group details (default: false)

Returns:



17
18
19
20
21
22
23
24
# File 'lib/lastpass-api/groups.rb', line 17

def find( search_text, with_password: false )
  search_text.to_s.gsub!( '/', '' )
  search_text << '/' unless is_number?( search_text )
  params = super
  if params.is_a?( Hash ) && params[:name]&.end_with?( '/' )
    Group.new( params )
  end
end

#find_all(search_text = '.*', with_passwords: false) ⇒ Array<Lastpass::Group>

Note:

By default, with no params specified, all groups will be returned.

Find all groups by name or by ID

Examples:

# Find all groups that match string (or regex)
groups = @lastpass.groups.find_all( 'Gro' )
puts groups.count
puts groups.first.to_h

# Fetch all groups - same as find_all( '.*' )
@lastpass.groups.find_all

Parameters:

  • search_text (String) (defaults to: '.*')

    Group name or ID (can pass in regex like ‘.*’)

  • with_passwords (Boolean) (defaults to: false)

    Fetch the account passwords along with the group details (default: false)

Returns:



40
41
42
43
44
45
# File 'lib/lastpass-api/groups.rb', line 40

def find_all( search_text = '.*', with_passwords: false )
  groups = super.select { |params| params[:name]&.end_with? '/' }
  groups.map do |params|
    Group.new( params )
  end
end

#inspectObject

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



62
63
64
65
# File 'lib/lastpass-api/groups.rb', line 62

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