courrier 0.5.0 → 0.5.1

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: 394bb78e24569d93855f2bcf788662ec8773371779b7743c5737867b893d4b38
4
- data.tar.gz: 4f35baf4f3ccca75ac05cd6bc7140f2eb4585c0c95e528f1aa45bc1227ec3777
3
+ metadata.gz: 7b53b10ca70de7f78cc85b10132ef28629ab062421e0d8ba0c7179b69e45d98d
4
+ data.tar.gz: 95aecbc0697a720292f9bf3e98e32a5a50637c73367b121fdd5549c6dfbe8f9a
5
5
  SHA512:
6
- metadata.gz: 387e9a879abac10ecbd97ac1a254fb08c40e48e8faf1a37f3a284dd2efd118dd70e0bf1d0032d3318914b2ddaa9242a56495547c6599dc3483844b3449114846
7
- data.tar.gz: f5b458d0cc5ff6f640f0e3ffc19be8e0e6982721dcd4ff29a3dc49d42e7a3d6e9e6b0ba2d132e8f75d2a6c5edb8f6d2ae581b3076027fc9a5a48207c54ecc2ec
6
+ metadata.gz: 42d52645c4ee70b04ec3005c699555f17ab3f93da25096d9c240126b6765e4f00197dafba99f0eaeec873df5577bbb828e9d177877d16c7611f6a2087cfc990f
7
+ data.tar.gz: 03e8724821bc2452e4f838564f7e12ea3654658a20c4eb5c4c2d1b782f7f53e66972a6b88e48490c23ab652e1a8f8df710573028ac88b7c186876462bc36916e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- courrier (0.5.0)
4
+ courrier (0.5.1)
5
5
  launchy (>= 3.1, < 4)
6
6
  nokogiri (>= 1.18, < 2)
7
7
 
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Modern, API-powered email delivery for Ruby apps.
4
4
 
