Class: Blastengine::Transaction

Inherits:
Base
  • Object
show all
Includes:
Blastengine
Defined in:
lib/blastengine/transaction.rb

Constant Summary

Constants included from Blastengine

BASE_PATH, DOMAIN, VERSION

Instance Attribute Summary collapse

Attributes inherited from Base

#created_time, #delivery_id, #delivery_time, #delivery_type, #drop_count, #hard_error_count, #open_count, #sent_count, #soft_error_count, #status, #total_count, #updated_time

Instance Method Summary collapse

Methods included from Blastengine

#email, initialize

Methods inherited from Base

#cancel, #client, client, #delete, #get, #set, #sets, #unsubscribe

Constructor Details

#initializeTransaction

Returns a new instance of Transaction.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/blastengine/transaction.rb', line 7

def initialize
  @to = ""
  @cc = []
  @bcc = []
  @attachments = []
  @encode = "UTF-8"
  @insert_code = {}
  @list_unsubscribe = {
    url: "",
    email: ""
  }
end

Instance Attribute Details

#attachmentsObject

Returns the value of attribute attachments.



6
7
8
# File 'lib/blastengine/transaction.rb', line 6

def attachments
  @attachments
end

#bccObject

Returns the value of attribute bcc.



6
7
8
# File 'lib/blastengine/transaction.rb', line 6

def bcc
  @bcc
end

#ccObject

Returns the value of attribute cc.



6
7
8
# File 'lib/blastengine/transaction.rb', line 6

def cc
  @cc
end

#encodeObject

Returns the value of attribute encode.



6
7
8
# File 'lib/blastengine/transaction.rb', line 6

def encode
  @encode
end

#html_partObject

Returns the value of attribute html_part.



6
7
8
# File 'lib/blastengine/transaction.rb', line 6

def html_part
  @html_part
end

#insert_codeObject

Returns the value of attribute insert_code.



6
7
8
# File 'lib/blastengine/transaction.rb', line 6

def insert_code
  @insert_code
end

#list_unsubscribeObject

Returns the value of attribute list_unsubscribe.



6
7
8
# File 'lib/blastengine/transaction.rb', line 6

def list_unsubscribe
  @list_unsubscribe
end

#subjectObject

Returns the value of attribute subject.



6
7
8
# File 'lib/blastengine/transaction.rb', line 6

def subject
  @subject
end

#text_partObject

Returns the value of attribute text_part.



6
7
8
# File 'lib/blastengine/transaction.rb', line 6

def text_part
  @text_part
end

#toObject

Returns the value of attribute to.



6
7
8
# File 'lib/blastengine/transaction.rb', line 6

def to
  @to
end

Instance Method Details

#from(email:, name: "") ⇒ Object

送信主の追加



23
24
25
# File 'lib/blastengine/transaction.rb', line 23

def from(email:, name: "")
  @_from = {email: email, name: name}
end

#sendObject

トランザクションメールの送信



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/blastengine/transaction.rb', line 30

def send
  # APIリクエスト用のパス
  path = "/deliveries/transaction"
  # APIリクエスト用のデータ
  data = {
    from: @_from,
    to: @to,
    cc: @cc,
    bcc: @bcc,
    subject: @subject,
    encode: @encode,
    text_part: @text_part,
  }
  # HTMLパートがある場合は追加
  data[:html_part] = @html_part unless @html_part.nil?
  if @insert_code != nil
    data[:insert_code] = @insert_code.map do |key, value|
      {
        key: "__#{key}__",
        value: value
      }
    end
  end
  unless @list_unsubscribe.nil?
    data[:list_unsubscribe] = {}
    data[:list_unsubscribe][:url] = @list_unsubscribe[:url] if !@list_unsubscribe[:url].nil? && @list_unsubscribe[:url] != ""
    data[:list_unsubscribe][:mailto] = "mailto:#{@list_unsubscribe[:email]}" if !@list_unsubscribe[:email].nil? && @list_unsubscribe[:email] != ""
  end
  # API実行
  res = @@client.post path, data, @attachments
  # エラーがあったら例外を投げるので、この場合は通常終了
  @delivery_id = res["delivery_id"]
  return res["delivery_id"]
end