blastengine 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9d7c3658112bf007f14c0db5b8e63c753c3ef74edb1428af29cc458229fa349
4
- data.tar.gz: 649c891776820ff43fefeb250f7d5359dc58acf5ebd20f4e8aeffd0f4ebd3afe
3
+ metadata.gz: 02bc35ccd669b289c2a0f988b9b45eb234b340ebe56f95f24b8428774edefa65
4
+ data.tar.gz: 9311a00bbbd6b704f5dcb7317ad80122606326519c4a929ba484f026a17e3e4f
5
5
  SHA512:
6
- metadata.gz: b8ccb93cbf79da083e1b5260d84a90450e090dd43603aafca3bf06b217f9c67fbb56ff17290a7949e7aec002c7891b11ec3f9f437404dcd7fb1fa76cd4c08942
7
- data.tar.gz: 3ed44fe674133c8a7bd58e661c03d9b1f65108e3e2f8cff80c521172a25d58e6e6d853cf9b36df9b16a5a47f9e8f779d9e75456f52fadb8615b937fb98c1b752
6
+ metadata.gz: 43416c93510d316fff59df714bc0e086539989d227691875fe34dc6579786d18ae85dc34c01db07065ab214d0ce9ad2b96a097b61ea626c2d7538c915fc1225c
7
+ data.tar.gz: 4e25b0934cf68ea34f62b6a671f2d79db388e50a1fbf47e0de4337a616363f57df8d15a9b277571c491bf964a00b71e87d248f5af71a68b53943cf62e9d6a1b1
data/README.md CHANGED
@@ -28,13 +28,71 @@ APIキーとユーザー名はblastengineのサイトで取得してください
28
28
  client = Blastengine.initialize api_key: "API_KEY", user_name: "YOUR_USER_NAME"
29
29
  ```
30
30
 
31
+ ### メール送信
32
+
33
+ ```ruby
34
+ mail = Blastengine::Mail.new
35
+ mail.from email: "admin@example.com", name: "Administrator"
36
+ mail.addTo email: config["to"], insert_code: { name1: "name 1" }
37
+ mail.subject = "Test email"
38
+ mail.text_part = "This is a test email __name1__"
39
+ mail.html_part = "<html><body>This is a test email __name1__</body></html>"
40
+ mail.attachments << "README.md"
41
+ bol = mail.send
42
+ expect(bol).to be true
43
+ delivery_id = mail.delivery_id
44
+ expect(delivery_id).to be_an(Integer)
45
+ ```
46
+
47
+ 送信先は制限なく登録できます。
48
+
49
+ ```ruby
50
+ mail = Blastengine::Mail.new
51
+ mail.from email: "admin@example.com", name: "Administrator"
52
+ 10000.times do |i|
53
+ mail.addTo email: "bulk#{i}@example.jp", insert_code: { name1: "name #{i}" }
54
+ end
55
+ mail.subject = "Test email"
56
+ mail.text_part = "This is a test email __name1__"
57
+ mail.html_part = "<html><body>This is a test email __name1__</body></html>"
58
+ mail.attachments << "README.md"
59
+ bol = mail.send
60
+ expect(bol).to be true
61
+ delivery_id = mail.delivery_id
62
+ expect(delivery_id).to be_an(Integer)
63
+ ```
64
+
65
+ ### メール検索
66
+
67
+ ```ruby
68
+ params = {
69
+ "delivery_start": Time.now - 60 * 60 * 24 * 30,
70
+ "delivery_end": Time.now,
71
+ "delivery_type": ["BULK"],
72
+ "status": ["EDIT", "SENT"]
73
+ }
74
+ ary = Blastengine::Mail.find params
75
+ ary[0].delivery_type # BULK
76
+ ary[0].status # SENT
77
+ ```
78
+
79
+ ### 配信ログ検索
80
+
81
+ ```ruby
82
+ params = {
83
+ "delivery_type": ["BULK"],
84
+ "status": ["EDIT", "SENT"]
85
+ }
86
+ ary = Blastengine::Log.find params
87
+ ```
88
+
31
89
  ### トランザクションメール
32
90
 
33
91
  #### テキストメール
34
92
 
35
93
  ```ruby
36
94
  transaction = Blastengine::Transaction.new
37
- transaction.from "admin@example.com", "Administrator"
95
+ transaction.from email: "admin@example.com", name: "Administrator"
38
96
  transaction.to = "user@example.jp"
39
97
  transaction.subject = "Test subject"
40
98
  transaction.text_part = "This is a test email"
@@ -1,3 +1,5 @@
1
+ require "date"
2
+
1
3
  module Blastengine
2
4
  class Base
3
5
  include Blastengine
@@ -1,6 +1,7 @@
1
1
  require "time"
2
2
  require "tempfile"
3
3
  require "csv"
4
+ require "date"
4
5
 
5
6
  module Blastengine
6
7
  class Bulk < Base
@@ -5,6 +5,7 @@ require "faraday"
5
5
  require "faraday/multipart"
6
6
  require "json"
7
7
  require "mini_mime"
8
+ require "date"
8
9
 
9
10
  #
10
11
  # Blastengine SDKのモジュール
@@ -1,3 +1,4 @@
1
+ require 'date'
1
2
  require "zip"
2
3
  require "tempfile"
3
4
 
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module Blastengine
2
4
  class Email < Base
3
5
  include Blastengine
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module Blastengine
2
4
  class Job < Download
3
5
  include Blastengine
