enveloop 0.1.5 → 0.2.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: 4de448ebf9699afceacb4f9bbe512de8743f4b65793850e991967b1724b52109
4
- data.tar.gz: f4b7c8e5418f394bf34ab7952c71dc48530ac9bd274de2b4e91c62af08c1f850
3
+ metadata.gz: 97d604a2c0de5c5291ddd80b3da8af6498a27ec51a5f3309c757935642dcc9c5
4
+ data.tar.gz: a2a7da964a3b81d8b333d05bb83a282433a65b99b32c0537ae1591517ba90c07
5
5
  SHA512:
6
- metadata.gz: cd504a7f37f14c2a728d854c336ecd8b6ec7a8fca4190c259bbd67bb09de1ca57636b9c8c8a4913aa5a50871185110808c30de9216c99b4685b6821afd7a7e66
7
- data.tar.gz: 65a021f76297552af4e7edbb41f57b3334290c77812254a3fc7e0eeeaff53543f8ba55baa86161e8e1817cdfec43b18b707732ea42327791ff6bd051e6754113
6
+ metadata.gz: 9b1ee3493f3f48bfe4f633c8f0620776653d9d8fc08dd16df4a59068fd941bd678d240142a4ea1a773f14e7eb1a9f30a6b8a35bd9dfacbd4b159045bdc44bce4
7
+ data.tar.gz: cf7c9b076d2e80c9972ae155e4ef395910ca1cf2142356b379e31f9a84ceb279c32666913d3f813571f2bca40cab2a660f80a31e7d8c82d98aa0f382f37c5e60
data/CHANGELOG.md CHANGED
@@ -26,3 +26,12 @@
26
26
  > ## Version 0.1.5
27
27
 
28
28
  * Use new `/messages` endpoint
29
+
30
+ > ## Version 0.1.6
31
+
32
+ * Raise ruby errors when an error is encountered in the API
33
+
34
+ > ## Version 0.2.0
35
+
36
+ * Add support for Rails via ActiveMailer
37
+ * Add `send_raw` method to send HTML email without a template
data/Gemfile.lock CHANGED
@@ -1,18 +1,180 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enveloop (0.1.5)
4
+ enveloop (0.2.0)
5
5
  faraday
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ actioncable (7.1.1)
11
+ actionpack (= 7.1.1)
12
+ activesupport (= 7.1.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ zeitwerk (~> 2.6)
16
+ actionmailbox (7.1.1)
17
+ actionpack (= 7.1.1)
18
+ activejob (= 7.1.1)
19
+ activerecord (= 7.1.1)
20
+ activestorage (= 7.1.1)
21
+ activesupport (= 7.1.1)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.1.1)
27
+ actionpack (= 7.1.1)
28
+ actionview (= 7.1.1)
29
+ activejob (= 7.1.1)
30
+ activesupport (= 7.1.1)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.2)
36
+ actionpack (7.1.1)
37
+ actionview (= 7.1.1)
38
+ activesupport (= 7.1.1)
39
+ nokogiri (>= 1.8.5)
40
+ rack (>= 2.2.4)
41
+ rack-session (>= 1.0.1)
42
+ rack-test (>= 0.6.3)
43
+ rails-dom-testing (~> 2.2)
44
+ rails-html-sanitizer (~> 1.6)
45
+ actiontext (7.1.1)
46
+ actionpack (= 7.1.1)
47
+ activerecord (= 7.1.1)
48
+ activestorage (= 7.1.1)
49
+ activesupport (= 7.1.1)
50
+ globalid (>= 0.6.0)
51
+ nokogiri (>= 1.8.5)
52
+ actionview (7.1.1)
53
+ activesupport (= 7.1.1)
54
+ builder (~> 3.1)
55
+ erubi (~> 1.11)
56
+ rails-dom-testing (~> 2.2)
57
+ rails-html-sanitizer (~> 1.6)
58
+ activejob (7.1.1)
59
+ activesupport (= 7.1.1)
60
+ globalid (>= 0.3.6)
61
+ activemodel (7.1.1)
62
+ activesupport (= 7.1.1)
63
+ activerecord (7.1.1)
64
+ activemodel (= 7.1.1)
65
+ activesupport (= 7.1.1)
66
+ timeout (>= 0.4.0)
67
+ activestorage (7.1.1)
68
+ actionpack (= 7.1.1)
69
+ activejob (= 7.1.1)
70
+ activerecord (= 7.1.1)
71
+ activesupport (= 7.1.1)
72
+ marcel (~> 1.0)
73
+ activesupport (7.1.1)
74
+ base64
75
+ bigdecimal
76
+ concurrent-ruby (~> 1.0, >= 1.0.2)
77
+ connection_pool (>= 2.2.5)
78
+ drb
79
+ i18n (>= 1.6, < 2)
80
+ minitest (>= 5.1)
81
+ mutex_m
82
+ tzinfo (~> 2.0)
83
+ base64 (0.2.0)
84
+ bigdecimal (3.1.4)
85
+ builder (3.2.4)
86
+ concurrent-ruby (1.2.2)
87
+ connection_pool (2.4.1)
88
+ crass (1.0.6)
89
+ date (3.3.4)
10
90
  diff-lcs (1.4.4)
