mailpy 0.1.3 → 0.1.4

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: 4abed45c631030cc0ce9c3dfbc1e411766c62c53ba16dbec1008204339009eff
4
- data.tar.gz: 53f6daf94bbc49ec9bd2575ecbd8ed92e42e9f8312c30dda3aab2dbe6b813287
3
+ metadata.gz: 385d9f2c54a82f019dda1cd1a3b66ed094a7f87abe5d0d7d40bb88ee54e4f2bb
4
+ data.tar.gz: '0796cd3016d2675fe446b0d2255c8359b35418ad3394646088d135c8c15109fc'
5
5
  SHA512:
6
- metadata.gz: 1bcd790724d95a2629436f415d3a8e24b45513a6a164db9c9f593c2392e1bd614a28722be6d1d1f2c260d5f463abf2a94c250c0e6ae6eb9b124a75dbe3b308c2
7
- data.tar.gz: 452893b081f16ea81ff9c00c06ca3f2993f3d411ee3bb5058144bd63caf46d3437b43b36fce98cabb5f33e5ab444dcccd45bde1215754463f308b4e15b22225e
6
+ metadata.gz: 854ae6892456083d68b93376d2a67ef075c49d3bd25957a6fc42f31a86e8281e233ba299212d368a2f2c9d400f03ced70e7a55d4bf5b5adc24c11f1e644f7521
7
+ data.tar.gz: fe9811beccd2286a53f49277870ff9de6b70707248e324edc79a8b79589642119c4dc7e18ab6ef073374f5b3cb0391d137baf6839494076d37c01b9656ac74e6
@@ -3,6 +3,8 @@ require "mailpy/mailer_api"
3
3
 
4
4
  module Mailpy
5
5
  class DeliveryMethod
6
+ MailpyDeliveryError = Class.new(StandardError)
7
+
6
8
  attr_accessor :settings
7
9
 
8
10
  def initialize(params)
@@ -10,20 +12,14 @@ module Mailpy
10
12
  end
11
13
 
12
14
  def deliver!(mail)
13
- MailerApi.new(mail_options(mail), mail.body.to_s).send
15
+ perform_send_request(mail, settings)
14
16
  end
15
17
 
16
18
  private
17
- def mail_options(mail)
18
- {
19
- to: mail.to.try(:join, ', '),
20
- cc: mail.cc.try(:join, ', '),
21
- bcc: mail.bcc.try(:join, ', '),
22
- sender: mail.from.try(:join, ', '),
23
- subject: mail.subject,
24
- endpoint: settings[:endpoint],
25
- token: settings[:token]
26
- }
27
- end
19
+ def perform_send_request(mail, settings)
20
+ result = MailerApi.new(mail, settings).send
21
+ raise(MailpyDeliveryError, JSON.parse(result.body)['message']) unless result.code === 200
22
+ result
23
+ end
28
24
  end
29
25
  end
@@ -1,34 +1,34 @@
1
1
  require 'httparty'
2
2
 
3
3
  class MailerApi
4
- attr_reader :options, :message
5
-
6
- def initialize(options, message)
4
+ def initialize(mail, options = {})
5
+ @mail = mail
7
6
  @options = options
8
- @message = message
9
7
  end
10
8
 
11
9
  def send
12
- send_email
13
- end
14
-
15
- private
16
- def send_email
17
10
  result = HTTParty.post(
18
11
  options[:endpoint],
19
- body: {
20
- sender_email: options[:sender],
21
- recipient_email: options[:to],
22
- cc_email: options[:cc],
23
- bcc_email: options[:bcc],
24
- subject_email: options[:subject],
25
- message_email: message
26
- }.to_json,
27
-
28
- headers: {
29
- 'Content-Type': 'application/json',
30
- 'Authorization': options[:token].to_s
31
- }
32
- )
12
+ body: form_data,
13
+ headers: headers
14
+ )
33
15
  end
16
+
17
+ private
18
+ attr_reader :mail, :options
19
+
20
+ def form_data
21
+ {
22
+ to: mail.to.try(:join, ', '),
23
+ cc: mail.cc.try(:join, ', '),
24
+ bcc: mail.bcc.try(:join, ', '),
25
+ from: mail.from.try(:join, ', '),
26
+ subject: mail.subject,
27
+ body: mail.body.to_s
28
+ }.to_json
29
+ end
30
+
31
+ def headers
32
+ { 'Content-Type': 'application/json' }.merge!(options[:headers])
33
+ end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module Mailpy
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailpy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nasrul Gunawan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.4
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.2.4.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.2.4
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.2.4.4
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: httparty
15
35
  requirement: !ruby/object:Gem::Requirement