customers_mail_cloud 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6613c90dcec96e35935ff0c7a8bacf5fb0f542ef9b3fd90fc836ee2efbbf78cf
4
- data.tar.gz: 68daccd52615ec358995d5ea54594d37988cd65263646c62f6a99ad3dad1fe49
3
+ metadata.gz: 52ace0a622b1296cfaf753148596ae5dbc4353b003b47dab9281918b967b4d4b
4
+ data.tar.gz: 19068e35c021e5439f4a2ecb8e583ca2fc15d24f971c755f445a1f8082c3cac8
5
5
  SHA512:
6
- metadata.gz: 50c9cfa817d82ccd7d296456c0b0e610cd815853b8290fc43e35984912d5d33f906b8d37bfe50fc198beec59faa49d80ae05c8c59844ee50b3c34570fd6f173a
7
- data.tar.gz: dc2e82fad147ff7443e42a28b54c6eff57fc70cecfa99c3204b3cf55ca2547a3d066a7709f0a687148b63d4abb015e3e60c4d48f7119e6a84be1688a6d2154a8
6
+ metadata.gz: f83b5986d9996d2ef206091e73c393258dd9698b353912709533e6f5ddcba3972ca8ad883b7064490e3b9dd90ee8bc46e0adaf99533ef6b2ac9e93421911e859
7
+ data.tar.gz: bbc629ed5f045b77f37dbc6eb18f56b9efb09a2f1842b1cc3fd401b366c8ec0263b0e8701244e61d88546c23f12222c3af195f889b8913d361514f921b225c62
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- customers_mail_cloud (0.1.0)
4
+ customers_mail_cloud (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -49,6 +49,28 @@ client.attachments << open("./test.rb")
49
49
  json = client.send
50
50
  ```
51
51
 
52
+ ## Get Transaction
53
+
54
+ ### Get bounce
55
+
56
+ ```ruby
57
+ bounce = @client.bounce
58
+ bounce.server_composition = 'sandbox'
59
+ bounce.start_date = Date.parse("2020-11-20")
60
+ bounce.limit = 100
61
+ bounce.list
62
+ ```
63
+
64
+ ### Get delivery
65
+
66
+ ```ruby
67
+ delivery = @client.bounce
68
+ delivery.server_composition = 'sandbox'
69
+ delivery.date = Date.parse("2020-11-20")
70
+ delivery.limit = 100
71
+ delivery.list
72
+ ```
73
+
52
74
  ## Contributing
53
75
 
54
76
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/customers_mail_cloud. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/customers_mail_cloud/blob/master/CODE_OF_CONDUCT.md).
@@ -1,6 +1,7 @@
1
1
  require "customers_mail_cloud/version"
2
2
  require "customers_mail_cloud/client"
3
3
  require "customers_mail_cloud/mail_address"
4
+ require "customers_mail_cloud/transaction"
4
5
 
5
6
  module CustomersMailCloud
6
7
  class Error < StandardError; end
@@ -36,6 +36,18 @@ module CustomersMailCloud
36
36
  @url = @endpoints[:pro].gsub('SUBDOMAIN', subdomain)
37
37
  end
38
38
 
39
+ def bounce
40
+ Transaction.new 'bounces', self
41
+ end
42
+
43
+ def delivery
44
+ Transaction.new 'deliveries', self
45
+ end
46
+
47
+ def block
48
+ Transaction.new 'blocks', self
49
+ end
50
+
39
51
  def send
40
52
  raise Error.new '契約プランを選択してください(trial/standard/pro)' if @url == nil || @url == ''
41
53
  raise Error.new '送信元アドレスは必須です' if @from == nil
@@ -0,0 +1,91 @@
1
+ module CustomersMailCloud
2
+ class Transaction
3
+ def initialize type, client
4
+ @client = client
5
+ @type = type
6
+ @server_composition = nil
7
+ @base_url = 'https://api.smtps.jp/transaction/v2/__TYPE__/__ACTION__.json'
8
+ @params = {}
9
+ end
10
+
11
+ attr_accessor :server_composition
12
+
13
+ def url action
14
+ @base_url.gsub('__TYPE__', @type).gsub('__ACTION__', action)
15
+ end
16
+
17
+ def list
18
+ params = @params
19
+ params[:api_user] = @client.api_user
20
+ params[:api_key] = @client.api_key
21
+ unless @server_composition
22
+ raise Error.new('Server Composition is required.')
23
+ end
24
+ params[:server_composition] = @server_composition
25
+ headers = {
26
+ 'Content-Type': 'application/json',
27
+ 'Accept': 'application/json'
28
+ }
29
+ uri = URI.parse url('list')
30
+ req = Net::HTTP::Post.new(uri.path)
31
+ req.body = params.to_json
32
+ headers.each do |k, v|
33
+ req[k] = v
34
+ end
35
+ http = Net::HTTP.new uri.host, uri.port
36
+ http.use_ssl = true
37
+ response = http.request req
38
+ if response.code == '200' || response.code == '204'
39
+ return [] if response.body.nil?
40
+ return JSON.parse(response.body)[@type]
41
+ else
42
+ message = JSON.parse(response.body)['errors'].map do |error|
43
+ "#{error['message']} (#{error['code']})"
44
+ end.join(" ")
45
+ raise Error.new message
46
+ end
47
+ end
48
+
49
+ def email= address
50
+ @params[:email] = address
51
+ end
52
+
53
+ def status= status
54
+ @params[:status] = status
55
+ end
56
+
57
+ def start_date= date
58
+ @params[:start_date] = date.strftime('%Y-%m-%d')
59
+ end
60
+
61
+ def end_date= date
62
+ @params[:end_date] = date.strftime('%Y-%m-%d')
63
+ end
64
+
65
+ def date= date
66
+ @params[:date] = date.strftime('%Y-%m-%d')
67
+ end
68
+
69
+ def hour= hour
70
+ if hour < 0 || hour > 23
71
+ raise Error.new('hour allows the range from 0 to 23.')
72
+ end
73
+ @params[:hour] = hour
74
+ end
75
+
76
+ def minute= minute
77
+ if minute < 0 || minute > 59
78
+ raise Error.new('minute allows the range from 0 to 59.')
79
+ end
80
+ @params[:minute] = minute
81
+ end
82
+
83
+ def page= page
84
+ @params[:p] = page
85
+ end
86
+
87
+ def limit= limit
88
+ @params[:r] = limit
89
+ end
90
+ end
91
+ end
@@ -1,3 +1,3 @@
1
1
  module CustomersMailCloud
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: customers_mail_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atsushi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-21 00:00:00.000000000 Z
11
+ date: 2020-11-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby library for Customers Mail Cloud. Customers Mail Cloud is email
14
14
  sending service provider that supports SMTP or Web API.
@@ -33,6 +33,7 @@ files:
33
33
  - lib/customers_mail_cloud.rb
34
34
  - lib/customers_mail_cloud/client.rb
35
35
  - lib/customers_mail_cloud/mail_address.rb
36
+ - lib/customers_mail_cloud/transaction.rb
36
37
  - lib/customers_mail_cloud/version.rb
37
38
  homepage: https://smtps.jp/
38
39
  licenses: