blastengine 0.1.0 → 0.2.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/blastengine.gemspec +39 -0
- data/lib/blastengine/bulk.rb +98 -0
- data/lib/blastengine/client.rb +37 -3
- data/lib/blastengine/transaction.rb +3 -0
- data/lib/blastengine/version.rb +1 -1
- data/lib/blastengine.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5f2374200e5fe2ca4fda4eb5440c4d443252cf87c771edf80ebd67e65408f6d
|
4
|
+
data.tar.gz: 238f73b30b0786fdb7376dc9ebdf10c854c7539093acf1a07db3d7bcbd2ae55d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f738c2aaa8efe12b219ff97b3189b17f163ae452c7a37d1aac5a7342f735c90a29659b43fc80cdf52ea0ca7b9181fe5bd40654b3b3fdbb44e5f363d842f76bf9
|
7
|
+
data.tar.gz: 481c6708c05f9b4d6d3273574fb5b8c2700bc2bdebb53cec9e67fcb04b1295509282ccae09f392a5b4d3c6b4fcc13b2d227d98e0e6a518ff88a6d24e977ea801
|
data/blastengine.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/blastengine/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "blastengine"
|
7
|
+
spec.version = Blastengine::VERSION
|
8
|
+
spec.authors = ["Atsushi Nakatsugawa"]
|
9
|
+
spec.email = ["atsushi@moongift.jp"]
|
10
|
+
|
11
|
+
spec.summary = "SDK for sending email by blastengine"
|
12
|
+
spec.description = "This is a SDK for sending email by blastengine."
|
13
|
+
spec.homepage = "https://blastengine.jp/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/blastengineMania/blastengine-ruby"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/blastengineMania/blastengine-ruby/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require "time"
|
2
|
+
|
3
|
+
module Blastengine
|
4
|
+
class Bulk
|
5
|
+
include Blastengine
|
6
|
+
attr_accessor :subject, :text_part, :encode, :html_part, :attachments, :delivery_id
|
7
|
+
def initialize
|
8
|
+
@to = []
|
9
|
+
@attachments = []
|
10
|
+
@encode = "UTF-8"
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# 送信主の追加
|
15
|
+
#
|
16
|
+
def from(email, name = "")
|
17
|
+
@_from = {email: email, name: name}
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# バルクメールの登録
|
22
|
+
#
|
23
|
+
def register
|
24
|
+
# APIリクエスト用のパス
|
25
|
+
path = "/deliveries/bulk/begin"
|
26
|
+
data = {
|
27
|
+
from: @_from,
|
28
|
+
subject: @subject,
|
29
|
+
encode: @encode,
|
30
|
+
text_part: @text_part,
|
31
|
+
}
|
32
|
+
# HTMLパートがある場合は追加
|
33
|
+
data[:html_part] = @html_part unless @html_part.nil?
|
34
|
+
# API実行
|
35
|
+
res = @@client.post path, data, @attachments
|
36
|
+
@delivery_id = res["delivery_id"]
|
37
|
+
return res["delivery_id"]
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# 受信者の追加
|
42
|
+
#
|
43
|
+
def add(email, params = {})
|
44
|
+
@to << {
|
45
|
+
email: email,
|
46
|
+
insert_code: params.map{|key, value| {
|
47
|
+
key: "__#{key}__",
|
48
|
+
value: value
|
49
|
+
}}
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# バルクメールの更新
|
55
|
+
#
|
56
|
+
def update
|
57
|
+
# APIリクエスト用のパス
|
58
|
+
path = "/deliveries/bulk/update/#{@delivery_id}"
|
59
|
+
data = {
|
60
|
+
to: @to
|
61
|
+
}
|
62
|
+
# subject, text_part, from, html_partはあれば追加
|
63
|
+
data[:subject] = @subject unless @subject.nil?
|
64
|
+
data[:from] = @_from unless @_from.nil?
|
65
|
+
data[:text_part] = @text_part unless @text_part.nil?
|
66
|
+
data[:html_part] = @html_part unless @html_part.nil?
|
67
|
+
# API実行
|
68
|
+
res = @@client.put path, data
|
69
|
+
return res["delivery_id"]
|
70
|
+
end
|
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
|
+
#
|
83
|
+
# バルクメールの送信
|
84
|
+
#
|
85
|
+
def send(date = nil)
|
86
|
+
# APIリクエスト用のパス
|
87
|
+
path = date ?
|
88
|
+
"/deliveries/bulk/commit/#{@delivery_id}" :
|
89
|
+
"/deliveries/bulk/commit/#{@delivery_id}/immediate"
|
90
|
+
# APIリクエスト用のデータ
|
91
|
+
data = date ? {reservation_time: date.iso8601} : {}
|
92
|
+
# API実行
|
93
|
+
res = @@client.patch path, data
|
94
|
+
# エラーがあったら例外を投げるので、この場合は通常終了
|
95
|
+
return res["delivery_id"]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/blastengine/client.rb
CHANGED
@@ -64,7 +64,7 @@ module Blastengine
|
|
64
64
|
# APIリクエストを行うFaradayのインスタンスを返す
|
65
65
|
# 添付ファイルの有無によって返すオブジェクトが異なる
|
66
66
|
#
|
67
|
-
def conn(attachment_count)
|
67
|
+
def conn(attachment_count = 0)
|
68
68
|
# 共通の設定
|
69
69
|
url = "https://#{DOMAIN}"
|
70
70
|
headers = {
|
@@ -93,7 +93,7 @@ module Blastengine
|
|
93
93
|
#
|
94
94
|
# POSTリクエスト用のデータを生成する
|
95
95
|
#
|
96
|
-
def post_data(data, attachments)
|
96
|
+
def post_data(data, attachments = [])
|
97
97
|
# 添付ファイルがない場合は、データをJSONに変換して返す
|
98
98
|
return data.to_json if attachments.length == 0
|
99
99
|
# 添付ファイルがある場合はファイルを読み込んで返す
|
@@ -115,6 +115,41 @@ module Blastengine
|
|
115
115
|
params = self.post_data data, attachments
|
116
116
|
# リクエスト実行
|
117
117
|
res = self.conn(attachments.size).post("#{BASE_PATH}#{path}", params)
|
118
|
+
# レスポンスを処理
|
119
|
+
return self.handle_response res
|
120
|
+
end
|
121
|
+
|
122
|
+
#
|
123
|
+
# PUTリクエストを行う
|
124
|
+
#
|
125
|
+
def put(path, data)
|
126
|
+
# リクエスト実行
|
127
|
+
res = self.conn.put("#{BASE_PATH}#{path}", data.to_json)
|
128
|
+
# レスポンスを処理
|
129
|
+
return self.handle_response res
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# PATCHリクエストを行う
|
134
|
+
#
|
135
|
+
def patch(path, data)
|
136
|
+
# リクエスト実行
|
137
|
+
res = self.conn.patch("#{BASE_PATH}#{path}", data.to_json)
|
138
|
+
# レスポンスを処理
|
139
|
+
return self.handle_response res
|
140
|
+
end
|
141
|
+
|
142
|
+
def delete(path)
|
143
|
+
# リクエスト実行
|
144
|
+
res = self.conn.delete("#{BASE_PATH}#{path}")
|
145
|
+
# レスポンスを処理
|
146
|
+
return self.handle_response res
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# レスポンスのハンドリング用
|
151
|
+
#
|
152
|
+
def handle_response(res)
|
118
153
|
# レスポンスをJSONパース
|
119
154
|
json = JSON.parse res.body
|
120
155
|
# 200または201なら、レスポンスを返す
|
@@ -124,6 +159,5 @@ module Blastengine
|
|
124
159
|
@@last_error = Blastengine::Error.new message
|
125
160
|
raise @@last_error
|
126
161
|
end
|
127
|
-
|
128
162
|
end
|
129
163
|
end
|
data/lib/blastengine/version.rb
CHANGED
data/lib/blastengine.rb
CHANGED
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.2.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-09-
|
11
|
+
date: 2022-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This is a SDK for sending email by blastengine.
|
14
14
|
email:
|
@@ -25,7 +25,9 @@ files:
|
|
25
25
|
- LICENSE
|
26
26
|
- README.md
|
27
27
|
- Rakefile
|
28
|
+
- blastengine.gemspec
|
28
29
|
- lib/blastengine.rb
|
30
|
+
- lib/blastengine/bulk.rb
|
29
31
|
- lib/blastengine/client.rb
|
30
32
|
- lib/blastengine/transaction.rb
|
31
33
|
- lib/blastengine/version.rb
|