Class: Mailercity::Message

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/mailercity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#underscore

Constructor Details

#initialize(args) ⇒ Message

Returns a new instance of Message.



71
72
73
74
# File 'lib/mailercity.rb', line 71

def initialize(args)
  @template = args.fetch(:template)
  @params = args.fetch(:params)
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



69
70
71
# File 'lib/mailercity.rb', line 69

def params
  @params
end

#templateObject (readonly)

Returns the value of attribute template.



69
70
71
# File 'lib/mailercity.rb', line 69

def template
  @template
end

Instance Method Details

#deliverObject



80
81
82
83
84
85
86
# File 'lib/mailercity.rb', line 80

def deliver
  log = "[#{self.class.name}] Posting to #{Mailercity.api_base}/#{mailer_name}/#{template}: #{params.to_json}"
  Mailercity.logger.info(log) unless Mailercity.logger.nil?
  return true if Mailercity.perform_deliveries == false
  response = Mailercity.request("/#{mailer_name}/#{template}", params)
  response.status == 201
end

#mailer_nameObject



76
77
78
# File 'lib/mailercity.rb', line 76

def mailer_name
  underscore self.class.name.split(/::/).last
end