blastengine 0.2.1 → 0.3.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 +41 -0
- data/lib/blastengine/bulk.rb +11 -12
- data/lib/blastengine/client.rb +14 -4
- data/lib/blastengine/job.rb +41 -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 +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a47352b61b543f83adc3ae313d9c9298dcdb37487fd73b0a1c9eab8953d58c78
|
4
|
+
data.tar.gz: e0ffb1caa1e5c7cf19f243e137d42e4b21fb8e1ec1167551aed0716d2ba55b65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0eb29959156cd65b67a13d7937ce8a64faa7c4bab7d8e01371799681caf06afc8302357cb6a31f10eecec0f6f30b9af74f6b67dd05e36bcebf640f53bc760e84
|
7
|
+
data.tar.gz: ac6a08967fa317c0691fd884a34b735f2dcd16ce52a7bae39d7702521db4ef7e82a4e2725fdbdc76245b921486f16bdf6f6e7d0441f54766de21d5971255fdb0
|
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,41 @@
|
|
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
|
+
end
|
41
|
+
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,14 @@ module Blastengine
|
|
94
84
|
# エラーがあったら例外を投げるので、この場合は通常終了
|
95
85
|
return res["delivery_id"]
|
96
86
|
end
|
87
|
+
|
88
|
+
def import(file, ignore_errors = false)
|
89
|
+
# APIリクエスト用のパス
|
90
|
+
path = "/deliveries/#{@delivery_id}/emails/import"
|
91
|
+
# API実行
|
92
|
+
res = @@client.post path, {ignore_errors: ignore_errors}, [file]
|
93
|
+
@job = Blastengine::Job.new res["job_id"]
|
94
|
+
return @job
|
95
|
+
end
|
97
96
|
end
|
98
97
|
end
|
data/lib/blastengine/client.rb
CHANGED
@@ -107,6 +107,16 @@ 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
|
#
|
@@ -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,41 @@
|
|
1
|
+
require "time"
|
2
|
+
require "zip"
|
3
|
+
require "tempfile"
|
4
|
+
|
5
|
+
module Blastengine
|
6
|
+
class Job < Base
|
7
|
+
include Blastengine
|
8
|
+
attr_accessor :job_id, :percentage, :status, :error_file_url, :success_count, :failed_count, :total_count
|
9
|
+
def initialize id
|
10
|
+
@job_id = id
|
11
|
+
end
|
12
|
+
|
13
|
+
def finish?
|
14
|
+
# APIリクエスト用のパス
|
15
|
+
path = "/deliveries/-/emails/import/#{@job_id}"
|
16
|
+
res = @@client.get path
|
17
|
+
@percentage = res["percentage"]
|
18
|
+
@status = res["status"]
|
19
|
+
@error_file_url = res["error_file_url"] unless res["error_file_url"].nil?
|
20
|
+
@success_count = res["success_count"] unless res["success_count"].nil?
|
21
|
+
@failed_count = res["failed_count"] unless res["failed_count"].nil?
|
22
|
+
@total_count = res["total_count"] unless res["total_count"].nil?
|
23
|
+
return @percentage == 100
|
24
|
+
end
|
25
|
+
|
26
|
+
def error_message
|
27
|
+
return @error_message unless @error_message.nil?
|
28
|
+
return nil if @error_file_url.nil?
|
29
|
+
path = "/deliveries/-/emails/import/#{@job_id}/errorinfo/download"
|
30
|
+
res = @@client.get path, true
|
31
|
+
f = Tempfile.create("blastengine")
|
32
|
+
f.binmode
|
33
|
+
f.write res
|
34
|
+
f.flush
|
35
|
+
path = f.path
|
36
|
+
input = Zip::File.open path
|
37
|
+
@error_message = input.read input.entries[0].to_s
|
38
|
+
@error_message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
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,11 @@
|
|
2
2
|
|
3
3
|
require_relative "blastengine/version"
|
4
4
|
require "blastengine/client"
|
5
|
+
require "blastengine/base"
|
5
6
|
require "blastengine/transaction"
|
6
7
|
require "blastengine/bulk"
|
8
|
+
require "blastengine/job"
|
9
|
+
require "blastengine/usage"
|
7
10
|
|
8
11
|
module Blastengine
|
9
12
|
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.3.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-23 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,12 @@ 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/job.rb
|
32
34
|
- lib/blastengine/transaction.rb
|
35
|
+
- lib/blastengine/usage.rb
|
33
36
|
- lib/blastengine/version.rb
|
34
37
|
- sig/blastengine.rbs
|
35
38
|
homepage: https://blastengine.jp/
|