blastengine 0.3.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a47352b61b543f83adc3ae313d9c9298dcdb37487fd73b0a1c9eab8953d58c78
4
- data.tar.gz: e0ffb1caa1e5c7cf19f243e137d42e4b21fb8e1ec1167551aed0716d2ba55b65
3
+ metadata.gz: cb192455e96f1e16a8c2d70ac2035758bef80f0d5e56c0c651b33dd118558f15
4
+ data.tar.gz: 6fc1ef4846f1090cb4b57b38fe1ff1c063a8eeb4f47cadff2a930fb62b1af0f4
5
5
  SHA512:
6
- metadata.gz: 0eb29959156cd65b67a13d7937ce8a64faa7c4bab7d8e01371799681caf06afc8302357cb6a31f10eecec0f6f30b9af74f6b67dd05e36bcebf640f53bc760e84
7
- data.tar.gz: ac6a08967fa317c0691fd884a34b735f2dcd16ce52a7bae39d7702521db4ef7e82a4e2725fdbdc76245b921486f16bdf6f6e7d0441f54766de21d5971255fdb0
6
+ metadata.gz: 6c44da8ddac18082ebcf1fe7a3007bf242e7b3d3236c4b6479df8ae643b1f0f8762122716b87f8795cc245ad6ebe97aafa0de0e5325a6db2f59d6ad96da1cb76
7
+ data.tar.gz: 7001480e3afe9debb0d7ec8c95996450c79bb0e92eafbdbdc37758ea2aa7c277e938b8772b2a362d537f8ca32ca904d506028a2ac4645d265cb5208c53d6a842
@@ -37,5 +37,11 @@ module Blastengine
37
37
  res = @@client.delete path
38
38
  return res["delivery_id"]
39
39
  end
40
+
41
+ def report
42
+ report = Blastengine::Report.new @delivery_id
43
+ report.create
44
+ report
45
+ end
40
46
  end
41
47
  end
@@ -85,6 +85,14 @@ module Blastengine
85
85
  return res["delivery_id"]
86
86
  end
87
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
+
88
96
  def import(file, ignore_errors = false)
89
97
  # APIリクエスト用のパス
90
98
  path = "/deliveries/#{@delivery_id}/emails/import"
@@ -94,4 +102,8 @@ module Blastengine
94
102
  return @job
95
103
  end
96
104
  end
105
+
106
+ def email
107
+ Blastengine::Email.new(@delivery_id)
108
+ end
97
109
  end
@@ -120,7 +120,7 @@ module Blastengine
120
120
  #
121
121
  # POSTリクエストを行う
122
122
  #
123
- def post(path, data, attachments = [])
123
+ def post(path, data = {}, attachments = [])
124
124
  # リクエストボディの生成
125
125
  params = self.post_data data, attachments
126
126
  # リクエスト実行
@@ -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
@@ -1,9 +1,5 @@
1
- require "time"
2
- require "zip"
3
- require "tempfile"
4
-
5
1
  module Blastengine
6
- class Job < Base
2
+ class Job < Download
7
3
  include Blastengine
8
4
  attr_accessor :job_id, :percentage, :status, :error_file_url, :success_count, :failed_count, :total_count
9
5
  def initialize id
@@ -28,13 +24,7 @@ module Blastengine
28
24
  return nil if @error_file_url.nil?
29
25
  path = "/deliveries/-/emails/import/#{@job_id}/errorinfo/download"
30
26
  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
27
+ @error_message = download res
38
28
  @error_message
39
29
  end
40
30
  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,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Blastengine
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/blastengine.rb CHANGED
@@ -3,10 +3,13 @@
3
3
  require_relative "blastengine/version"
4
4
  require "blastengine/client"
5
5
  require "blastengine/base"
6
+ require "blastengine/download"
6
7
  require "blastengine/transaction"
7
8
  require "blastengine/bulk"
8
9
  require "blastengine/job"
9
10
  require "blastengine/usage"
11
+ require "blastengine/email"
12
+ require "blastengine/report"
10
13
 
11
14
  module Blastengine
12
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.3.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-10-23 00:00:00.000000000 Z
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:
@@ -30,7 +30,10 @@ files:
30
30
  - lib/blastengine/base.rb
31
31
  - lib/blastengine/bulk.rb
32
32
  - lib/blastengine/client.rb
33
+ - lib/blastengine/download.rb
34
+ - lib/blastengine/email.rb
33
35
  - lib/blastengine/job.rb
36
+ - lib/blastengine/report.rb
34
37
  - lib/blastengine/transaction.rb
35
38
  - lib/blastengine/usage.rb
36
39
  - lib/blastengine/version.rb