Class: Timepad::Mail

Inherits:
Base
  • Object
show all
Defined in:
lib/timepad/mail.rb

Instance Method Summary collapse

Methods inherited from Base

#make_query, #make_uri, #request, #subscribers_to_hash

Constructor Details

#initialize(timepad_client) ⇒ Mail

Returns a new instance of Mail.



4
5
6
# File 'lib/timepad/mail.rb', line 4

def initialize(timepad_client)
  @client = timepad_client
end

Instance Method Details

#create(attrs) ⇒ Array

Create and send mail

Parameters:

  • attrs (Hash)

    mail attributes

Returns:

  • (Array)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/timepad/mail.rb', line 12

def create attrs
  params = {}
  params[:name] = attrs[:subject] if attrs.has_key?(:subject)
  params[:text] = attrs[:text] if attrs.has_key?(:text)
  params[:e_id] = attrs[:event] if attrs.has_key?(:event)
  params[:reply_to] = attrs[:reply_to] if attrs.has_key?(:reply_to)
  params[:template] = attrs[:template] if attrs.has_key?(:template)
  params[:org_info] = attrs[:org_info] if attrs.has_key?(:org_info)

  if attrs.has_key?(:subscribers)
    i = 0
    attrs[:subscribers].each do |email|
      params["a#{i}".to_sym] = email
      i += 1
    end
  end

  attrs[:maillists] ||= []
  if attrs.has_key?(:maillist)
    attrs[:maillists] << attrs[:maillist]
  end

  i = 0
  attrs[:maillists].each do |maillist_id|
    params["m#{i}".to_sym] = maillist_id
    i += 1
  end

  request 'create', params
end