11
- faraday (1.1.0)
12
- multipart-post (>= 1.2, < 3)
91
+ drb (2.2.0)
13
92
  ruby2_keywords
14
- multipart-post (2.1.1)
93
+ erubi (1.12.0)
94
+ faraday (2.7.11)
95
+ base64
96
+ faraday-net_http (>= 2.0, < 3.1)
97
+ ruby2_keywords (>= 0.0.4)
98
+ faraday-net_http (3.0.2)
99
+ globalid (1.2.1)
100
+ activesupport (>= 6.1)
101
+ i18n (1.14.1)
102
+ concurrent-ruby (~> 1.0)
103
+ io-console (0.6.0)
104
+ irb (1.8.3)
105
+ rdoc
106
+ reline (>= 0.3.8)
107
+ loofah (2.21.4)
108
+ crass (~> 1.0.2)
109
+ nokogiri (>= 1.12.0)
110
+ mail (2.8.1)
111
+ mini_mime (>= 0.1.1)
112
+ net-imap
113
+ net-pop
114
+ net-smtp
115
+ marcel (1.0.2)
116
+ mini_mime (1.1.5)
117
+ mini_portile2 (2.8.5)
118
+ minitest (5.20.0)
119
+ mutex_m (0.2.0)
120
+ net-imap (0.4.4)
121
+ date
122
+ net-protocol
123
+ net-pop (0.1.2)
124
+ net-protocol
125
+ net-protocol (0.2.2)
126
+ timeout
127
+ net-smtp (0.4.0)
128
+ net-protocol
129
+ nio4r (2.5.9)
130
+ nokogiri (1.15.4)
131
+ mini_portile2 (~> 2.8.2)
132
+ racc (~> 1.4)
133
+ psych (5.1.1.1)
134
+ stringio
135
+ racc (1.7.3)
136
+ rack (3.0.8)
137
+ rack-session (2.0.0)
138
+ rack (>= 3.0.0)
139
+ rack-test (2.1.0)
140
+ rack (>= 1.3)
141
+ rackup (2.1.0)
142
+ rack (>= 3)
143
+ webrick (~> 1.8)
144
+ rails (7.1.1)
145
+ actioncable (= 7.1.1)
146
+ actionmailbox (= 7.1.1)
147
+ actionmailer (= 7.1.1)
148
+ actionpack (= 7.1.1)
149
+ actiontext (= 7.1.1)
150
+ actionview (= 7.1.1)
151
+ activejob (= 7.1.1)
152
+ activemodel (= 7.1.1)
153
+ activerecord (= 7.1.1)
154
+ activestorage (= 7.1.1)
155
+ activesupport (= 7.1.1)
156
+ bundler (>= 1.15.0)
157
+ railties (= 7.1.1)
158
+ rails-dom-testing (2.2.0)
159
+ activesupport (>= 5.0.0)
160
+ minitest
161
+ nokogiri (>= 1.6)
162
+ rails-html-sanitizer (1.6.0)
163
+ loofah (~> 2.21)
164
+ nokogiri (~> 1.14)
165
+ railties (7.1.1)
166
+ actionpack (= 7.1.1)
167
+ activesupport (= 7.1.1)
168
+ irb
169
+ rackup (>= 1.0.0)
170
+ rake (>= 12.2)
171
+ thor (~> 1.0, >= 1.2.2)
172
+ zeitwerk (~> 2.6)
15
173
  rake (12.3.3)