@@ -0,0 +1,28 @@
1
+ require 'date'
2
+
3
+ module Blastengine
4
+ class Log < Base
5
+ include Blastengine
6
+ attr_accessor :cc, :bcc, :subject, :text_part, :encode, :html_part, :attachments, :delivery_id, :job
7
+
8
+ def self.from_hash(params)
9
+ log = Log.new
10
+ log.sets(params)
11
+ log
12
+ end
13
+
14
+ def self.find(params = {})
15
+ Hash[ params.map{|k,v| [k.to_sym, v] } ]
16
+ if params[:delivery_start] != nil
17
+ params[:delivery_start] = params[:delivery_start].iso8601
18
+ end
19
+ if params[:delivery_end] != nil
20
+ params[:delivery_end] = params[:delivery_end].iso8601
21
+ end
22
+ query_string = URI.encode_www_form(params)
23
+ url = "/logs/mails/results?#{query_string}";
24
+ res = Mail.client.get url
25
+ return res['data'].map {|params| Log.from_hash params }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,105 @@
1
+ require 'date'
2
+
3
+ module Blastengine
4
+ class Mail < Base
5
+ include Blastengine
6
+ attr_accessor :to, :cc, :bcc, :subject, :text_part, :encode, :html_part, :attachments, :delivery_id
7
+ def initialize
8
+ @to = []
9
+ @cc = []
10
+ @bcc = []
11
+ @attachments = []
12
+ @encode = "UTF-8"
13
+ end
14
+
15
+ #
16
+ # 送信主の追加
17
+ #
18
+ def from(email:, name: "")
19
+ @_from = {email: email, name: name}
20
+ end
21
+
22
+ #
23
+ # 受信者の追加
24
+ #
25
+ def addTo(email:, insert_code: {})
26
+ @to << {
27
+ email: email,
28
+ insert_code: insert_code
29
+ }
30
+ end
31
+
32
+ def send(date = nil)
33
+ # CCまたはBCCがある場合はTransaction × Toの分
34
+ # Toが複数の場合はBulk、Toが1つの場合はTransaction
35
+ if @cc.size > 0 || @bcc.size > 0
36
+ # CCまたはBCCがある場合は、指定時刻送信はできない
37
+ raise "CC or BCC is not supported when sending at a specified time." if date != nil
38
+ raise "CC or BCC is not supported when sending to multiple recipients." if @to.size > 1
39
+ end
40
+ if date != nil || @to.size == 1
41
+ return self.sendTransaction();
42
+ end
43
+ return self.sendBulk(date)
44
+ end
45
+
46
+ def sendBulk(date = nil)
47
+ bulk = Bulk.new
48
+ bulk.from email: @_from[:email], name: @_from[:name]
49
+ bulk.subject = @subject
50
+ bulk.encode = @encode
51
+ bulk.text_part = @text_part
52
+ bulk.html_part = @html_part
53
+ if @attachments.size > 0
54
+ bulk.attachments = @attachments
55
+ end
56
+ bulk.register
57
+ @to.each do |to|
58
+ bulk.addTo(to[:email], to[:insert_code])
59
+ end
60
+ bulk.update
61
+ bulk.send date
62
+ @delivery_id = bulk.delivery_id
63
+ return true;
64
+ end
65
+
66
+ def sendTransaction
67
+ transaction = Transaction.new
68
+ transaction.from email: @_from[:email], name: @_from[:name]
69
+ transaction.subject = @subject
70
+ transaction.encode = @encode
71
+ transaction.text_part = @text_part
72
+ transaction.html_part = @html_part
73
+ transaction.to = @to[0][:email]
74
+ transaction.insert_code = @to[0][:insert_code] if @to[0][:insert_code].size > 0
75
+ transaction.cc = @cc if @cc.size > 0
76
+ transaction.bcc = @bcc if @bcc.size > 0
77
+ if @attachments.size > 0
78
+ transaction.attachments = @attachments
79
+ end
80
+ transaction.send
81
+ @delivery_id = transaction.delivery_id
82
+ return true;
83
+ end
84
+
85
+ def self.from_hash(params)
86
+ mail = params["delivery_type"] == "TRANSACTION" ? Transaction.new : Bulk.new
87
+ mail.sets(params);
88
+ mail
89
+ end
90
+
91
+ def self.find(params = {})
92
+ Hash[ params.map{|k,v| [k.to_sym, v] } ]
93
+ if params[:delivery_start] != nil
94
+ params[:delivery_start] = params[:delivery_start].iso8601
95
+ end
96
+ if params[:delivery_end] != nil
97
+ params[:delivery_end] = params[:delivery_end].iso8601
98
+ end
99
+ query_string = URI.encode_www_form(params)
100
+ url = "/deliveries?#{query_string}";
101
+ res = Mail.client.get url
102
+ return res['data'].map {|params| Mail.from_hash params }
103
+ end
104
+ end
105
+ end
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module Blastengine
2
4
  class Report < Download
3
5
  include Blastengine
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module Blastengine
2
4
  class Transaction < Base
3
5
  include Blastengine
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module Blastengine
2
4
  class Usage < Base
3
5
  include Blastengine
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Blastengine
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blastengine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atsushi Nakatsugawa
@@ -32,6 +32,8 @@ files:
32
32
  - lib/blastengine/download.rb
33
33
  - lib/blastengine/email.rb
34
34
  - lib/blastengine/job.rb
35
+ - lib/blastengine/log.rb
36
+ - lib/blastengine/mail.rb
35
37
  - lib/blastengine/report.rb
36
38
  - lib/blastengine/transaction.rb
37
39
  - lib/blastengine/usage.rb