5
+ ![A cute cartoon mascot wearing a blue postal uniform with red scarf and cap, carrying a leather messenger bag, representing a modern email delivery system for Ruby applications](https://raw.githubusercontent.com/Rails-Designer/courrier/HEAD/.github/cover.jpg)
6
+
5
7
  ```ruby
6
8
  # Quick example
7
9
  OrderEmail.deliver to: "recipient@railsdesigner.com"
@@ -39,6 +41,7 @@ Generate a new email:
39
41
  ```bash
40
42
  bin/rails generate courrier:email Order
41
43
  ```
44
+
42
45
  ```ruby
43
46
  class OrderEmail < Courrier::Email
44
47
  def subject = "Here is your order!"
@@ -55,7 +58,10 @@ class OrderEmail < Courrier::Email
55
58
  HTML
56
59
  end
57
60
  end
61
+
62
+ # OrderEmail.deliver to: "recipient@railsdesigner.com"
58
63
  ```
64
+
59
65
  💡 Write your email content using the [Minimal Email Editor](https://railsdesigner.com/minimal-email-editor/).
60
66
 
61
67
 
@@ -80,7 +86,7 @@ end
80
86
  2. **Email class defaults**
81
87
  ```ruby
82
88
  class OrderEmail < Courrier::Email
83
- configure from: "devs@railsdesigner.com",
89
+ configure from: "orders@railsdesigner.com",
84
90
  cc: "records@railsdesigner.com",
85
91
  provider: "mailgun",
86
92
  end
@@ -89,12 +95,61 @@ end
89
95
  3. **Instance options**
90
96
  ```ruby
91
97
  OrderEmail.deliver to: "recipient@railsdesigner.com",\
92
- from: "devs@railsdesigner.com",\
98
+ from: "shop@railsdesigner.com",\
93
99
  provider: "sendgrid",\
94
100
  api_key: "sk_a1b1c3"
95
101
  ```
96
102
 
97
103
 
104
+ Provider and API key settings can be overridden using environment variables (`COURRIER_PROVIDER` and `COURRIER_API_KEY`) for both global configuration and email class defaults.
105
+
106
+
107
+ ## Custom Attributes
108
+
109
+ Besides the standard email attributes (`from`, `to`, `reply_to`, etc.), you can pass any additional attributes that will be available in your email templates:
110
+ ```ruby
111
+ OrderEmail.deliver to: "recipient@railsdesigner.com", download_url: downloads_path(token: "token")
112
+ ```
113
+
114
+ These custom attributes are accessible directly in your email class:
115
+ ```ruby
116
+ def text
117
+ <<~TEXT
118
+ #{download_url}
119
+ TEXT
120
+ end
121
+ ```
122
+
123
+
124
+ ## Result Object
125
+
126
+ When sending an email through Courrier, a `Result` object is returned that provides information about the delivery attempt. This object offers a simple interface to check the status and access response data.
127
+
128
+
129
+ ### Available Methods
130
+
131
+ | Method | Return Type | Description |
132
+ |:-------|:-----------|:------------|
133
+ | `success?` | Boolean | Returns `true` if the API request was successful |
134
+ | `response` | Net::HTTP::Response | The raw HTTP response from the email provider |
135
+ | `data` | Hash | Parsed JSON response body from the provider |
136
+ | `error` | Exception | Contains any error that occurred during delivery |
137
+
138
+
139
+ ### Example
140
+
141
+ ```ruby
142
+ delivery = OrderEmail.deliver(to: "recipient@example.com")
143
+
144
+ if delivery.success?
145
+ puts "Email sent successfully!"
146
+ puts "Provider response: #{delivery.data}"
147
+ else
148
+ puts "Failed to send email: #{delivery.error}"
149
+ end
150
+ ```
151
+
152
+
98
153
  ## Providers
99
154
 
100
155
  Courrier supports these transactional email providers:
@@ -119,10 +174,10 @@ Additional functionality to help with development and email handling:
119
174
 
120
175
  Preview emails in your browser during development:
121
176
  ```ruby
122
- config.provider = "preview" # Opens emails in your default browser
177
+ config.provider = "preview" # Opens emails in your default browser
123
178
  ```
124
179
 
125
- Previews are automatically cleared with `bin/rails tmp:clear`, or manually with `bin/rails courrier:clear`.
180
+ Previews are automatically cleared with `bin/rails tmp:clear`, or manually with `bin/rails courrier:clear`.
126
181
 
127
182
 
128
183
  ### Layout Support
@@ -172,13 +227,13 @@ end
172
227
 
173
228
  Automatically generate plain text versions from your HTML emails:
174
229
  ```ruby
175
- config.auto_generate_text = true # Defaults to false
230
+ config.auto_generate_text = true # Defaults to false
176
231
  ```
177
232
 
178
233
 
179
234
  ### Email Address Helper
180
235
 
181
- Compose RFC 2822-compliant email addresses with display names:
236
+ Compose email addresses with display names:
182
237
  ```ruby
183
238
  class SignupsController < ApplicationController
184
239
  def create
@@ -214,9 +269,9 @@ config.logger = custom_logger # Optional: defaults to ::Logger.new($stdout)
214
269
 
215
270
  ### Custom Providers
216
271
 
217
- Create your own provider by inheriting from `Courrier::Email::Base`:
272
+ Create your own provider by inheriting from `Courrier::Email::Providers::Base`:
218
273
  ```ruby
219
- class CustomProvider < Courrier::Email::Base
274
+ class CustomProvider < Courrier::Email::Providers::Base
220
275
  ENDPOINT_URL = ""
221
276
 
222
277
  def body = ""
@@ -14,9 +14,7 @@ module Courrier
14
14
  private
15
15
 
16
16
  def default_destination
17
- return Rails.root.join("tmp", "courrier", "emails").to_s if defined?(Rails)
18
-
19
- File.join(Dir.tmpdir, "courrier", "emails")
17
+ defined?(Rails) ? Rails.root.join("tmp", "courrier", "emails").to_s : File.join(Dir.tmpdir, "courrier", "emails")
20
18
  end
21
19
  end
22
20
  end
@@ -45,9 +45,7 @@ module Courrier
45
45
  private
46
46
 
47
47
  def default_email_path
48
- return Rails.root.join("app", "emails").to_s if defined?(Rails)
49
-
50
- File.join("courrier", "emails")
48
+ defined?(Rails) ? Rails.root.join("app", "emails").to_s : File.join("courrier", "emails")
51
49
  end
52
50
  end
53
51
  end
@@ -42,11 +42,9 @@ module Courrier
42
42
  end
43
43
 
44
44
  def body_for(request)
45
- if requires_multipart_form?
46
- set_multipart_form(request)
47
- else
48
- set_json_body(request)
49
- end
45
+ return set_multipart_form(request) if requires_multipart_form?
46
+
47
+ set_json_body(request)
50
48
  end
51
49
 
52
50
  def default_headers
@@ -49,7 +49,7 @@ module Courrier
49
49
 
50
50
  def initialize(options = {})
51
51
  @provider = options[:provider] || ENV["COURRIER_PROVIDER"] || self.class.provider || Courrier.configuration&.provider
52
- @api_key = options[:api_key] || ENV["COURRIER_PROVIDER"] || self.class.api_key || Courrier.configuration&.api_key
52
+ @api_key = options[:api_key] || ENV["COURRIER_API_KEY"] || self.class.api_key || Courrier.configuration&.api_key
53
53
 
54
54
  @default_url_options = self.class.default_url_options.merge(options[:default_url_options] || {})
55
55
  @context_options = options.except(:provider, :api_key, :from, :to, :reply_to, :cc, :bcc, :subject, :text, :html)
@@ -1,3 +1,3 @@
1
1
  module Courrier
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: courrier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rails Designer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-09 00:00:00.000000000 Z
11
+ date: 2025-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: launchy