174
+ rdoc (6.6.0)
175
+ psych (>= 4.0.0)
176
+ reline (0.4.0)
177
+ io-console (~> 0.5)
16
178
  rspec (3.10.0)
17
179
  rspec-core (~> 3.10.0)
18
180
  rspec-expectations (~> 3.10.0)
@@ -26,13 +188,24 @@ GEM
26
188
  diff-lcs (>= 1.2.0, < 2.0)
27
189
  rspec-support (~> 3.10.0)
28
190
  rspec-support (3.10.2)
29
- ruby2_keywords (0.0.4)
191
+ ruby2_keywords (0.0.5)
192
+ stringio (3.0.9)
193
+ thor (1.3.0)
194
+ timeout (0.4.1)
195
+ tzinfo (2.0.6)
196
+ concurrent-ruby (~> 1.0)
197
+ webrick (1.8.1)
198
+ websocket-driver (0.7.6)
199
+ websocket-extensions (>= 0.1.0)
200
+ websocket-extensions (0.1.5)
201
+ zeitwerk (2.6.12)
30
202
 
31
203
  PLATFORMS
32
204
  ruby
33
205
 
34
206
  DEPENDENCIES
35
207
  enveloop!
208
+ rails
36
209
  rake (~> 12.0)
37
210
  rspec (~> 3.0)
38
211
 
data/README.md CHANGED
@@ -20,6 +20,8 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+ ### Ruby (direct usage)
24
+
23
25
  Setup the client connection:
24
26
 
25
27
  ```ruby
@@ -28,7 +30,7 @@ require 'enveloop'
28
30
  enveloop = Enveloop::Client.new(api_key: ENV['ENVELOOP_API_TOKEN'])
29
31
  ```
30
32
 
31
- Send a message:
33
+ Send a message using a template:
32
34
 
33
35
  ```ruby
34
36
  enveloop.send_message(
@@ -42,11 +44,32 @@ enveloop.send_message(
42
44
  )
43
45
  ```
44
46
 
47
+ Send a message passing HTML body:
48
+
49
+ ```ruby
50
+ enveloop.send_message(
51
+ html: '<h1>Hello John, Welcome to MyApp</h1>',
52
+ to: 'user@email.com',
53
+ from: 'welcome@myapp.com',
54
+ subject: 'Welcome to MyApp',
55
+ )
56
+ ```
57
+
45
58
  Get information about a template (variables and body html):
46
59
 
47
60
  ```ruby
48
61
  enveloop.template_info(template: 'welcome-email')
49
62
  ```
63
+ ### Rails
64
+
65
+ Add the following to your initializer and send Active::Mailer messaegs with Enveloop as well
66
+
67
+ ```ruby
68
+ config.action_mailer.delivery_method = :enveloop
69
+ config.action_mailer.enveloop_settings = {
70
+ api_key: ENV['ENVELOOP_API_TOKEN']
71
+ }
72
+ ```
50
73
 
51
74
  ## Development
52
75
 
data/enveloop.gemspec CHANGED
@@ -8,15 +8,16 @@ Gem::Specification.new do |spec|
8
8
 
