Class: Blastengine::Bulk
- Includes:
- Blastengine
- Defined in:
- lib/blastengine/bulk.rb
Constant Summary
Constants included from Blastengine
Instance Attribute Summary collapse
-
#attachments ⇒ Object
Returns the value of attribute attachments.
-
#delivery_id ⇒ Object
Returns the value of attribute delivery_id.
-
#encode ⇒ Object
Returns the value of attribute encode.
-
#html_part ⇒ Object
Returns the value of attribute html_part.
-
#job ⇒ Object
Returns the value of attribute job.
-
#list_unsubscribe ⇒ Object
Returns the value of attribute list_unsubscribe.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#text_part ⇒ Object
Returns the value of attribute text_part.
Attributes inherited from Base
#created_time, #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
-
#addTo(email, params = {}) ⇒ Object
受信者の追加.
- #csv_update ⇒ Object
-
#from(email:, name: "") ⇒ Object
送信主の追加.
- #import(file, ignore_errors = false) ⇒ Object
-
#initialize ⇒ Bulk
constructor
A new instance of Bulk.
- #normal_update ⇒ Object
-
#register ⇒ Object
バルクメールの登録.
-
#send(date = nil) ⇒ Object
バルクメールの送信.
-
#update ⇒ Object
バルクメールの更新.
Methods included from Blastengine
Methods inherited from Base
#cancel, #client, client, #delete, #get, #set, #sets, #unsubscribe
Constructor Details
#initialize ⇒ Bulk
Returns a new instance of Bulk.
10 11 12 13 14 15 16 17 18 |
# File 'lib/blastengine/bulk.rb', line 10 def initialize @to = [] @attachments = [] @encode = "UTF-8" @list_unsubscribe = { url: "", email: "" } end |
Instance Attribute Details
#attachments ⇒ Object
Returns the value of attribute attachments.
9 10 11 |
# File 'lib/blastengine/bulk.rb', line 9 def @attachments end |
#delivery_id ⇒ Object
Returns the value of attribute delivery_id.
9 10 11 |
# File 'lib/blastengine/bulk.rb', line 9 def delivery_id @delivery_id end |
#encode ⇒ Object
Returns the value of attribute encode.
9 10 11 |
# File 'lib/blastengine/bulk.rb', line 9 def encode @encode end |
#html_part ⇒ Object
Returns the value of attribute html_part.
9 10 11 |
# File 'lib/blastengine/bulk.rb', line 9 def html_part @html_part end |
#job ⇒ Object
Returns the value of attribute job.
9 10 11 |
# File 'lib/blastengine/bulk.rb', line 9 def job @job end |
#list_unsubscribe ⇒ Object
Returns the value of attribute list_unsubscribe.
9 10 11 |
# File 'lib/blastengine/bulk.rb', line 9 def list_unsubscribe @list_unsubscribe end |
#subject ⇒ Object
Returns the value of attribute subject.
9 10 11 |
# File 'lib/blastengine/bulk.rb', line 9 def subject @subject end |
#text_part ⇒ Object
Returns the value of attribute text_part.
9 10 11 |
# File 'lib/blastengine/bulk.rb', line 9 def text_part @text_part end |
Instance Method Details
#addTo(email, params = {}) ⇒ Object
受信者の追加
56 57 58 59 60 61 62 63 64 |
# File 'lib/blastengine/bulk.rb', line 56 def addTo(email, params = {}) @to << { email: email, insert_code: params.map{|key, value| { key: "__#{key}__", value: value }} } end |
#csv_update ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/blastengine/bulk.rb', line 100 def csv_update f = Tempfile.create(['blastengine', '.csv']) f.close csv = CSV.open(f.path, "w") # ヘッダーの作成 headers = ["email"] @to.each do |to| to[:insert_code].each do |insert_code| headers << insert_code[:key] if headers.index(insert_code[:key]) == nil end end csv.puts headers @to.each do |to| lines = [to[:email]] headers.each do |header| next if header == "email" insert_code = to[:insert_code].find{|insert_code| insert_code[:key] == header} lines << insert_code[:value] if insert_code != nil end csv.puts lines end csv.close job = self.import f.path while !job.finish? sleep 1 end File.unlink f.path @delivery_id end |
#from(email:, name: "") ⇒ Object
送信主の追加
23 24 25 |
# File 'lib/blastengine/bulk.rb', line 23 def from(email:, name: "") @_from = {email: email, name: name} end |
#import(file, ignore_errors = false) ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/blastengine/bulk.rb', line 147 def import(file, ignore_errors = false) # APIリクエスト用のパス path = "/deliveries/#{@delivery_id}/emails/import" # API実行 res = @@client.post path, {ignore_errors: ignore_errors}, [file] @job = Blastengine::Job.new res["job_id"] return @job end |
#normal_update ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/blastengine/bulk.rb', line 77 def normal_update # APIリクエスト用のパス path = "/deliveries/bulk/update/#{@delivery_id}" data = { to: @to } # subject, text_part, from, html_partはあれば追加 data[:subject] = @subject unless @subject.nil? data[:from] = @_from unless @_from.nil? data[:text_part] = @text_part unless @text_part.nil? data[:html_part] = @html_part unless @html_part.nil? # 退会リンクがある場合は追加 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.put path, data return res["delivery_id"] end |
#register ⇒ Object
バルクメールの登録
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/blastengine/bulk.rb', line 30 def register # APIリクエスト用のパス path = "/deliveries/bulk/begin" data = { from: @_from, subject: @subject, encode: @encode, text_part: @text_part, } # HTMLパートがある場合は追加 data[:html_part] = @html_part unless @html_part.nil? # 退会リンクがある場合は追加 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 |
#send(date = nil) ⇒ Object
バルクメールの送信
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/blastengine/bulk.rb', line 133 def send(date = nil) # APIリクエスト用のパス path = date ? "/deliveries/bulk/commit/#{@delivery_id}" : "/deliveries/bulk/commit/#{@delivery_id}/immediate" # APIリクエスト用のデータ data = date ? {reservation_time: date.iso8601} : {} # API実行 res = @@client.patch path, data # エラーがあったら例外を投げるので、この場合は通常終了 @delivery_id = res["delivery_id"] return res["delivery_id"] end |
#update ⇒ Object
バルクメールの更新
69 70 71 72 73 74 75 |
# File 'lib/blastengine/bulk.rb', line 69 def update if @to.size > 50 return self.csv_update else return self.normal_update end end |