Class: Pushpop::Sendgrid

Inherits:
Step
  • Object
show all
Defined in:
lib/pushpop-sendgrid.rb,
lib/pushpop-sendgrid/version.rb

Constant Summary collapse

PLUGIN_NAME =
'sendgrid'
VERSION =
'0.1.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_attachmentObject

Returns the value of attribute _attachment.



27
28
29
# File 'lib/pushpop-sendgrid.rb', line 27

def _attachment
  @_attachment
end

#_bodyObject

Returns the value of attribute _body.



25
26
27
# File 'lib/pushpop-sendgrid.rb', line 25

def _body
  @_body
end

#_fromObject

Returns the value of attribute _from.



22
23
24
# File 'lib/pushpop-sendgrid.rb', line 22

def _from
  @_from
end

#_previewObject

Returns the value of attribute _preview.



26
27
28
# File 'lib/pushpop-sendgrid.rb', line 26

def _preview
  @_preview
end

#_subjectObject

Returns the value of attribute _subject.



24
25
26
# File 'lib/pushpop-sendgrid.rb', line 24

def _subject
  @_subject
end

#_toObject

Returns the value of attribute _to.



23
24
25
# File 'lib/pushpop-sendgrid.rb', line 23

def _to
  @_to
end

Instance Method Details

#attachment(_attachment) ⇒ Object



91
92
93
# File 'lib/pushpop-sendgrid.rb', line 91

def attachment(_attachment)
  self._attachment = _attachment
end

#body(*args) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/pushpop-sendgrid.rb', line 83

def body(*args)
  if args.length == 1
    self._body = args.first
  else
    self._body = template(*args)
  end
end

#configure(last_response = nil, step_responses = nil) ⇒ Object



63
64
65
# File 'lib/pushpop-sendgrid.rb', line 63

def configure(last_response=nil, step_responses=nil)
  self.instance_exec(last_response, step_responses, &block)
end

#from(from) ⇒ Object



67
68
69
# File 'lib/pushpop-sendgrid.rb', line 67

def from(from)
  self._from = from
end

#preview(preview) ⇒ Object



79
80
81
# File 'lib/pushpop-sendgrid.rb', line 79

def preview(preview)
  self._preview = preview
end

#run(last_response = nil, step_responses = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pushpop-sendgrid.rb', line 29

def run(last_response=nil, step_responses=nil)

  self.configure(last_response, step_responses)

  # print the message if its just a preview
  return print_preview if self._preview

  _to = self._to
  _from = self._from
  _subject = self._subject
  _body = self._body
  _attachment = self._attachment

  if _to && _from && _subject && _body
    send_email(_to, _from, _subject, _body, _attachment)
  end
end

#send_email(_to, _from, _subject, _body, _attachment) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pushpop-sendgrid.rb', line 47

def send_email(_to, _from, _subject, _body, _attachment)
  Mail.deliver do
    to _to
    from _from
    subject _subject
    add_file _attachment if _attachment
    text_part do
      body _body
    end
    html_part do
      content_type 'text/html; charset=UTF-8'
      body _body
    end
  end
end

#subject(subject) ⇒ Object



75
76
77
# File 'lib/pushpop-sendgrid.rb', line 75

def subject(subject)
  self._subject = subject
end

#to(to) ⇒ Object



71
72
73
# File 'lib/pushpop-sendgrid.rb', line 71

def to(to)
  self._to = to
end