9
9
  spec.summary = "Envelope API wrapper"
10
10
  spec.description = "This gem provides a wrapper for the Envelope API."
11
- spec.homepage = "https://github.com/enveloophq/ruby_enveloop"
11
+ spec.homepage = "https://github.com/enveloophq/enveloop-ruby"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
14
 
15
15
  spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = "https://github.com/enveloophq/ruby_enveloop"
17
- spec.metadata["changelog_uri"] = "https://github.com/enveloophq/ruby_enveloop/blob/master/CHANGELOG.md"
16
+ spec.metadata["source_code_uri"] = "https://github.com/enveloophq/enveloop-ruby"
17
+ spec.metadata["changelog_uri"] = "https://github.com/enveloophq/enveloop-ruby/blob/master/CHANGELOG.md"
18
18
 
19
19
  spec.add_dependency "faraday"
20
+ spec.add_development_dependency "rails"
20
21
 
21
22
  # Specify which files should be added to the gem when it is released.
22
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -5,12 +5,13 @@ module Enveloop
5
5
  @api_key = api_key
6
6
  end
7
7
 
8
- def send_message(template:, to:, from: nil, subject: nil, template_variables: {})
8
+ def send_message(to:, template: nil, html: nil, from: nil, subject: nil, template_variables: {})
9
9
  data = {
10
10
  to: to,
11
11
  from: from,
12
12
  subject: subject,
13
13
  template: template,
14
+ html: html,
14
15
  templateVariables: template_variables
15
16
  }
16
17
 
@@ -27,6 +28,35 @@ module Enveloop
27
28
  req.body = data.to_json
28
29
  end
29
30
 
31
+ if response.status == 500
32
+ raise Enveloop::Error.new(JSON.parse(response.body)['error'])
33
+ end
34
+
35
+ return MessageResponse.new(status: response.status, body: response.body)
36
+ end
37
+
38
+ def send_raw(email:)
39
+ data = {
40
+ email: email
41
+ }
42
+
43
+ conn = Faraday.new(
44
+ url: @endpoint,
45
+ headers: {
46
+ "Content-Type" => "application/json",
47
+ "Authorization" => "token #{@api_key}",
48
+ "Sdk-Version" => "ruby-#{Enveloop::VERSION}"
49
+ }
50
+ )
51
+
52
+ response = conn.post('/messages/rawEmail') do |req|
53
+ req.body = data.to_json
54
+ end
55
+
56
+ if response.status == 500
57
+ raise Enveloop::Error.new(JSON.parse(response.body)['error'])
58
+ end
59
+
30
60
  return MessageResponse.new(status: response.status, body: response.body)
31
61
  end
32
62
 
@@ -41,6 +71,10 @@ module Enveloop
41
71
 
42
72
  response = conn.get("/templates/#{template}")
43
73
 
74
+ if response.status == 500
75
+ raise Enveloop::Error.new(JSON.parse(response.body)['error'])
76
+ end
77
+
44
78
  return TemplateResponse.new(status: response.status, body: response.body)
45
79
  end
46
80
  end
@@ -1,3 +1,3 @@
1
1
  module Enveloop
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/enveloop.rb CHANGED
@@ -6,6 +6,8 @@ require 'enveloop/client'
6
6
  require 'enveloop/message_response'
7
7
  require 'enveloop/template_response'
8
8
 
9
+ require 'enveloop_rails' if defined?(Rails) && defined?(ActionMailer)
10
+
9
11
  module Enveloop
10
12
  class Error < StandardError; end
11
13
  end
