Class: Gophish::Group

Inherits:
Base
  • Object
show all
Defined in:
lib/gophish/group.rb

Instance Method Summary collapse

Methods inherited from Base

all, configuration, delete, #destroy, find, get, #initialize, #new_record?, #persisted?, post, put, resource_name, resource_path, #save, #update_attributes

Constructor Details

This class inherits a constructor from Gophish::Base

Instance Method Details

#add_target(target) ⇒ Object



27
28
29
30
# File 'lib/gophish/group.rb', line 27

def add_target(target)
  current_targets = targets || []
  self.targets = current_targets + [target]
end

#body_for_createObject



18
19
20
# File 'lib/gophish/group.rb', line 18

def body_for_create
  { name:, targets: }
end

#import_csv(csv_data) ⇒ Object



22
23
24
25
# File 'lib/gophish/group.rb', line 22

def import_csv(csv_data)
  targets_array = CSV.parse(csv_data, headers: true).map { |row| parse_csv_row row }
  self.targets = targets_array
end

#remove_target(target) ⇒ Object



32
33
34
35
# File 'lib/gophish/group.rb', line 32

def remove_target(target)
  current_targets = targets || []
  self.targets = current_targets.reject { |t| t == target }
end

#remove_target_by_email(email) ⇒ Object



37
38
39
40
# File 'lib/gophish/group.rb', line 37

def remove_target_by_email(email)
  current_targets = targets || []
  self.targets = current_targets.reject { |t| (t[:email] || t['email']) == email }
end