Class: Gophish::Template

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

Class Method Summary collapse

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

Class Method Details

.build_import_options(content, convert_links) ⇒ Object



34
35
36
37
38
39
# File 'lib/gophish/template.rb', line 34

def self.build_import_options(content, convert_links)
  {
    body: { content:, convert_links: }.to_json,
    headers: { 'Content-Type' => 'application/json' }
  }
end

.import_email(content, convert_links: false) ⇒ Object

Raises:

  • (StandardError)


26
27
28
29
30
31
32
# File 'lib/gophish/template.rb', line 26

def self.import_email(content, convert_links: false)
  options = build_import_options content, convert_links
  response = post '/import/email', options
  raise StandardError, 'Failed to import email' unless response.success?

  response.parsed_response
end

Instance Method Details

#add_attachment(content, type, name) ⇒ Object



41
42
43
44
45
# File 'lib/gophish/template.rb', line 41

def add_attachment(content, type, name)
  encoded_content = encode_content content
  attachments << { content: encoded_content, type:, name: }
  attachments_will_change!
end

#attachment_countObject



57
58
59
# File 'lib/gophish/template.rb', line 57

def attachment_count
  attachments.length
end

#body_for_createObject



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

def body_for_create
  { name:, envelope_sender:, subject:, text:, html:, attachments: }
end

#has_attachments?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/gophish/template.rb', line 53

def has_attachments?
  !attachments.empty?
end

#has_envelope_sender?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/gophish/template.rb', line 61

def has_envelope_sender?
  !envelope_sender.blank?
end

#remove_attachment(name) ⇒ Object



47
48
49
50
51
# File 'lib/gophish/template.rb', line 47

def remove_attachment(name)
  original_size = attachments.size
  attachments.reject! { |attachment| attachment[:name] == name || attachment['name'] == name }
  attachments_will_change! if attachments.size != original_size
end