blastengine 0.1.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 +7 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +46 -0
- data/LICENSE +21 -0
- data/README.md +65 -0
- data/Rakefile +4 -0
- data/lib/blastengine/client.rb +129 -0
- data/lib/blastengine/transaction.rb +37 -0
- data/lib/blastengine/version.rb +5 -0
- data/lib/blastengine.rb +10 -0
- data/sig/blastengine.rbs +4 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a32c93429a747fae165318a2078c7e39750469c07f4fe8e974adc162d4ab0db8
|
4
|
+
data.tar.gz: 7eaa9bf6dc06fd82269c860307a870a18a369bc7a8189372ff6d672164b812be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 716f9265649718d4aa3a5d7895b3bc46c63bb920adceecb8ca650ee4a0a171788c8a7c574d934580d4db64a3c10d228732d026f95ddede1d7dc80725bb9c4fdb
|
7
|
+
data.tar.gz: fdf904fea321762b809b43ef43ca534279189f16bf814aa7d47772bc1a24c8d106c40d24f0037a9a35c967179e7e03833dbcb00b20162f02e0876d47cc09520d
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at nakatsugawa@AtsushinoMac-mini.local. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
blastengine (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.5.0)
|
10
|
+
faraday (2.5.2)
|
11
|
+
faraday-net_http (>= 2.0, < 3.1)
|
12
|
+
ruby2_keywords (>= 0.0.4)
|
13
|
+
faraday-multipart (1.0.4)
|
14
|
+
multipart-post (~> 2)
|
15
|
+
faraday-net_http (3.0.0)
|
16
|
+
mini_mime (1.1.2)
|
17
|
+
multipart-post (2.2.3)
|
18
|
+
rake (13.0.6)
|
19
|
+
rspec (3.11.0)
|
20
|
+
rspec-core (~> 3.11.0)
|
21
|
+
rspec-expectations (~> 3.11.0)
|
22
|
+
rspec-mocks (~> 3.11.0)
|
23
|
+
rspec-core (3.11.0)
|
24
|
+
rspec-support (~> 3.11.0)
|
25
|
+
rspec-expectations (3.11.1)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.11.0)
|
28
|
+
rspec-mocks (3.11.1)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.11.0)
|
31
|
+
rspec-support (3.11.1)
|
32
|
+
ruby2_keywords (0.0.5)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
arm64-darwin-21
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
blastengine!
|
39
|
+
faraday
|
40
|
+
faraday-multipart
|
41
|
+
mini_mime
|
42
|
+
rake (~> 13.0)
|
43
|
+
rspec (~> 3.9)
|
44
|
+
|
45
|
+
BUNDLED WITH
|
46
|
+
2.3.7
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright © 2022 Atsushi Nakatsugawa
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the “Software”), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Blastengine SDK
|
2
|
+
|
3
|
+
Blastengine SDKは、Rubyを用いて[エンジニア向けメール配信システム「ブラストエンジン」](https://blastengine.jp/)にてメール送信を行うSDKです。
|
4
|
+
|
5
|
+
## インストール
|
6
|
+
|
7
|
+
Gemfileに以下を追加します。
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'blastengine'
|
11
|
+
```
|
12
|
+
|
13
|
+
そして下記コマンドを実行します。
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
またはgemコマンドでインストールしてください。
|
18
|
+
|
19
|
+
$ gem install blastengine
|
20
|
+
|
21
|
+
## 使い方
|
22
|
+
|
23
|
+
### 初期化
|
24
|
+
|
25
|
+
APIキーとユーザー名はblastengineのサイトで取得してください。
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
client = Blastengine.initialize api_key: "API_KEY", user_name: "YOUR_USER_NAME"
|
29
|
+
```
|
30
|
+
|
31
|
+
### トランザクションメール
|
32
|
+
|
33
|
+
#### テキストメール
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
transaction = Blastengine::Transaction.new
|
37
|
+
transaction.from "admin@example.com", "Administrator"
|
38
|
+
transaction.to << "user@example.jp"
|
39
|
+
transaction.subject = "Test subject"
|
40
|
+
transaction.text_part = "This is a test email"
|
41
|
+
transaction.html_part = "<H1>Hello, world!</h1>"
|
42
|
+
delivery_id = transaction.send
|
43
|
+
```
|
44
|
+
|
45
|
+
#### 添付ファイル付きメール
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
transaction = Blastengine::Transaction.new
|
49
|
+
transaction.from "admin@example.com", "Administrator"
|
50
|
+
transaction.to << "user@example.jp"
|
51
|
+
transaction.subject = "Test subject"
|
52
|
+
transaction.text_part = "This is a test email"
|
53
|
+
transaction.html_part = "<H1>Hello, world!</h1>"
|
54
|
+
transaction.attachments << "README.md"
|
55
|
+
transaction.attachments << "./spec/test.jpg"
|
56
|
+
delivery_id = transaction.send
|
57
|
+
```
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
62
|
+
|
63
|
+
## Code of Conduct
|
64
|
+
|
65
|
+
Everyone interacting in the Blastengine project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/blastengineMania/blastengine/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "base64"
|
3
|
+
require "digest/sha2"
|
4
|
+
require "faraday"
|
5
|
+
require "faraday/multipart"
|
6
|
+
require "json"
|
7
|
+
require "mini_mime"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Blastengine SDKのモジュール
|
11
|
+
#
|
12
|
+
module Blastengine
|
13
|
+
# APIエンドポイント
|
14
|
+
DOMAIN = "app.engn.jp"
|
15
|
+
# APIのベースパス
|
16
|
+
BASE_PATH = "/api/v1"
|
17
|
+
# APIリクエストエラーが入る変数
|
18
|
+
@@last_error = nil
|
19
|
+
# APIクライアントが入る変数
|
20
|
+
@@client = nil
|
21
|
+
|
22
|
+
#
|
23
|
+
# Blastengine SDKを初期化する
|
24
|
+
#
|
25
|
+
def Blastengine.initialize(api_key:, user_name:)
|
26
|
+
@@client = Client.new api_key, user_name
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Blastengine SDKクライアント
|
31
|
+
# 基本的に各メール機能から呼ばれる
|
32
|
+
#
|
33
|
+
class Client
|
34
|
+
include Blastengine
|
35
|
+
# APIキー
|
36
|
+
@api_key = nil
|
37
|
+
# ユーザー名
|
38
|
+
@user_name = nil
|
39
|
+
# トークン
|
40
|
+
@token = nil
|
41
|
+
|
42
|
+
#
|
43
|
+
# コンストラクター
|
44
|
+
# APIキー、ユーザー名の設定とトークンの生成を行う
|
45
|
+
#
|
46
|
+
def initialize(api_key, user_name)
|
47
|
+
self.api_key = api_key
|
48
|
+
self.user_name = user_name
|
49
|
+
self.generate_token
|
50
|
+
end
|
51
|
+
# アクセッサー
|
52
|
+
attr_accessor :token, :api_key, :user_name
|
53
|
+
|
54
|
+
#
|
55
|
+
# トークンを生成する
|
56
|
+
#
|
57
|
+
def generate_token
|
58
|
+
return @token unless @token.nil?
|
59
|
+
str = "#{@user_name}#{@api_key}";
|
60
|
+
@token = Base64.urlsafe_encode64 Digest::SHA256.hexdigest(str).downcase
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# APIリクエストを行うFaradayのインスタンスを返す
|
65
|
+
# 添付ファイルの有無によって返すオブジェクトが異なる
|
66
|
+
#
|
67
|
+
def conn(attachment_count)
|
68
|
+
# 共通の設定
|
69
|
+
url = "https://#{DOMAIN}"
|
70
|
+
headers = {
|
71
|
+
"Authorization": "Bearer #{@token}"
|
72
|
+
}
|
73
|
+
# 添付ファイルがある場合
|
74
|
+
if attachment_count > 0
|
75
|
+
# MultiPartの設定をして返す
|
76
|
+
Faraday.new(
|
77
|
+
url: url,
|
78
|
+
headers: headers
|
79
|
+
) do |faraday|
|
80
|
+
faraday.request :multipart, flat_encode: true
|
81
|
+
end
|
82
|
+
else
|
83
|
+
# 添付ファイルがない場合
|
84
|
+
# JSONの設定をして返す
|
85
|
+
headers["Content-Type"] = "application/json"
|
86
|
+
Faraday.new(
|
87
|
+
url: url,
|
88
|
+
headers: headers
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# POSTリクエスト用のデータを生成する
|
95
|
+
#
|
96
|
+
def post_data(data, attachments)
|
97
|
+
# 添付ファイルがない場合は、データをJSONに変換して返す
|
98
|
+
return data.to_json if attachments.length == 0
|
99
|
+
# 添付ファイルがある場合はファイルを読み込んで返す
|
100
|
+
return {
|
101
|
+
data: Faraday::Multipart::ParamPart.new(data.to_json, "application/json"),
|
102
|
+
file: attachments.map{|a| Faraday::Multipart::FilePart.new(
|
103
|
+
File.open(a),
|
104
|
+
MiniMime.lookup_by_filename(a) ? MiniMime.lookup_by_filename(a).content_type : "application/octet-stream",
|
105
|
+
File.basename(a)
|
106
|
+
)}
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# POSTリクエストを行う
|
112
|
+
#
|
113
|
+
def post(path, data, attachments = [])
|
114
|
+
# リクエストボディの生成
|
115
|
+
params = self.post_data data, attachments
|
116
|
+
# リクエスト実行
|
117
|
+
res = self.conn(attachments.size).post("#{BASE_PATH}#{path}", params)
|
118
|
+
# レスポンスをJSONパース
|
119
|
+
json = JSON.parse res.body
|
120
|
+
# 200または201なら、レスポンスを返す
|
121
|
+
return json if res.status == 200 or res.status == 201
|
122
|
+
# それ以外はエラーを生成して例外処理
|
123
|
+
message = json["error_messages"].map{|key, value| "Error in #{key} (#{value})"}.join("\n")
|
124
|
+
@@last_error = Blastengine::Error.new message
|
125
|
+
raise @@last_error
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Blastengine
|
2
|
+
class Transaction
|
3
|
+
include Blastengine
|
4
|
+
attr_accessor :to, :subject, :text_part, :encode, :html_part, :attachments
|
5
|
+
def initialize
|
6
|
+
@to = []
|
7
|
+
@attachments = []
|
8
|
+
@encode = "UTF-8"
|
9
|
+
end
|
10
|
+
|
11
|
+
def from(email, name = "")
|
12
|
+
@_from = {email: email, name: name}
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# トランザクションメールの送信
|
17
|
+
#
|
18
|
+
def send
|
19
|
+
# APIリクエスト用のパス
|
20
|
+
path = "/deliveries/transaction"
|
21
|
+
# APIリクエスト用のデータ
|
22
|
+
data = {
|
23
|
+
from: @_from,
|
24
|
+
to: @to.join(","),
|
25
|
+
subject: @subject,
|
26
|
+
encode: @encode,
|
27
|
+
text_part: @text_part,
|
28
|
+
}
|
29
|
+
# HTMLパートがある場合は追加
|
30
|
+
data[:html_part] = @html_part unless @html_part.nil?
|
31
|
+
# API実行
|
32
|
+
res = @@client.post path, data, @attachments
|
33
|
+
# エラーがあったら例外を投げるので、この場合は通常終了
|
34
|
+
return res["delivery_id"]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/blastengine.rb
ADDED
data/sig/blastengine.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blastengine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Atsushi Nakatsugawa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This is a SDK for sending email by blastengine.
|
14
|
+
email:
|
15
|
+
- atsushi@moongift.jp
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- CHANGELOG.md
|
22
|
+
- CODE_OF_CONDUCT.md
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/blastengine.rb
|
29
|
+
- lib/blastengine/client.rb
|
30
|
+
- lib/blastengine/transaction.rb
|
31
|
+
- lib/blastengine/version.rb
|
32
|
+
- sig/blastengine.rbs
|
33
|
+
homepage: https://blastengine.jp/
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata:
|
37
|
+
homepage_uri: https://blastengine.jp/
|
38
|
+
source_code_uri: https://github.com/blastengineMania/blastengine-ruby
|
39
|
+
changelog_uri: https://github.com/blastengineMania/blastengine-ruby/CHANGELOG.md
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.6.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.3.7
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: SDK for sending email by blastengine
|
59
|
+
test_files: []
|