@@ -0,0 +1,26 @@
1
+ module EnveloopRails
2
+ class Error < StandardError
3
+
4
+ attr_reader :object
5
+
6
+ def initialize(message = nil, object = nil)
7
+ super(message)
8
+
9
+ @object = object
10
+ end
11
+ end
12
+
13
+ class ConfigurationError < Error
14
+ end
15
+
16
+ class InternalError < Error
17
+
18
+ attr_reader :source_exception
19
+
20
+ def initialize(source_exc, message = nil, object = nil)
21
+ super(message, object)
22
+
23
+ @source_exception = source_exc
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ require 'action_mailer'
2
+ require 'json'
3
+ require 'enveloop'
4
+ require 'rails'
5
+ require 'enveloop_rails/errors'
6
+
7
+ module EnveloopRails
8
+
9
+ # EnveloopRails::Mailer is an ActionMailer provider for sending mail through Enveloop.
10
+ class Mailer
11
+ # [Hash] config ->
12
+ # Requires *at least* `api_key`
13
+ attr_accessor :config, :settings
14
+
15
+ # Initialize the EnveloopRails mailer.
16
+ #
17
+ # @param [Hash] config Hash of config values, typically from `app_config.action_mailer.enveloop_settings`
18
+ def initialize(config)
19
+ @config = config
20
+
21
+ raise EnveloopRails::ConfigurationError.new("Config requires `api_key` key", @config) unless @config.has_key?(:api_key)
22
+
23
+ @enveloop_client = Enveloop::Client.new(**config)
24
+
25
+ # To avoid exception in mail gem v2.6
26
+ @settings = { return_response: true }
27
+ end
28
+
29
+ def deliver!(mail)
30
+ @enveloop_client.send_raw(email: mail.to_s)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ require 'enveloop_rails/mailer'
2
+
3
+ module EnveloopRails
4
+ class Railtie < ::Rails::Railtie
5
+ ActiveSupport.on_load(:action_mailer) do
6
+ add_delivery_method :enveloop, EnveloopRails::Mailer
7
+ ActiveSupport.run_load_hooks(:enveloop_mailer, EnveloopRails::Mailer)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ require 'enveloop_rails/railtie'
2
+ require 'enveloop_rails/errors'
3
+ require 'enveloop_rails/mailer'
4
+
5
+ module EnveloopRails
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enveloop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Wyrosdick
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-10 00:00:00.000000000 Z
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: This gem provides a wrapper for the Envelope API.
28
42
  email:
29
43
  - support@enveloop.com
@@ -48,14 +62,18 @@ files:
48
62
  - lib/enveloop/message_response.rb
49
63
  - lib/enveloop/template_response.rb
50
64
  - lib/enveloop/version.rb
51
- homepage: https://github.com/enveloophq/ruby_enveloop
65
+ - lib/enveloop_rails.rb
66
+ - lib/enveloop_rails/errors.rb
67
+ - lib/enveloop_rails/mailer.rb
68
+ - lib/enveloop_rails/railtie.rb
69
+ homepage: https://github.com/enveloophq/enveloop-ruby
52
70
  licenses:
53
71
  - MIT
54
72
  metadata:
55
- homepage_uri: https://github.com/enveloophq/ruby_enveloop
56
- source_code_uri: https://github.com/enveloophq/ruby_enveloop
57
- changelog_uri: https://github.com/enveloophq/ruby_enveloop/blob/master/CHANGELOG.md
58
- post_install_message:
73
+ homepage_uri: https://github.com/enveloophq/enveloop-ruby
74
+ source_code_uri: https://github.com/enveloophq/enveloop-ruby
75
+ changelog_uri: https://github.com/enveloophq/enveloop-ruby/blob/master/CHANGELOG.md
76
+ post_install_message:
59
77
  rdoc_options: []
60
78
  require_paths:
61
79
  - lib
@@ -70,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
88
  - !ruby/object:Gem::Version
71
89
  version: '0'
72
90
  requirements: []
73
- rubygems_version: 3.1.2
74
- signing_key:
91
+ rubygems_version: 3.4.10
92
+ signing_key:
75
93
  specification_version: 4
76
94
  summary: Envelope API wrapper
77
95
  test_files: []