blastengine 0.2.1 → 0.4.0
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 +4 -4
- data/README.md +49 -2
- data/lib/blastengine/base.rb +47 -0
- data/lib/blastengine/bulk.rb +23 -12
- data/lib/blastengine/client.rb +15 -5
- data/lib/blastengine/download.rb +20 -0
- data/lib/blastengine/email.rb +71 -0
- data/lib/blastengine/job.rb +31 -0
- data/lib/blastengine/report.rb +37 -0
- data/lib/blastengine/transaction.rb +8 -4
- data/lib/blastengine/usage.rb +36 -0
- data/lib/blastengine/version.rb +1 -1
- data/lib/blastengine.rb +6 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb192455e96f1e16a8c2d70ac2035758bef80f0d5e56c0c651b33dd118558f15
|
4
|
+
data.tar.gz: 6fc1ef4846f1090cb4b57b38fe1ff1c063a8eeb4f47cadff2a930fb62b1af0f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c44da8ddac18082ebcf1fe7a3007bf242e7b3d3236c4b6479df8ae643b1f0f8762122716b87f8795cc245ad6ebe97aafa0de0e5325a6db2f59d6ad96da1cb76
|
7
|
+
data.tar.gz: 7001480e3afe9debb0d7ec8c95996450c79bb0e92eafbdbdc37758ea2aa7c277e938b8772b2a362d537f8ca32ca904d506028a2ac4645d265cb5208c53d6a842
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ client = Blastengine.initialize api_key: "API_KEY", user_name: "YOUR_USER_NAME"
|
|
35
35
|
```ruby
|
36
36
|
transaction = Blastengine::Transaction.new
|
37
37
|
transaction.from "admin@example.com", "Administrator"
|
38
|
-
transaction.to
|
38
|
+
transaction.to = "user@example.jp"
|
39
39
|
transaction.subject = "Test subject"
|
40
40
|
transaction.text_part = "This is a test email"
|
41
41
|
transaction.html_part = "<H1>Hello, world!</h1>"
|
@@ -47,7 +47,7 @@ delivery_id = transaction.send
|
|
47
47
|
```ruby
|
48
48
|
transaction = Blastengine::Transaction.new
|
49
49
|
transaction.from "admin@example.com", "Administrator"
|
50
|
-
transaction.to
|
50
|
+
transaction.to = "user@example.jp"
|
51
51
|
transaction.subject = "Test subject"
|
52
52
|
transaction.text_part = "This is a test email"
|
53
53
|
transaction.html_part = "<H1>Hello, world!</h1>"
|
@@ -56,6 +56,53 @@ transaction.attachments << "./spec/test.jpg"
|
|
56
56
|
delivery_id = transaction.send
|
57
57
|
```
|
58
58
|
|
59
|
+
### バルクメール
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
bulk = Blastengine::Bulk.new
|
63
|
+
bulk.from "admin@example.com", "Administrator"
|
64
|
+
bulk.subject = "Test bulk email"
|
65
|
+
bulk.text_part = "This is a test email to __name__"
|
66
|
+
# Register email as template
|
67
|
+
bulk.register
|
68
|
+
|
69
|
+
# Add address
|
70
|
+
bulk.add "test1@example.jp", {name: "User 1"}
|
71
|
+
bulk.add "test2@example.jp", {name: "User 2"}
|
72
|
+
bulk.update
|
73
|
+
|
74
|
+
# Send email immediately
|
75
|
+
bulk.send
|
76
|
+
|
77
|
+
# Send email 2 minutes later
|
78
|
+
bulk.send Time.now + 120
|
79
|
+
```
|
80
|
+
|
81
|
+
### アドレスのCSVアップロード
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
bulk = Blastengine::Bulk.new
|
85
|
+
bulk.from email: config["from"]["email"], name: config["from"]["name"]
|
86
|
+
bulk.subject = "Test bulk email, 2 minute later"
|
87
|
+
bulk.text_part = "This is a test email to __name__"
|
88
|
+
bulk.register
|
89
|
+
|
90
|
+
job = bulk.import "./spec/example.csv"
|
91
|
+
|
92
|
+
while !job.finish?
|
93
|
+
puts job.percentage
|
94
|
+
end
|
95
|
+
|
96
|
+
# Result of importing email addresses
|
97
|
+
job.total_count
|
98
|
+
job.success_count
|
99
|
+
job.failed_count
|
100
|
+
job.error_file_url
|
101
|
+
|
102
|
+
# Get error if there is it
|
103
|
+
job.error_message
|
104
|
+
```
|
105
|
+
|
59
106
|
## License
|
60
107
|
|
61
108
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Blastengine
|
2
|
+
class Base
|
3
|
+
include Blastengine
|
4
|
+
attr_accessor :delivery_id, :status, :delivery_time, :delivery_type, :open_count,
|
5
|
+
:created_time, :updated_time, :hard_error_count, :soft_error_count, :drop_count, :sent_count, :total_count
|
6
|
+
|
7
|
+
def get
|
8
|
+
# APIリクエスト用のパス
|
9
|
+
path = "/deliveries/#{@delivery_id}"
|
10
|
+
res = @@client.get path
|
11
|
+
# エラーがあったら例外を投げるので、この場合は通常終了
|
12
|
+
@delivery_type = res["delivery_type"]
|
13
|
+
@delivery_id = res["delivery_id"]
|
14
|
+
@status = res["status"]
|
15
|
+
@total_count = res["total_count"]
|
16
|
+
@sent_count = res["sent_count"]
|
17
|
+
@drop_count = res["drop_count"]
|
18
|
+
@hard_error_count = res["hard_error_count"]
|
19
|
+
@soft_error_count = res["soft_error_count"]
|
20
|
+
@open_count = res["open_count"]
|
21
|
+
@delivery_time = res["delivery_time"]
|
22
|
+
@reservation_time = res["reservation_time"]
|
23
|
+
@created_time = res["created_time"]
|
24
|
+
@updated_time = res["updated_time"]
|
25
|
+
@_from = res["from"]
|
26
|
+
@subject = res["subject"]
|
27
|
+
@text_part = res["text_part"]
|
28
|
+
@html_part = res["html_part"]
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# バルクメールの削除
|
33
|
+
#
|
34
|
+
def delete
|
35
|
+
path = "/deliveries/#{@delivery_id}"
|
36
|
+
# API実行
|
37
|
+
res = @@client.delete path
|
38
|
+
return res["delivery_id"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def report
|
42
|
+
report = Blastengine::Report.new @delivery_id
|
43
|
+
report.create
|
44
|
+
report
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/blastengine/bulk.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require "time"
|
2
2
|
|
3
3
|
module Blastengine
|
4
|
-
class Bulk
|
4
|
+
class Bulk < Base
|
5
5
|
include Blastengine
|
6
|
-
attr_accessor :subject, :text_part, :encode, :html_part, :attachments, :delivery_id
|
6
|
+
attr_accessor :subject, :text_part, :encode, :html_part, :attachments, :delivery_id, :job
|
7
7
|
def initialize
|
8
8
|
@to = []
|
9
9
|
@attachments = []
|
@@ -69,16 +69,6 @@ module Blastengine
|
|
69
69
|
return res["delivery_id"]
|
70
70
|
end
|
71
71
|
|
72
|
-
#
|
73
|
-
# バルクメールの削除
|
74
|
-
#
|
75
|
-
def delete
|
76
|
-
path = "/deliveries/#{@delivery_id}"
|
77
|
-
# API実行
|
78
|
-
res = @@client.delete path
|
79
|
-
return res["delivery_id"]
|
80
|
-
end
|
81
|
-
|
82
72
|
#
|
83
73
|
# バルクメールの送信
|
84
74
|
#
|
@@ -94,5 +84,26 @@ module Blastengine
|
|
94
84
|
# エラーがあったら例外を投げるので、この場合は通常終了
|
95
85
|
return res["delivery_id"]
|
96
86
|
end
|
87
|
+
|
88
|
+
def cancel
|
89
|
+
# APIリクエスト用のパス
|
90
|
+
path = "/deliveries/#{@delivery_id}/cancel"
|
91
|
+
# API実行
|
92
|
+
res = @@client.patch path, {}
|
93
|
+
return res["delivery_id"]
|
94
|
+
end
|
95
|
+
|
96
|
+
def import(file, ignore_errors = false)
|
97
|
+
# APIリクエスト用のパス
|
98
|
+
path = "/deliveries/#{@delivery_id}/emails/import"
|
99
|
+
# API実行
|
100
|
+
res = @@client.post path, {ignore_errors: ignore_errors}, [file]
|
101
|
+
@job = Blastengine::Job.new res["job_id"]
|
102
|
+
return @job
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def email
|
107
|
+
Blastengine::Email.new(@delivery_id)
|
97
108
|
end
|
98
109
|
end
|
data/lib/blastengine/client.rb
CHANGED
@@ -107,10 +107,20 @@ module Blastengine
|
|
107
107
|
}
|
108
108
|
end
|
109
109
|
|
110
|
+
#
|
111
|
+
# GETリクエストを行う
|
112
|
+
#
|
113
|
+
def get(path, binary = false)
|
114
|
+
# リクエスト実行
|
115
|
+
res = self.conn.get("#{BASE_PATH}#{path}")
|
116
|
+
# レスポンスを処理
|
117
|
+
return self.handle_response res, binary
|
118
|
+
end
|
119
|
+
|
110
120
|
#
|
111
121
|
# POSTリクエストを行う
|
112
122
|
#
|
113
|
-
def post(path, data, attachments = [])
|
123
|
+
def post(path, data = {}, attachments = [])
|
114
124
|
# リクエストボディの生成
|
115
125
|
params = self.post_data data, attachments
|
116
126
|
# リクエスト実行
|
@@ -149,13 +159,13 @@ module Blastengine
|
|
149
159
|
#
|
150
160
|
# レスポンスのハンドリング用
|
151
161
|
#
|
152
|
-
def handle_response(res)
|
162
|
+
def handle_response(res, binary = false)
|
153
163
|
# レスポンスをJSONパース
|
154
|
-
|
164
|
+
body = binary ? res.body : JSON.parse(res.body)
|
155
165
|
# 200または201なら、レスポンスを返す
|
156
|
-
return
|
166
|
+
return body if res.status == 200 or res.status == 201
|
157
167
|
# それ以外はエラーを生成して例外処理
|
158
|
-
message =
|
168
|
+
message = body["error_messages"].map{|key, value| "Error in #{key} (#{value})"}.join("\n")
|
159
169
|
@@last_error = Blastengine::Error.new message
|
160
170
|
raise @@last_error
|
161
171
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "zip"
|
2
|
+
require "tempfile"
|
3
|
+
|
4
|
+
module Blastengine
|
5
|
+
class Download < Base
|
6
|
+
include Blastengine
|
7
|
+
|
8
|
+
def download res
|
9
|
+
f = Tempfile.create("blastengine")
|
10
|
+
f.binmode
|
11
|
+
f.write res
|
12
|
+
f.flush
|
13
|
+
path = f.path
|
14
|
+
input = Zip::File.open path
|
15
|
+
data = input.read input.entries[0].to_s
|
16
|
+
f.close
|
17
|
+
return data
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Blastengine
|
2
|
+
class Email < Base
|
3
|
+
include Blastengine
|
4
|
+
attr_accessor :delivery_id, :address, :insert_code, :email_id, :created_time, :updated_time
|
5
|
+
def initialize delivery_id
|
6
|
+
@delivery_id = delivery_id
|
7
|
+
@insert_code = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def get
|
11
|
+
# APIリクエスト用のパス
|
12
|
+
path = "/deliveries/-/emails/#{@email_id}"
|
13
|
+
# API実行
|
14
|
+
res = @@client.get path
|
15
|
+
@email_id = res["email_id"]
|
16
|
+
res["insert_code"].each do |params|
|
17
|
+
@insert_code[params["key"].gsub("__", "")] = params["value"]
|
18
|
+
end
|
19
|
+
@address = res["email"]
|
20
|
+
@created_time = Time.parse(res["created_time"])
|
21
|
+
@updated_time = Time.parse(res["updated_time"])
|
22
|
+
return res["email_id"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def save
|
26
|
+
# APIリクエスト用のパス
|
27
|
+
if @email_id.nil?
|
28
|
+
return create
|
29
|
+
else
|
30
|
+
return update
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def create
|
35
|
+
path = "/deliveries/#{@delivery_id}/emails"
|
36
|
+
params = {
|
37
|
+
email: @address,
|
38
|
+
insert_code: @insert_code.map{|key, value| {
|
39
|
+
key: "__#{key}__",
|
40
|
+
value: value
|
41
|
+
}}
|
42
|
+
}
|
43
|
+
# API実行
|
44
|
+
res = @@client.post path, params
|
45
|
+
@email_id = res["email_id"]
|
46
|
+
return res["email_id"]
|
47
|
+
end
|
48
|
+
|
49
|
+
def update
|
50
|
+
path = "/deliveries/-/emails/#{@email_id}"
|
51
|
+
params = {
|
52
|
+
email: @address,
|
53
|
+
insert_code: @insert_code.map{|key, value| {
|
54
|
+
key: "__#{key}__",
|
55
|
+
value: value
|
56
|
+
}}
|
57
|
+
}
|
58
|
+
# API実行
|
59
|
+
res = @@client.put path, params
|
60
|
+
@email_id = res["email_id"]
|
61
|
+
return res["email_id"]
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete
|
65
|
+
path = "/deliveries/-/emails/#{@email_id}"
|
66
|
+
# API実行
|
67
|
+
res = @@client.delete path
|
68
|
+
return res["email_id"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Blastengine
|
2
|
+
class Job < Download
|
3
|
+
include Blastengine
|
4
|
+
attr_accessor :job_id, :percentage, :status, :error_file_url, :success_count, :failed_count, :total_count
|
5
|
+
def initialize id
|
6
|
+
@job_id = id
|
7
|
+
end
|
8
|
+
|
9
|
+
def finish?
|
10
|
+
# APIリクエスト用のパス
|
11
|
+
path = "/deliveries/-/emails/import/#{@job_id}"
|
12
|
+
res = @@client.get path
|
13
|
+
@percentage = res["percentage"]
|
14
|
+
@status = res["status"]
|
15
|
+
@error_file_url = res["error_file_url"] unless res["error_file_url"].nil?
|
16
|
+
@success_count = res["success_count"] unless res["success_count"].nil?
|
17
|
+
@failed_count = res["failed_count"] unless res["failed_count"].nil?
|
18
|
+
@total_count = res["total_count"] unless res["total_count"].nil?
|
19
|
+
return @percentage == 100
|
20
|
+
end
|
21
|
+
|
22
|
+
def error_message
|
23
|
+
return @error_message unless @error_message.nil?
|
24
|
+
return nil if @error_file_url.nil?
|
25
|
+
path = "/deliveries/-/emails/import/#{@job_id}/errorinfo/download"
|
26
|
+
res = @@client.get path, true
|
27
|
+
@error_message = download res
|
28
|
+
@error_message
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Blastengine
|
2
|
+
class Report < Download
|
3
|
+
include Blastengine
|
4
|
+
attr_accessor :job_id, :delivery_id, :percentage, :status, :mail_open_file_url, :total_count, :report
|
5
|
+
def initialize delivery_id
|
6
|
+
@delivery_id = delivery_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
# APIリクエスト用のパス
|
11
|
+
path = "/deliveries/#{@delivery_id}/analysis/report"
|
12
|
+
res = @@client.post path
|
13
|
+
@job_id = res["job_id"]
|
14
|
+
return @job_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def finish?
|
18
|
+
# APIリクエスト用のパス
|
19
|
+
path = "/deliveries/-/analysis/report/#{@job_id}"
|
20
|
+
res = @@client.get path
|
21
|
+
@percentage = res["percentage"]
|
22
|
+
@status = res["status"]
|
23
|
+
@total_count = res["total_count"] unless res["total_count"].nil?
|
24
|
+
@mail_open_file_url = res["mail_open_file_url"] unless res["mail_open_file_url"].nil?
|
25
|
+
return @percentage == 100
|
26
|
+
end
|
27
|
+
|
28
|
+
def get
|
29
|
+
return @report unless @report.nil?
|
30
|
+
return nil unless @percentage == 100
|
31
|
+
path = "/deliveries/-/analysis/report/#{@job_id}/download"
|
32
|
+
res = @@client.get path, true
|
33
|
+
@report = download res
|
34
|
+
@report
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module Blastengine
|
2
|
-
class Transaction
|
2
|
+
class Transaction < Base
|
3
3
|
include Blastengine
|
4
|
-
attr_accessor :to, :subject, :text_part, :encode, :html_part, :attachments
|
4
|
+
attr_accessor :to, :cc, :bcc, :subject, :text_part, :encode, :html_part, :attachments
|
5
5
|
def initialize
|
6
|
-
@to =
|
6
|
+
@to = ""
|
7
|
+
@cc = []
|
8
|
+
@bcc = []
|
7
9
|
@attachments = []
|
8
10
|
@encode = "UTF-8"
|
9
11
|
end
|
@@ -24,7 +26,9 @@ module Blastengine
|
|
24
26
|
# APIリクエスト用のデータ
|
25
27
|
data = {
|
26
28
|
from: @_from,
|
27
|
-
to: @to
|
29
|
+
to: @to,
|
30
|
+
cc: @cc,
|
31
|
+
bcc: @bcc,
|
28
32
|
subject: @subject,
|
29
33
|
encode: @encode,
|
30
34
|
text_part: @text_part,
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Blastengine
|
2
|
+
class Usage < Base
|
3
|
+
include Blastengine
|
4
|
+
attr_accessor :month, :current, :remaining, :updated_time, :plan_id
|
5
|
+
def initialize params
|
6
|
+
@month = params["month"]
|
7
|
+
@current = params["current"]
|
8
|
+
@remaining = params["remaining"]
|
9
|
+
@updated_time = params["updated_time"]
|
10
|
+
@plan_id = params["plan_id"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.all month_ago = 1
|
14
|
+
# APIリクエスト用のパス
|
15
|
+
path = "/usages?month_ago=#{month_ago}"
|
16
|
+
res = @@client.get path
|
17
|
+
res["data"].map do |params|
|
18
|
+
self.new params
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get month = Date.today.strftime("%Y%m")
|
23
|
+
# APIリクエスト用のパス
|
24
|
+
path = "/usages/#{month}"
|
25
|
+
res = @@client.get path
|
26
|
+
self.new res
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.latest
|
30
|
+
# APIリクエスト用のパス
|
31
|
+
path = "/usages/latest"
|
32
|
+
res = @@client.get path
|
33
|
+
self.new res
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/blastengine/version.rb
CHANGED
data/lib/blastengine.rb
CHANGED
@@ -2,8 +2,14 @@
|
|
2
2
|
|
3
3
|
require_relative "blastengine/version"
|
4
4
|
require "blastengine/client"
|
5
|
+
require "blastengine/base"
|
6
|
+
require "blastengine/download"
|
5
7
|
require "blastengine/transaction"
|
6
8
|
require "blastengine/bulk"
|
9
|
+
require "blastengine/job"
|
10
|
+
require "blastengine/usage"
|
11
|
+
require "blastengine/email"
|
12
|
+
require "blastengine/report"
|
7
13
|
|
8
14
|
module Blastengine
|
9
15
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blastengine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atsushi Nakatsugawa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This is a SDK for sending email by blastengine.
|
14
14
|
email:
|
@@ -27,9 +27,15 @@ files:
|
|
27
27
|
- Rakefile
|
28
28
|
- blastengine.gemspec
|
29
29
|
- lib/blastengine.rb
|
30
|
+
- lib/blastengine/base.rb
|
30
31
|
- lib/blastengine/bulk.rb
|
31
32
|
- lib/blastengine/client.rb
|
33
|
+
- lib/blastengine/download.rb
|
34
|
+
- lib/blastengine/email.rb
|
35
|
+
- lib/blastengine/job.rb
|
36
|
+
- lib/blastengine/report.rb
|
32
37
|
- lib/blastengine/transaction.rb
|
38
|
+
- lib/blastengine/usage.rb
|
33
39
|
- lib/blastengine/version.rb
|
34
40
|
- sig/blastengine.rbs
|
35
41
|
homepage: https://blastengine.jp/
|